Figure 1 Block diagram of a 4-bit binary counter

Similar documents
HDL & High Level Synthesize (EEET 2035) Laboratory II Sequential Circuits with VHDL: DFF, Counter, TFF and Timer

Lab 4: Hex Calculator

Lab 3: VGA Bouncing Ball I

Ryerson University Department of Electrical and Computer Engineering EES508 Digital Systems

Eng. Mohammed Samara. Fall The Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department

Flip-flop and Registers

California State University, Bakersfield Computer & Electrical Engineering & Computer Science ECE 3220: Digital Design with VHDL Laboratory 7

Laboratory Exercise 7

Main Design Project. The Counter. Introduction. Macros. Procedure

Main Design Project. The Counter. Introduction. Macros. Procedure

DEPARTMENT OF ELECTRICAL &ELECTRONICS ENGINEERING DIGITAL DESIGN

YEDITEPE UNIVERSITY DEPARTMENT OF COMPUTER ENGINEERING. EXPERIMENT VIII: FLIP-FLOPS, COUNTERS 2014 Fall

Flip-Flops and Registers

ACS College of Engineering. Department of Biomedical Engineering. HDL pre lab questions ( ) Cycle-1

Lab 6: Video Game PONG

Laboratory Exercise 7

Spartan-II Development System

Design Problem 4 Solutions

Class 06 Sequential Logic: Flip-Flop

Digital Fundamentals: A Systems Approach

ASYNCHRONOUS COUNTER CIRCUITS

EEM Digital Systems II

Design and implementation (in VHDL) of a VGA Display and Light Sensor to run on the Nexys4DDR board Report and Signoff due Week 6 (October 4)

MASSACHUSETTS INSTITUTE OF TECHNOLOGY Department of Electrical Engineering and Computer Sciences

Class 19 Sequential Logic: Flip-Flop

Digital Circuits I and II Nov. 17, 1999

PHYSICS 5620 LAB 9 Basic Digital Circuits and Flip-Flops

Programmable Logic Design I

Asynchronous (Ripple) Counters

ECE 263 Digital Systems, Fall 2015

We are here. Assembly Language. Processors Arithmetic Logic Units. Finite State Machines. Circuits Gates. Transistors

10.1 Sequential logic circuits are a type of logic circuit where the output of the circuit depends not only on

Design of a Binary Number Lock (using schematic entry method) 1. Synopsis: 2. Description of the Circuit:

1. Synopsis: 2. Description of the Circuit:

FPGA Laboratory Assignment 4. Due Date: 06/11/2012

ECE 3401 Lecture 11. Sequential Circuits

ECE 3401 Lecture 12. Sequential Circuits (II)

ENGG2410: Digital Design Lab 5: Modular Designs and Hierarchy Using VHDL

Sequential circuits. Same input can produce different output. Logic circuit. William Sandqvist

Electrical and Telecommunications Engineering Technology_TCET3122/TC520. NEW YORK CITY COLLEGE OF TECHNOLOGY The City University of New York

CSCB58 - Lab 4. Prelab /3 Part I (in-lab) /1 Part II (in-lab) /1 Part III (in-lab) /2 TOTAL /8

STATIC RANDOM-ACCESS MEMORY

Sri Vidya College of Engineering And Technology. Virudhunagar Department of Electrical and Electronics Engineering

COMPUTER ENGINEERING PROGRAM

Tutorial 11 ChipscopePro, ISE 10.1 and Xilinx Simulator on the Digilent Spartan-3E board

FPGA TechNote: Asynchronous signals and Metastability

Lecture 8: Sequential Logic

download instant at

Chapter 9 Counters. Clock Edge Output Q 2 Q 1 Q

EE178 Lecture Module 4. Eric Crabill SJSU / Xilinx Fall 2005

Traffic Light Controller

Using the XSV Board Xchecker Interface

FPGA-BASED EDUCATIONAL LAB PLATFORM

CSE Latches and Flip-flops Dr. Izadi. NOR gate property: A B Z Cross coupled NOR gates: S M S R Q M

library IEEE; use IEEE.STD_LOGIC_1164.ALL;

Other Flip-Flops. Lecture 27 1

Figure 1 shows a simple implementation of a clock switch, using an AND-OR type multiplexer logic.

COE758 Xilinx ISE 9.2 Tutorial 2. Integrating ChipScope Pro into a project

Debugging of VHDL Hardware Designs on Altera s DE2 Boards

Outline. CPE/EE 422/522 Advanced Logic Design L04. Review: 8421 BCD to Excess3 BCD Code Converter. Review: Mealy Sequential Networks

Dr. Shahram Shirani COE2DI4 Midterm Test #2 Nov 19, 2008

DIGITAL SYSTEM DESIGN UNIT I (2 MARKS)

Laboratory 1 - Introduction to Digital Electronics and Lab Equipment (Logic Analyzers, Digital Oscilloscope, and FPGA-based Labkit)

CH 11 Latches and Flip-Flops

Microprocessor Design

Lab #5: Design Example: Keypad Scanner and Encoder - Part 1 (120 pts)

AIM: To study and verify the truth table of logic gates

Sequential Digital Design. Laboratory Manual. Experiment #3. Flip Flop Storage Elements

Chapter 5 Synchronous Sequential Logic

Faculty of Electrical & Electronics Engineering BEE3233 Electronics System Design. Laboratory 3: Finite State Machine (FSM)

RS flip-flop using NOR gate

VHDL 4 BUILDING BLOCKS OF A COMPUTER.

Advanced Devices. Registers Counters Multiplexers Decoders Adders. CSC258 Lecture Slides Steve Engels, 2006 Slide 1 of 20

Modeling Latches and Flip-flops

Professor Henry Selvaraj, PhD. November 30, CPE 302 Digital System Design. Super Project

Counters

ELCT201: DIGITAL LOGIC DESIGN

Unit 11. Latches and Flip-Flops

CHAPTER 4: Logic Circuits

Chapter 6. Flip-Flops and Simple Flip-Flop Applications

Digital Logic Design Sequential Circuits. Dr. Basem ElHalawany

Experiment 8 Introduction to Latches and Flip-Flops and registers

Chapter 6 Digital Circuit 6-5 Department of Mechanical Engineering

Sequential Digital Design. Laboratory Manual. Experiment #7. Counters

Digital Logic Design ENEE x. Lecture 19

Synchronous Sequential Design

MUHAMMAD NAEEM LATIF MCS 3 RD SEMESTER KHANEWAL

SEQUENTIAL LOGIC. Satish Chandra Assistant Professor Department of Physics P P N College, Kanpur

Register Transfer Level in Verilog: Part II

Lab 5 FPGA Design Flow Based on Aldec Active-HDL. Fast Reflex Game.

EE178 Spring 2018 Lecture Module 5. Eric Crabill

CprE 281: Digital Logic

IT T35 Digital system desigm y - ii /s - iii

Unit 9 Latches and Flip-Flops. Dept. of Electrical and Computer Eng., NCTU 1

TMEL53, DIGITALTEKNIK. INTRODUCTION TO SYNCHRONOUS CIRCUITS, FLIP-FLOPS and COUNTERS

Flip-Flops and Sequential Circuit Design

Laboratory Exercise 6

Inside Digital Design Accompany Lab Manual

Counter dan Register

Level and edge-sensitive behaviour

Transcription:

Lab 3: Four-Bit Binary Counter EE-459/500 HDL Based Digital Design with Programmable Logic Electrical Engineering Department, University at Buffalo Last update: Cristinel Ababei, August 2012 1. Objective The objective of this lab is to design and test a 4-bit binary counter. Aside from learning about the on-board clock signal and push-buttons as well as about frequency dividers, this lab reinforces the design flow steps introduced in the previous labs. 2. Description We design a 4-bit binary counter. Our counter has an output Q with four bits. During correct operation, the counter starts at 0000 and then binary counts up to output 0001, 0010, 0011, and so on until it outputs 1111, after which it resets to 0000 and starts again. The first implementation of our counter has only one input: a clock signal CK. The clock signal is provided by the external (to the FPGA) clock generator. We use the output Q to drive the first four LEDs on the Atlys board. The block diagram of the simplest/basic structural implementation of such a binary counter is shown in the next figure. This implementation is known as a ripple counter. Toggle Flip-Flop Figure 1 Block diagram of a 4-bit binary counter As shown in the figure above, we use four Toggle Flip-Flops (TFF s). As you remember, the operation of a TFF is as follows: When the T input is logic 1, the output Q will toggle on each clock transition. When the T input is logic 0, the output Q will not change. To start our design, we first create a new project by launching Xilinx ISE WebPack and following the steps discussed in lab 2. Call the new project fourbit_counter and select the same location where you created the previous project. Create and add to the project a first VHDL file called tff.vhd with the following content: -- tff.vhd -- Toggle Flip-Flop with behavioral description 1

library IEEE; entity tff is Port ( T end tff; : in STD_LOGIC; CK : in STD_LOGIC; Q, QN : out STD_LOGIC); architecture My_behavioral of tff is signal mem : std_logic := '0'; process (CK, T, mem) -- execute this process only when the clock changes if T = '0' then null; -- no toggle, so do nothing elsif (CK'event and CK = '1') then mem <= not mem; -- rising edge of clock and T = 1, toggle stored value end process; Q <= mem; QN <= not mem; end; Clock Divider Our counter uses as a clock a signal generated by the on-board clock generator. This clock generator is a single 100 MHz CMOS oscillator on the Atlys board connected to pin L15 of the Spartan-6 FPGA. Because the frequency of 100 MHz is too high for the human eye to be able to see how the counter output drives the LEDs, we must utilize a clock divider to lower the frequency to about 1 Hz. Create and add to the project a second VHDL file called ck_divider.vhd with the following content: -- ck_divider.vhd -- This is a clock divider. It takes as input a signal -- of 100 MHz and generates an output as signal with a frequency -- of about 1 Hz. library IEEE; entity ck_divider is Port ( CK_IN : in STD_LOGIC; CK_OUT : out STD_LOGIC); end ck_divider; architecture Behavioral of ck_divider is constant TIMECONST : integer := 84; signal count0, count1, count2, count3 : integer range 0 to 1000; signal D : std_logic := '0'; process (CK_IN, D) 2

if (CK_IN'event and CK_IN = '1') then count0 <= count0 + 1; if count0 = TIMECONST then count0 <= 0; count1 <= count1 + 1; elsif count1 = TIMECONST then count1 <= 0; count2 <= count2 + 1; elsif count2 = TIMECONST then count2 <= 0; count3 <= count3 + 1; elsif count3 = TIMECONST then count3 <= 0; D <= not D; CK_OUT <= D; end process; end Behavioral; Read the above code to understand its operation. It takes the 100 MHz external clock as input CK_IN and generates an output signal CK_OUT of 1 Hz. The output frequency is adjustable according to the following formula (TIMECONST = 84 in this case in order to get an output frequency of about 1 Hz): Output Frequency = 100000000 / ( 2 * (TIMECONST ^ 4) ) Note: There are other ways of implementing the TFF or the clock divider. In time, by accumulating more and more experience, you will develop your own VHDL programming style by adopting different coding techniques. 4-bit Binary Counter Finally, let s create a third VHDL file with the top-level description of our fourbit_counter design described in Figure 1. Create and add to the project the third VHDL file called fourbit_counter.vhd with the following content: -- fourbit_counter.vhd -- This is a simple 4-bit (Ripple) binary counter made up -- of four T flip-flops. It also includes a clock divider -- to bring down the input CK signal from 100 MHz to about 1 Hz. library IEEE; entity fourbit_counter is Port ( CK : in STD_LOGIC; Q : out STD_LOGIC_VECTOR (3 downto 0)); end fourbit_counter; architecture Structural of fourbit_counter is component tff 3

Port ( T end component; : in STD_LOGIC; CK : in STD_LOGIC; Q, QN : out STD_LOGIC); component ck_divider Port ( CK_IN : in STD_LOGIC; CK_OUT : out STD_LOGIC); end component; signal all_t, S0, S1, S2, S3, internal_ck : STD_LOGIC; -- We use signal all_t set to logic '1' to drive -- input T of all T flip-flops to logic '1'. all_t <= '1'; CLOCK: ck_divider port map (CK, internal_ck); TFF0: tff port map (all_t, internal_ck, Q(0), S0); TFF1: tff port map (all_t, S0, Q(1), S1); TFF2: tff port map (all_t, S1, Q(2), S2); TFF3: tff port map (all_t, S2, q(3), S3); end Structural; Design Implementation At this time, we have coded the entire design and its components. Before continuing to Design Implementation, we first take care of two things: Set the fourbit_counter as the top-level design (we need to do this because currently TFF.vhd is the toplevel because it was added first to the project). To do that, in the Hierarchy window, Right click on fourbit_counter Structural (fourbit_counter.vhd) and select Set as To-Level. Pin assignment. As discussed earlier we use the external clock signal connected to pin L15 of the Spartan-6 FPGA. So, we assign pin L15 to the input CK of our design. Also, we use the output Q of our design to drive the first four LEDs of the Atlys board. Now, do the pin assignment as learned in lab 2. After this step, your UCF file should have the following content: # PlanAhead Generated physical constraints NET "Q[0]" LOC = U18; NET "Q[1]" LOC = M14; NET "Q[2]" LOC = N14; NET "Q[3]" LOC = L14; NET "CK" LOC = L15; We are now ready to implement the design: in the Processes tab double-click Implement Design (or rightclick on Implement Design and select Run). Generate the Programming File and Program the FPGA Double-click on Generate Programming File in the Process tab. Then, program the FPGA using the Adept software as learned in lab 2. Verify that our counter works correctly. 4

3. Lab assignment Lab preparation A major problem with the counter implemented in this lab is that the individual flip-flops do not all change state at the same time. Rather, each flip-flop is used to trigger the next one in the series. Thus, in switching from all 1s (count = 15) to all 0s (count wraps back to 0), we don t see a smooth transition. Instead, output Q(0) falls first, changing the apparent count to 14. This triggers output Q(1) to fall, changing the apparent count to 12. This in turn triggers output Q(2), which leaves a count of 8 while triggering output Q(3) to fall. This last action finally leaves us with the correct output count of zero. We say that the change of state ripples through the counter from one flip-flop to the next. Therefore, this circuit is known as a ripple counter. This causes no problem if the output is only to be read by human eyes; the ripple effect is too fast for us to see it. However, if the count is to be used as a selector by other digital circuits (such as a multiplexer or demultiplexer), the ripple effect can easily allow signals to get mixed together in an undesirable fashion. To prevent this, we need to devise a method of causing all of the flip-flops to change state at the same moment. That would be known as a synchronous counter because the flip-flops would be synchronized to operate in unison. In this lab assignment, you must design a synchronous counter version of our fourbit_counter to arrive to a new block diagram, where all flip-flops are driven by the same clock signal. You should design this counter using the Karnaugh Maps method and utilize JK flip-flops instead of T flip-flops. In addition, the top-level design of the fourbit_counter should have an additional input, RESET, which when set to logic 1 forces the counter to the initial state 0000. The RESET input should be controlled by one of the pushbuttons of the Atlys board. Optional: Remove entirely the clock divider from the design. Instead of the clock signal of 100 MHz utilize a signal from one of the pushbuttons of the Atlys board. In this case, the counter will advance each time the pushbutton is pressed. Modify the counter such that it can be told to count up or down. Lab report and demo You must turn-in a lab report, which should contain the following: Lab title Your name Introduction section a brief description of the problem you solve in this lab assignment, outlining the goal and design requirements. Solution details of your Karnaugh Maps method. Include all block diagrams and K-maps you need to illustrate each step. This section must be hand-written. VHDL code of your entire design. Use smaller font to save space. Conclusion describe your results and any issues you may have faced during this assignment and how you solved them. For full credit, you must demo the correct operation of your counter to the TA during the next lab. 5