Blink
The board's clock ticks CLK_HZ times a second (27 million on a Tang Nano 9K). A register that counts the ticks can measure time: after CLK_HZ / 2 ticks, half a second has passed.
always @(posedge clk) runs on every tick. Count up, and when the counter reaches the end, start again from 0 and flip the LED.
On the virtual board the clock runs at 1 kHz so you can watch it; on a real board CLK_HZ is set to its oscillator.
lab.v
drag to turn · scroll to zoom
Loading the board…
Press Run on the board: your Verilog is turned into gates in this browser and runs here, cycle by cycle.
Goals
- ○LED 0 blinks
- ○It changes every half second
Hints
- Use a counter wide enough for
CLK_HZ / 2: 32 bits is plenty. - When the counter reaches
CLK_HZ / 2 - 1, set it to 0 and doon <= ~on;.
Pin log
Run the design to see its outputs change.
Put it on a real board
- The clock is set to the board's 27 MHz, and its active-low buttons and LEDs are flipped for you.