Transmit Morse with a finite state machine
Online version: https://fpga.labsland.com/altera/digital-logic/lab-07/part-04/
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
LabsLand Online Editor · DE1-SoC
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.
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.
- From the extracted worksheet folder, open
starter/morse_fsm.qpfin the selected release of Quartus Prime Lite with Cyclone V support. The project-only download has the QPF at its root. - Edit the HDL file for
morse_fsm. If the exercise generates a new HDL file, copy its contents into that same project file. - Choose Processing → Start Compilation. Check the Fitter report for device 5CSEMA5F31C6.
- In the LabsLand bitstream upload lab, choose Standard and upload
output_files/morse_fsm.sof. Wait for programming confirmation before using the controls. - If your course uses a LabsLand classroom, the upload opens a firmware library instead: check that your SOF is selected and choose Enter board with selected firmware.
- Get the starterDownload
morse_fsm.v - Open the LabsLand Online EditorOpen the lab Choose DE1-SoC · Verilog when you open the lab. LabsLand asks you to sign in. Use the access your course or institution provides.
- Follow the worksheetPredict first, then build, read the board and hand in. The build steps are below.
- Install Quartus Prime Lite with Cyclone V supportSkip this if it is already installed.
- Download the activityDownload worksheet and Quartus project Includes the worksheet, the Quartus project and the simulation files.
- Complete the design and compileStart with Simulate in the worksheet below, then complete the design as its build steps describe. Open
morse_fsm.qpfand choose Processing → Start Compilation. Quartus writesoutput_files/morse_fsm.sof. - 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 · VHDL · SystemVerilog
Worksheet and starter (.zip) for offline work or printing
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.
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.
- In the LabsLand Online Editor, choose DE1-SoC for your HDL and the Standard interface.
- Create
morse_fsm, paste the design and set it as the top level. - 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
