Home / Learn Verilog / Project 1: LED Pattern Generator

Project 1: LED Pattern Generator

Knight-rider, binary counter and blink patterns on LEDs.

The short versionKnight-rider, binary counter and blink patterns on LEDs.

Theory in plain words

Pattern generatorclockdivider tickpattern FSMLEDs
Pattern generator

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.

LevelTimeWorks in simulation only?
Beginner2 hoursNo: 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.

ItemWhat it is (in simple words)Why you need itApprox. 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 resistorsAn 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

SignalDirectionGoes toNote
clkinputboard 27 MHz oscillator pincomes with the board
btninputuser buttonactive low on most boards
led[7:0]outputeight LEDsuse 330 ohm resistors for external LEDs

Step 1: simulate the design

Knight-rider scanner (simulation clock sped up)Verilog: edit and run

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

  1. Run the simulation and watch led[7:0] move.
  2. Replace DIV with 3_000_000 for a 27 MHz clock (about 9 steps per second).
  3. Write the top-level that connects clk, btn and led to board pins.
  4. Add pin constraints from the board manual.
  5. Build, program, press the button to switch patterns (try adding a binary counter mode).

Step 2: top-level for the board

Top-level wrapper and pin constraints (adapt pin names to your 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 manual

If it does not work

SymptomLikely causeFix
Board not detected by the PCCharge-only USB cable or missing driverTry another data cable; install the vendor/FTDI driver; check dmesg or Device Manager
Nothing happens after programmingWrong clock pin or wrong pin constraintsCompare every pin with the board schematic; first test with a blinking LED
LEDs too dim or offActive-low LEDs on the boardInvert the output: assign led_pin = ~led;
Pattern too fast to seeDIV left at 2Use 3_000_000 for 27 MHz
Tip:Keep your first board test tiny: if the LED blinks, the toolchain, cable and clock are fine. Then add your project piece by piece.

Quick quiz

1. A divider is needed because...