Lab 7

Transmit Morse with a finite state machine

An LED must send A through H at a pace a person can read. A dot lasts half a second, a dash lasts one and a half seconds, and successive marks within a letter have half a second of darkness between them. Design the controller as a state machine. Before opening the starter, sketch idle, dot, the three units of a dash, and the gap between symbols. Label the transitions that depend on the next symbol or the number of symbols remaining.

Select A through H with SW2–0 (A = 000). KEY1 starts one letter, KEY0 resets it immediately and LEDR0 transmits it. The controller samples the selected letter at the start. CLOCK_50 counts 25,000,000 cycles per half second. Compare the transition leaving the first dash unit with the one in your sketch. A divider change would affect the dots and gaps as well as the dashes.

Lab setup

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

Run the simulation on your computer with Icarus Verilog (Verilog or SystemVerilog) or NVC (VHDL). Then build your design and test it on the remote DE1-SoC.

  1. Get the starterDownload morse_fsm.v
  2. Open the LabsLand Online EditorOpen the lab LabsLand asks you to sign in. Use the access your course or institution provides.
  3. Follow the worksheetPredict first, then build, read the board and hand in. The build steps are below.

Starter files · Verilog · VHDL · SystemVerilog

Simulate

The testbench holds KEY1 down while sending E. Predict how many dots you should see before the key is released.

Extract the worksheet ZIP and run these commands from the folder containing activity.md.

The bench uses five clock edges per half-second unit and checks the light at every edge for all eight letters. It also changes the selector during a letter and asserts reset between clock edges. Run it on the starter, record the first pulse that is too short, and repeat after your correction.

test_morse.v

test_morse.vhd

Verilog

iverilog -g2005 -s test_morse -o bench starter/morse_fsm.v simulation/test_morse.v
vvp bench

SystemVerilog

iverilog -g2012 -s test_morse -o bench starter/morse_fsm.sv simulation/test_morse.v
vvp bench

VHDL

nvc --std=2008 -a starter/morse_fsm.vhd simulation/test_morse.vhd
nvc --std=2008 -e test_morse
nvc --std=2008 -r test_morse

Build

When the corrected design reports PASS A-H, use the same source file for the board. Keep the half-second unit at 25,000,000 clock cycles.

  1. In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
  2. Create morse_fsm, paste the design and set it as the top level.
  3. Choose Synthesize → Upload to FPGA. After editing the design, synthesize and upload it again to test the change on the board.

Time the physical signal

Send E, then A, then B. Estimate the time LEDR0 stays on during each mark. Decode the remaining letters without looking at the switch setting. If a camera refresh skips a transition, send the letter again. Use the simulation for exact clock counts.

Test Expected pattern Camera observation
A, B, C, D .− / −... / −.−. / −..
E, F, G, H . / ..−. / −−. / ....
Select C while B is transmitting
Press KEY0 during the first dash of B
Send E after reset

Explain which state holds the LED low between marks, which state ends the last mark and why the letter stays consistent after the switches move. Submit your diagram and one measured dot/dash pair.

Original LabsLand activity following FPGAcademy Digital Logic Lab 7, Part IV. Verilog handout · VHDL handout · MIT