Lab5_Counter
Lab5_Counter
CS 2052 Computer
CS1050 Computer Architecture
Organization and Digital Design
Dept. of Computer Science and Engineering, University of Moratuwa
Learning Outcomes
In this lab, we will design a 3-bit counter with an external input. After completing the lab,
you will be able to:
• design and develop a 3-bit counter
• count in clockwise and anticlockwise directions based on an external input
• verify its functionality via simulation and on the development board
Introduction
A register that goes through a predetermined sequence of states is called a counter. In
this lab, we will design a 3-bit counter that can show the sequence of LEDs (dark circles indicate
LEDs that are lit) defined in Fig. 1. We will control the direction of counting (clockwise or
anticlockwise) based on an external input. When the input button is switched off, we will count in
the clockwise direction. When it is switched on, we will count in the anticlockwise direction.
where D is the data input, reset clears FF to 0 (i.e., resets the value of FF), and
FF is driven by a clock. Q and Qbar are the 2 outputs.
So far we have used VHDL to define the behavior of our circuits as a sequence
of logic operations (this is referred to as Structural Modelling). VHDL also allows
us to define how a circuit should behave more abstractly. This style of circuit
definition is referred to as VHDL Behavioral Modelling. Behavioral modeling
describes how the circuit should behave using high-level programming constructs
such as variables, conditions, and procedures. Given a circuit defined using
behavioral modeling, the VHDL synthesizer tool will decide the actual circuit
implementation.
Crete a new VHDL file and name it as . Set the inputs as , , and
and outputs as and .
Then add the code given in Fig. 2 to define the behavior of the D FF. The
process is the key structure that defines the behavior of the VHDL model. It
defines the functionality of an entity. Here we name the process as Clk. Then we
detect the rising edge of the clock using rising_edge()function. When the
clock is high, we either set the output based on the D input or reset it to 0, if reset
input is high (if Ref = ‘1’).
Figure 2 – Behavioral model of D flip-flop.
Simulate the D_FF using XSim and make sure it functions correctly. Name the
simulation files as .
component D_FF
port (
D : in STD_LOGIC;
Res: in STD_LOGIC;
Clk : in STD_LOGIC;
Q : out STD_LOGIC;
Qbar : out STD_LOGIC);
end component;
component Slow_Clk
port (
Clk_in : in STD_LOGIC;
Clk_out: out STD_LOGIC);
end component;
begin
Slow_Clk0 : Slow_Clk
port map (
Clk_in => Clk,
Clk_out => Clk_slow);
D_FF0 : D_FF
port map (
D => D0,
Res => Res,
Clk => Clk_slow,
Q => Q0);
D_FF1 : D_FF
port map (
...); --Fill missing details
D_FF2 : D_FF
port map (
...); --Fill missing details
end Behavioral;
Verify the functionality of your counter using the simulator. Name the simulation
file as . For simulation purposes, you may want to reduce counter
value in slow-down counter, but make sure to reset it to 50 million before
generating the bitstream.
Bibliography
• Modeling Latches and Flip-flops, Xilinx, “Vivado Tutorial – Lab Workbook,” 2015.
• Modeling Registers and Counters, Xilinx, “Vivado Tutorial – Lab Workbook,” 2015.
Prepared By
• Dilum Bandara, PhD – Mar 26, 2014.
• Updated on Oct 11, 2018