Lab 6
Lab 6
Şenol Mutlu
The purpose of this lab is to design a parallel loadable, 2-digit up/down BCD counter.
Counting is done by pressing and releasing a push-button switch. By pressing and
releasing one of the three push-button switches, the counter can be parallel loaded, up-
counted or down-counted. The content of the counter is displayed on two 7-segment LED
displays. This counter is implemented on the FPGA board. Overall schematic for the
system is shown below.
1
EE244 Prof. Dr. Şenol Mutlu
by the slide switches to the counter. After loading, it should not count automatically. If you
press and release BTNU once, your system should count up once. If you press and
release BTND once, your system should count down once. If you keep pressing BTNU or
BTND, your counter should not do any counting. Counting is executed once you release
the button.
You should condition the output of the push-button switches before you use them as inputs
to your system since pressing these buttons once actually generates many glitches (many
negative and positive levels and edges). You can use a shift-register to detect if the button
is pressed and then generate a clean input signal.
In order to use the push buttons as inputs, they must be debounced so that a single push
of the button results in a clean signal. One way to debounce a switch signal is to shift the
bouncing signal down to a shift register. Then, the outputs of all the flip-flops can be
ANDed to generate a clean signal as shown in the figure below. Assume that the bounce
interval of a switch has been experimentally determined to be about 10 ms. That is the
output of the switch is stabilized 10 ms after acting on the switch. If we sample the switch
value every 100 Hz, and record the last four or more switch values in a shift register and
AND these four or more recent switch results, bouncing on the mechanical switch will be
filtered out and the AND gate will give us a clean signal with one edge for every press of
the switch. The fixed frequency of the global clock that the FPGA uses, which is generated
by the Nexys3 board, is 100 MHz. We should design a clock divider circuit using an N-bit
counter that will divide the 100 MHz clock into a clock rate suitable for switch debouncing
(approximately to 100 Hz by dividing it by 220 times). Note that an n-bit counter divides the
frequency of a clock signal by 2n times. Design a switch debouncing circuit in VHDL using
a 4-bit shift register and an AND gate. The output of this circuit should control your counter.
Also eight slide switches are available on the FPGA board. When closed (ON), each switch
pulls the connected pin of the FPGA to ground through a resistor. The pin is pulled high
through a resistor when the switch is open (OFF). You will use eight of these switches as
the 8 bit input to be parallel loaded to your counter. The format of the 8-bit input should be
in BCD. You do not need to implement debouncer circuits for them.
2
EE244 Prof. Dr. Şenol Mutlu
8-bit Up-Counter
Your counter should count up and down in two-digit BCD format. It should count from 00
(0000-0000) to 99 (1001-1001) as a push-button is pressed and released. You can
achieve this by implementing a BCD up/down counter. Alternatively, you can design a 7
or 8 bit binary up/down counter. Then, connect a binary to BCD converter to its outputs.
In this case, you can enter input from slide switches in the binary format. Also, you should
not worry about binary values exceeding 99. A behavioral VHDL code for an up-counting
single digit BCD counter is given below. You can modify this code to realize the desired
BCD counter in this lab.
A behavioral VHDL code for an up-counting 8-bit binary counter is given below. You can
modify this code to realize the desired counting function.
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
USE ieee.std_logic_unsigned.all;
entity my_count8 is
port( D: in std_logic_vector(7 downto 0);
Q: out std_logic_vector(7 downto 0);
CLK, clk_enable, RESET : in std_logic );
end count4;
3
EE244 Prof. Dr. Şenol Mutlu
(most significant digit) is connected to Digit1. The entity of your design should have two
sets of 8-bit output ports. These outputs are connected to the seven-segment display
driver, nexys3_sseg_driver.vhd, given and explained in Lab 5.
Overall Design
As explained above your design accepts 8-bit input, named pdata, one clock signal named
board_clk, three control signals named pload, upcount and downcount and generate 8-bit
lowdig output and 8-bit highdig output. Then, these outputs will be inputs to the design
given in the nexys3_sseg_driver.vhd file using structural vhdl style. This design will
generate the SSEG_CA(7 downto 0) and SSEG_AN(3 downto 0) outputs using the clock
signal. Your VHDL code for this design should have the following structure. You should
complete the architecture. Your VHDL code can use structural and/or dataflow and/or
behavioral style VHDL.
-- Synthesizable 2-Digit, parallel loadable up/down BCD Count by pressing push-button switches
-- EE244 class Bogazici University
-- Implemented on Xilinx Spartan VI FPGA chip
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
USE ieee.std_logic_signed.all ;
USE ieee.std_logic_arith.all ;
USE ieee.std_logic_unsigned.all;
entity ee240_bcdcounter is
port (
pdata: in std_logic_vector(7 downto 0);
pload: in std_logic;
upcount: in std_logic;
downcount: in std_logic;
board_clk: in std_logic;
SSEG_CA: out std_logic_vector(7 downto 0);
SSEG_AN: out std_logic_vector(3 downto 0));
end;
-- board_clk comes from the 100 MHz board clock connected to V10
4
EE244 Prof. Dr. Şenol Mutlu
end arch_BCD_counter;
Pin Assignment
After successfully completing the design, compilation, ISim simulations and synthesis, you
should show that your design work on the FPGA board. By looking at the manual of the
Nexys3 Board, we can find which FPGA pins are connected to which components. The
following is a list of pin connection we want for this lab and their meanings.
5
EE244 Prof. Dr. Şenol Mutlu
Preparation (Prelab)
For Frequency Divider and Debouncer Circuit
• Write a VHDL code for these components.
• Run ISim and verify that they function as expected by running test sequences.
6
EE244 Prof. Dr. Şenol Mutlu
• Combine the design components under ee240_bcdcounter architecture and run ISim
on it and verify that it functions as expected by running a few test sequences.
In Lab
• Use Xilinx ISE to synthesize the design based on Xilinx Spartan VI family. Use
either the given ucf file or enter pins manually to make pin assignment.
• Generate the bit file and upload it to your FPGA.
• On the hardware show that your design works.
• See if the LEDs show what you expect every time you apply your data using Slide
and push-button switches.
References
[1] "Nexys 3 Manual." (accessed 18 March 2021).