Teach lesson
Digital Logic on the DE1-SoC (1/6): Your first gates on real hardware
Students write Verilog for basic logic gates, synthesize and upload to the DE1-SoC, and verify truth tables on real switches and LEDs.
Learning Outcomes
Explain that Verilog describes hardware, not a program that runs step by step.
Use the LabsLand DE1-SoC Verilog workflow: edit, Synthesize, Upload, observe.
Build the six basic logic gates and verify their truth table on real hardware.
Recognize active-high LEDs and active-low pushbuttons on the DE1-SoC.
Student activity preview
Activity Content
Preview only. In a class session, students can fill in responses and submit their work to the teacher.
What you are about to do
12 min
Most programming you have seen runs on a processor: instructions execute one after another. In this course you will do something different. You will describe a digital circuit in a language called Verilog, and a real chip will be configured to become that circuit. There is no processor running your lines one by one — your description becomes actual wires and gates that all operate at once.
The chip is an FPGA (Field-Programmable Gate Array): an integrated circuit containing a large grid of logic blocks whose connections can be reconfigured. The board is a Terasic DE1-SoC with an Intel/Altera Cyclone V FPGA — the same board used in many university digital-design courses. You reach a real one through your browser with LabsLand: a server runs Intel Quartus to turn your Verilog into a configuration file, programs the physical board, and streams a live camera so you can see the real LEDs respond.
The board parts you will use in this course:
- SW[9:0] — 10 slide switches you control on screen. A switch up is logic 1.
- KEY[3:0] — 4 pushbuttons. These are active-low: a button reads 0 when pressed and 1 when released.
- CLOCK_50 — a 50 MHz clock signal (used from Lesson 3 on).
- LEDR[9:0] — 10 red LEDs, with LEDR0 at the right end of the row and LEDR9 at the left. These are active-high: an LED lights when you drive it 1.
- HEX0–HEX5 — six 7-segment displays. These are active-low: a segment lights when you drive it 0.
The workflow (the same every lesson): the LabsLand Verilog editor opens with one file, leds_mirror.v, containing a top-level module called leds_mirror. You will replace the contents of that file with the design for the exercise (always keeping the module named leds_mirror), then click Synthesize, wait for it to finish, click Upload to FPGA, and use the on-screen switches while watching the camera. If a guided tour or help overlay covers the editor buttons, close or skip the tour before continuing.
The course workflow: edit leds_mirror.v, Synthesize (server-side Quartus), Upload to FPGA, then drive the on-screen switches and read the live camera. Your Verilog module is synthesized directly as the top-level design, so you only ever edit this one file.
Which statement best describes what your Verilog does in this lab?
On this board, an LED lights when you drive it to which value, and a pushbutton KEY reads which value when it is pressed? (One sentence.)
The six basic gates
12 min
A logic gate takes one or more binary inputs and produces a binary output. Six gates cover almost everything in this course. With inputs A and B:
Truth table for A, B:
- A=0, B=0 -> AND 0, OR 0, NOT A 1, NAND 1, NOR 1, XOR 0
- A=0, B=1 -> AND 0, OR 1, NOT A 1, NAND 1, NOR 0, XOR 1
- A=1, B=0 -> AND 0, OR 1, NOT A 0, NAND 1, NOR 0, XOR 1
- A=1, B=1 -> AND 1, OR 1, NOT A 0, NAND 0, NOR 0, XOR 0
In Verilog these are the bitwise operators & | ~ ^. The design below wires switch SW[0] to A, SW[1] to B, and sends each gate's result to one LED. assign means "this output continuously equals this expression" — exactly what a wire of gates does.
// Lesson 1 — basic gates. Replace ALL contents of leds_mirror.v with this.
module leds_mirror(SW, LEDR);
input [9:0] SW; // SW[0] = A, SW[1] = B (other switches unused)
output [9:0] LEDR;
wire A = SW[0];
wire B = SW[1];
assign LEDR[0] = A & B; // AND
assign LEDR[1] = A | B; // OR
assign LEDR[2] = ~A; // NOT A
assign LEDR[3] = ~(A & B); // NAND
assign LEDR[4] = ~(A | B); // NOR
assign LEDR[5] = A ^ B; // XOR
assign LEDR[9:6] = 4'b0000; // unused LEDs held off
endmodule
Before you run it, work out the initial LED pattern yourself. With both switches down, A=0 and B=0 — find that row in the truth table above and decide, for each of the six gates, whether its output is 1. You will check your prediction against the live board in the next step.
With both switches down (A=0, B=0), which of LEDR[0]–LEDR[5] do you predict will be lit? List them before you run the design.
Synthesize, upload, and verify
16 min
Now build the circuit on the real board and check it against the truth table.
Open the DE1-SoC Verilog lab. The editor shows a file
leds_mirror.v.Select all of the contents of
leds_mirror.vand replace them with the basic-gates module above. Keep the module namedleds_mirror.Click Synthesize. If a guided tour covers the button, close or skip the tour first. Wait for it to finish (about 1-3 minutes). If it reports an error, check for a missing semicolon or mismatched parenthesis, fix it, and Synthesize again. A build can show many warnings; continue only when the final status says the build succeeded with 0 errors.
Click Upload to FPGA and wait for the live board session and camera.
With both on-screen switches
SW0andSW1down (A=0, B=0), read the lit LEDs on the camera and compare with your prediction.Set
SW1up (A=0, B=1), thenSW0up (A=1, B=0), then both up (A=1, B=1), reading the six LEDs each time.
For each input row, set the switches and record what the six LEDs show on the camera (1 = lit, 0 = off). Compare with the truth table in the previous step.
| A = SW0 | B = SW1 | LEDR0 AND | LEDR1 OR | LEDR2 NOT A | LEDR3 NAND | LEDR4 NOR | LEDR5 XOR |
|---|---|---|---|---|---|---|---|
Upload your evidence. Capture a camera screenshot with both switches up (SW = 11) — LEDR0 (AND) and LEDR1 (OR) lit, the others off — and attach it in the response box below.
Which single gate outputs 1 for exactly one input combination — the row A=1, B=1?
Which single gate outputs 1 for exactly one input combination — the row A=0, B=0?
In plain English, what do NAND and NOR mean in terms of AND/OR plus NOT? Use your recorded data to justify your answer.
Workflow check
10 min
Which sequence matches what you just did?
In three sentences, explain what "Synthesize" did, what "Upload to FPGA" did, and how you knew the gates were working. Mention one place where active-high or active-low polarity mattered.