Dice roller
A clock running millions of times a second is a good source of chance: count 1, 2, … 6, 1, … on every cycle while button 0 is held. Nobody can time their release to the cycle, so where it stops is random.
Show the face on hex0 and keep it still once the button is up.
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
- ○After a roll, hex0 shows 1–6
- ○All six faces turn up
- ○The face stays put until the next roll
Hints
if (btn[0]) face <= (face == 6) ? 1 : face + 1;- Registers start at 0, so the display shows 0 until the first roll. That's fine.
Pin log
Run the design to see its outputs change.
Put it on a real board
- The Sipeed Tang Nano 9K (Gowin GW1NR-9) has no a 7-segment display: those ports go to header pins, where you can wire them.
- The clock is set to the board's 27 MHz, and its active-low buttons and LEDs are flipped for you.