Lab 3

Build a flip-flop from two latches

Connect two D latches so only one is transparent at a time. SW0 is D and SW1 is the clock. LED1 shows the master. LED0 shows the slave output. Predict which LED can change while the clock is low.

Lab setup

Physical DE1-SoCCyclone V · 5CSEMA5F31C6 · camera, switches and buttons in the browser

Use Technology Map Viewer in desktop Quartus to inspect the mapped logic. Upload the bitstream to check its behavior on the board.

  1. Install Quartus Prime Lite with Cyclone V supportSkip this if it is already installed.
  2. Download the activityDownload worksheet and Quartus project Includes the worksheet, the Quartus project and the simulation files.
  3. Complete the design and compileComplete the design as Build in the worksheet below describes. Open master_slave.qpf and choose Processing → Start Compilation. Quartus writes output_files/master_slave.sof.
  4. Upload the bitstream to LabsLandUpload bitstream LabsLand asks you to sign in. Use the access your course or institution provides.

Already compiled? Upload your .sof directly

Starter files · Verilog · Quartus 24.1 · VHDL · Quartus 24.1 · SystemVerilog · Quartus 24.1

Build

Open project/master_slave.qpf from your Quartus worksheet ZIP. Inspect both gate connections. The starter can make both latches transparent together. Repair their clock phases so the slave presents the value captured on the rising edge. Run the bench, compile and trace the path through both stages in Technology Map Viewer (Post-Mapping).

Simulate

Extract the complete worksheet ZIP. In the folder containing activity.md, run the commands below with Icarus Verilog for Verilog or SystemVerilog, or NVC for VHDL. The testbench applies the switch sequence and checks the observable retained states.

test_master_slave.v

test_master_slave.vhd

Verilog

iverilog -g2005 -s test_master_slave -o bench project/master_slave.v simulation/test_master_slave.v
vvp bench

SystemVerilog

iverilog -g2012 -s test_master_slave -o bench project/master_slave.sv simulation/test_master_slave.v
vvp bench

VHDL

nvc --std=2008 -a project/master_slave.vhd simulation/test_master_slave.vhd
nvc --std=2008 -e test_master_slave
nvc --std=2008 -r test_master_slave

Test on the DE1-SoC

Upload output_files/master_slave.sof through the DE1-SoC bitstream uploader. Start with D and clock low. Pulse the clock high then low to establish a known output. Raise D with clock low. Raise the clock. Lower D while clock stays high, then lower the clock. Read the LEDs after each action. Explain the interval in which the master and slave disagree.

Switch action Previous output Predicted Camera

FPGAcademy · Digital Logic · Lab 3 · III. VERILOG · VHDL · MIT