Logic gates on switches
Every digital circuit is built from a few gates. In Verilog they are operators: & (AND), | (OR), ^ (XOR) and ~ (NOT).
Use switches 0 and 1 as the inputs and put one gate on each of LEDs 0–3. Flip the switches on the board and check each LED against the truth table.
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 = sw0 AND sw1
- ○LED 1 = sw0 OR sw1
- ○LED 2 = sw0 XOR sw1
- ○LED 3 = NOT sw0
Hints
assign led[0] = sw[0] & sw[1];- XOR is 1 when the two inputs differ.
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 switches: 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.