Home / Learn Verilog / Project 1: LED Pattern Generator
Project 1: LED Pattern Generator
Knight-rider, binary counter and blink patterns on LEDs.
Theory in plain words
In plain terms
You will build a pattern generator that scans an LED back and forth (like KITT from Knight Rider), counts in binary and blinks. A button changes the pattern.
Why we use it
Projects turn knowledge into skill: you design, simulate, debug and finally see real hardware react.
Under the hood
Simulate in the browser, then build for your board following the steps.
Real-world use
- Portfolio
- Interviews
- Learning by doing
What you will build
You will build a pattern generator that scans an LED back and forth (like KITT from Knight Rider), counts in binary and blinks. A button changes the pattern.
| Level | Time | Works in simulation only? |
|---|---|---|
| Beginner | 2 hours | No: simulate first, then run on the board |
What you need (equipment and tools)
Read this table once and you will know exactly what to buy or prepare. You can do the simulation part with only a computer and the free tools.
| Item | What it is (in simple words) | Why you need it | Approx. cost |
|---|---|---|---|
| Computer (Windows, Linux or macOS) | Your normal laptop or desktop. You write Verilog here and run the free tools. | Simulator, synthesis and programmer all run on it. | you have it |
| FPGA development board (e.g. Tang Nano 9K, Basys 3, iCEBreaker, Arty A7) | A small circuit board with an FPGA chip, an oscillator (clock), LEDs, buttons and a USB port. The FPGA is the "blank hardware" that your Verilog turns into a real circuit. | This is where your design actually runs. Without it you can only simulate. | about $15 (Tang Nano 9K) to $150 (Arty A7) |
| USB cable (data type, not charge-only) | Cable between the board and the computer. Some cheap cables carry only power and no data. | Programs the FPGA and powers it. If the board is not found, try another cable first. | $2 |
| LEDs (5 mm) + 330 ohm resistors | An LED lights when current flows through it. The resistor limits that current so the LED and the FPGA pin do not burn. | Visible output. Many boards already have LEDs built in; external ones are for bigger demos. | $2 for a pack |
| Push buttons (tactile switches) | A small switch that connects two pins while pressed. | Your input to the design. They bounce, so the design needs a debouncer. | $1 |
Connections
| Signal | Direction | Goes to | Note |
|---|---|---|---|
| clk | input | board 27 MHz oscillator pin | comes with the board |
| btn | input | user button | active low on most boards |
| led[7:0] | output | eight LEDs | use 330 ohm resistors for external LEDs |
Step 1: simulate the design
In the waveform one LED bit travels left then right. On the board set DIV to about 3 million for a visible speed.
Step by step
- Run the simulation and watch led[7:0] move.
- Replace DIV with 3_000_000 for a 27 MHz clock (about 9 steps per second).
- Write the top-level that connects clk, btn and led to board pins.
- Add pin constraints from the board manual.
- Build, program, press the button to switch patterns (try adding a binary counter mode).
Step 2: top-level for the board
module top(input clk, input btn, output [7:0] led);
wire rst = ~btn; // active-low button
scanner #(.DIV(3_000_000)) s(clk, rst, led);
endmodule
// constraints: map clk, btn, led[0..7] to the pins from your board manualIf it does not work
| Symptom | Likely cause | Fix |
|---|---|---|
| Board not detected by the PC | Charge-only USB cable or missing driver | Try another data cable; install the vendor/FTDI driver; check dmesg or Device Manager |
| Nothing happens after programming | Wrong clock pin or wrong pin constraints | Compare every pin with the board schematic; first test with a blinking LED |
| LEDs too dim or off | Active-low LEDs on the board | Invert the output: assign led_pin = ~led; |
| Pattern too fast to see | DIV left at 2 | Use 3_000_000 for 27 MHz |
Quick quiz
1. A divider is needed because...
MHz clock vs human eye.