Lab 3: Sequential Logic and Counters
Loading...
Submission
Please accept the Lab 3 assignment on Classroom 50 and submit your lab report to the repository.
Ensure that your submission includes ALL required files.
Lab 3 Invitation
Due to the Classroom50 error, we will need to have you submit through Canvas until we can fix the issue.
Please download the lab 3 template and work on it in your local environment. Then submit it back to Canvas as a zip, with all required files included.
This repository must contain the archived Quartus project (.qar) file. You should not use this repository as your project directory; instead, have your Lab 3 project directory somewhere else on your local machine, and then archive and upload it to the repository when you are finished.
Documentation
Overview
- Implement counters using sequential logic and finite state machine concepts.
- Design circuits using SR latches and flip-flops.
- Create and simplify next-state logic using excitation tables and K-maps.
- Simulate and test sequential circuits in Quartus.
Please watch all the videos in the appendix related to Quartus before asking questions about it.
Introduction
In previous labs, you worked with combinational circuits, where the output is solely a function of the present input. This lab introduces sequential logic, where functions rely on both current inputs and past information (memory). You will use these principles to construct Finite State Machines (FSMs) and counters.
A counter, which is a type of FSM, counts through a sequence of numbers in some order, potentially having a reset, or inputs to go forwards and backwards. The main difference between a counter and a FSM in this course is that the counters will generally output their state, while a FSM will have more logic associated with it.
See Appendix A for the flip-flop excitation tables you will need to convert Q → Q+ transitions into the correct flip-flop inputs.
Pre-Lab Questions
- When implementing an SR latch, what happens when both S=1 and R=1?
- What is the purpose of the Clk signal?
- What is the difference between a SR flip-flop and a SR latch?
- Put a NOT gate in front of the S input of the SR flip-flop, then connect the input of that gate to the R input of the flip-flop so that S and R are always at opposite logic levels. What is the relationship between this single input and the output Q?
- Now do the same thing, except put the NOT gate in front of R instead. What is the relationship between the single input and Q?
- What are don't-care entries in an NSTT and why are they useful when simplifying logic?
- Why do we need flip-flops to build a counter? Why can't we build one with only combinational logic?
- Describe D, SR, JK, and T flip-flops: what inputs does each use, and how does Q change on a clock edge for each?
Pre-Lab Procedure
PART 1. SR LATCH & SR FLIP-FLOP:
The SR (Set-Reset) latch is a basic memory element built using feedback.
The S input sets Q to 1, while the R input resets Q to 0.
Because the output changes immediately when the inputs change, the SR latch is asynchronous.
NOR SR Latch. Can also be built from NAND gates, which inverts the inputs.
Adding an enable signal creates a gated SR latch, allowing the inputs to affect the output only when enable is active. Combining two gated SR latches creates a synchronous SR flip-flop that updates only on a clock edge.
A gated SR-latch consists of a NOR SR-Latch and AND gates connected to a clock signal.
An SR flip-flop is a synchronous component that only changes on a clock edge.
Build both circuits in Quartus (not Logisim) and simulate each to answer the pre-lab questions. Screenshots of the simulations are not required, only screenshots of the circuit designs. See Appendix C for simulation instructions.
Part 1 Deliverables:
- Screenshot of the SR Latch design in Quartus.
- Screenshot of the SR flip-flop design in Quartus.
PART 2. 2-BIT COUNTER:
Using the flip-flops from Part 1, you will now build a 2-bit counter that cycles through the following sequence:
1 → 3 → 2 → 1 → 3 → 2 → 1 → …
Counter specifications:
- Input GO(H): when high, the counter advances; when low, it holds its current value.
- RESET(L): asynchronous active-low reset to 1.
- Use the flip-flop's CLRN pin (active-low → Q=0) and PRN pin (active-low → Q=1) to implement this. Unused CLRN/PRN pins must be tied to VCC.
- The most significant state bit (Q1) must use a JK flip-flop; Q0 must use a D flip-flop.
Design steps:
- Draw the NSTT in counting order (columns: Q1 Q0 GO(H) | Q1+ Q0+). Use don't-cares for unused or undefined states and any input combinations that cannot occur. Color every other row gray. NSTTs must not be hand-drawn.
- Use the excitation tables in Appendix A to derive the flip-flop inputs D0, J1, K1 from the Q→Q+ columns.
- Build K-maps for D0, J1, and K1 and extract MSOP or MPOS equations. Use don't-cares to simplify.
- Implement the circuit in a Quartus .bdf file. This counter is simulation-only - no DE10 pin assignments needed.
- Simulate in Quartus and annotate the screenshot so it is clear what happens at each clock edge (state, inputs, reason for transition). See Appendix C for simulation steps.
Your NSTT should have the following column format:
| Q1 | Q0 | GO(H) | Q1+ | Q0+ |
|---|
RESET(L) is not included in the NSTT because it is an asynchronous input and is not part of the next-state combinational logic.
NSTTs must be colored gray every other row for readability. Points will be deducted if this is not done. NSTTs must not be on paper.
Part 2 Deliverables:
- Comprehensive NSTT (alternating gray rows, typed, not hand-drawn).
- K-maps and MSOP/MPOS equations for D0, J1, and K1 (don't-cares required).
- Screenshot of the complete circuit in a Quartus .bdf file.
- Annotated simulation screenshot showing reset, hold (GO=0), and counting behavior at each clock edge.
PART 3. 3-BIT BIDIRECTIONAL COUNTER WITH OUTPUT LOGIC:
This counter uses 3 state bits (Q2 Q1 Q0) but outputs a 4-bit hex value (Y3-Y0) through additional output logic. It also counts both forward and backward based on input F(H).
Count sequences:
F(H)=1 (forward): 4 → 5 → A → B → 2 → 4 → …
F(H)=0 (backward): 4 → 2 → B → A → 5 → 4 → …
Counter specifications:
- Q2 → JK flip-flop | Q1 → T flip-flop | Q0 → D flip-flop.
- Input RESET(L): asynchronous active-low reset to 4. Same CLRN/PRN approach as Part 2.
- Outputs Y3-Y0 represent the displayed hex digit. There is no required mapping between states and outputs, so choose whichever state assignments are most convenient. Include a table clearly showing the mapping between Q2Q1Q0 and the output value.
- The 4-bit output Y3-Y0 drives a single 7-segment display on the DE10-Lite via the ssgdecoder component (see Appendix B).
- Use a DE10-Lite button as CLK, and two switches for F(H) and RESET(L). Check the pin assignments to find the correct Quartus pin names for each button and switch.
Design steps:
- Draw the NSTT (alternating gray rows, typed). Use don't-cares for undefined states.
- Use the excitation tables (Appendix A) and K-maps to derive J2, K2, T1, D0 and the output equations for Y3-Y0. Use don't-cares throughout.
- Implement in Quartus .bdf, including the ssgdecoder component (Appendix B).
- Assign pins and program the DE10-Lite. Demo this in lab (simulation is not required for Part 3).
Your NSTT should have the following column format:
| Q2 | Q1 | Q0 | F(H) | Q2+ | Q1+ | Q0+ | Y3 | Y2 | Y1 | Y0 |
|---|
NSTTs must be colored gray every other row for readability. Points will be deducted if this is not done. NSTTs must not be on paper.
Part 3 Deliverables:
- Comprehensive NSTT with state-to-output mapping table (alternating gray rows, typed).
- K-maps and equations for J2, K2, T1, D0, and Y3-Y0 (don't-cares required).
- Screenshot of the complete circuit in a Quartus .bdf file including the ssgdecoder component.
- Working demo on DE10-Lite in lab.
In-Lab Procedure
- You will demo your circuit working from part 3 to your PI.
- Complete the quiz in-lab as specified by your PI.
Submission Files
- lab3.qar (Quartus project archive file)
- lab3.pdf
- Screenshot of the SR Latch design in Quartus.
- Screenshot of the SR flip-flop design in Quartus.
- Comprehensive NSTT (alternating gray rows, typed, not hand-drawn).
- K-maps and MSOP/MPOS equations for D0, J1, and K1 (don't-cares required).
- Screenshot of the complete circuit in a Quartus .bdf file.
- Annotated simulation screenshot showing reset, hold (GO=0), and counting behavior at each clock edge.
- Comprehensive NSTT with state-to-output mapping table (alternating gray rows, typed).
- K-maps and equations for J2, K2, T1, D0, and Y3-Y0 (don't-cares required).
- Screenshot of the complete circuit in a Quartus .bdf file including the ssgdecoder component.
- Working demo on DE10-Lite in lab.
Appendix A: Flip-flop Excitation Tables
X = Don't care, regardless of value output will be what is in the table. These tables represent the behavior of flip-flops on a clock edge. J, K, T, and D represent the inputs to a JK-FF, T-FF, and a D-FF respectively. Q represents the output of the FF before the clock edge, and Q+ represents the output of the FF after the clock edge.
| J | K | Q | Q+ |
|---|---|---|---|
| 0 | X | 0 | 0 |
| 1 | X | 0 | 1 |
| X | 0 | 1 | 1 |
| X | 1 | 1 | 0 |
| T | Q | Q+ |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
| D | Q | Q+ |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Appendix B: Adding the 7-Segment Decoder to a Quartus .bdf
In this lab, you will use a provided VHDL seven-segment decoder component for the DE10-Lite display. Follow these steps to add the ssgdecoder.vhd file as a symbol in Quartus.
- Download the provided ssgdecoder.vhd file and place it in your Quartus project folder.
- After setting up a Quartus project click on "Project" and select "Add/Remove Files in Project".
- Click on the three dots to open up file explorer and navigate to where you downloaded ssgdecoder.vhd and select it.
- Once you see that the file is set up to be added to the project select "Ok" and the window should close.
- Now in Project Navigator select Files and double click ssgdecoder.vhd so that it opens up in the Quartus text editor.
- To make the block symbol file (.bsf) component to add to a .bdf file click on File > Create / Update > Create Symbol Files for Current File. This will create a .bsf file in your project directory.
- Now open the .bdf in Quartus and add a Symbol like any of the other basic gate types.
- Since the .bsf we created should be in the Project directory (if you followed the previous instructions) you can expand the project folder and find the ssgdecoder symbol to add to your .bdf.
Appendix C: How to Simulate Designs in Quartus
Functional simulation allows you to test your circuit behavior before programming the FPGA. This helps catch logic errors quickly without recompiling and downloading to hardware after every change. You need to create a BDF file first, then you can simulate it. Follow these steps to simulate your design in Quartus. Also see Quartus Tutorial for more details on making your BDF and simulation.
- Run Analysis and Synthesis to make sure your design doesn't have any syntactic errors.
- Click File > New.
- Select "University Program VWF" and click "OK" which should now show the Simulation Waveform Editor window.
- Click Edit > Insert > Insert Node or Bus.
- Click Node Finder in the dialog box.
- Set the filter to "Pins: All" or "Signals: All".
- Click List to display all available signals (they are called Nodes here).
- Select the input and output signals you want to simulate.
- Click the > arrow to add them to the waveform.
- Click the >> arrow if you would like to add all listed signals to the waveform.
- Click OK to close Node Finder.
- Click OK again to insert the signals into the waveform window.
- Click and drag to highlight signals on the input rows, then set logic values to '1' or '0' by clicking the 1 or 0 buttons at the top, or by right-clicking the selected interval and forcing it high or low.
- Click Simulation > Run Functional Simulation (or press the play button).
- You will be prompted to save the waveform file in your project folder (e.g., Waveform.vwf). Save it.
- View the output waveforms below the input signals.
- Zoom in/out to examine timing and verify correctness.