Arduino Custom Verilog Chip: Wiring, Code and Simulator

To build this Arduino Custom Verilog Chip project you need an Arduino Uno and a Verilog chip and an LED bar graph. A 4-bit counter written in Verilog sits on the board like any other chip. The Uno clocks it and reads its outputs back. Make the 14 connections in the wiring table, upload the Arduino C++ code, and select the chip and edit its Verilog: make it count down (q <= q - 1), or add an enable input. Run again to see your hardware change.

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1Verilog ChipDesign your own chip in Verilog: its ports become pins (inputs left, outputs right). It is synthesized with Yosys when you press Run.
1LED Bar GraphTen LEDs in a row: A1–A10 anodes, C1–C10 cathodes.

Wiring

#FromTo
1Arduino Uno pin 2Verilog Chip clk
2Arduino Uno pin 3Verilog Chip rst
3Verilog Chip q[0]LED Bar Graph A1
4Verilog Chip q[1]LED Bar Graph A2
5Verilog Chip q[2]LED Bar Graph A3
6Verilog Chip q[3]LED Bar Graph A4
7Arduino Uno A0Verilog Chip q[0]
8Arduino Uno A1Verilog Chip q[1]
9Arduino Uno A2Verilog Chip q[2]
10Arduino Uno A3Verilog Chip q[3]
11Arduino Uno GNDLED Bar Graph C1
12Arduino Uno GNDLED Bar Graph C2
13Arduino Uno GNDLED Bar Graph C3
14Arduino Uno GNDLED Bar Graph C4

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add a Verilog chip and an LED bar graph from the parts palette.
  3. Wire 1. Connect Arduino Uno pin 2 to Verilog Chip clk.
  4. Wire 2. Connect Arduino Uno pin 3 to Verilog Chip rst.
  5. Wire 3. Connect Verilog Chip q[0] to LED Bar Graph A1.
  6. Wire 4. Connect Verilog Chip q[1] to LED Bar Graph A2.
  7. Wire 5. Connect Verilog Chip q[2] to LED Bar Graph A3.
  8. Wire 6. Connect Verilog Chip q[3] to LED Bar Graph A4.
  9. Wire 7. Connect Arduino Uno A0 to Verilog Chip q[0].
  10. Wire 8. Connect Arduino Uno A1 to Verilog Chip q[1].
  11. Wire 9. Connect Arduino Uno A2 to Verilog Chip q[2].
  12. Wire 10. Connect Arduino Uno A3 to Verilog Chip q[3].
  13. Wire 11. Connect Arduino Uno GND to LED Bar Graph C1.
  14. Wire 12. Connect Arduino Uno GND to LED Bar Graph C2.
  15. Wire 13. Connect Arduino Uno GND to LED Bar Graph C3.
  16. Wire 14. Connect Arduino Uno GND to LED Bar Graph C4.
  17. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  18. Run it. Press Run. Select the chip and edit its Verilog: make it count down (q <= q - 1), or add an enable input. Run again to see your hardware change.

Arduino C++ code

// A chip you designed in Verilog, wired to the Uno.
// The chip is a 4-bit counter: pin 2 clocks it, pin 3 resets it,
// and its outputs q[0]..q[3] light the bar graph and come back on A0..A3.
const int CLK = 2;
const int RST = 3;

void pulse(int pin) {
  digitalWrite(pin, HIGH);
  digitalWrite(pin, LOW);
}

void setup() {
  Serial.begin(9600);
  pinMode(CLK, OUTPUT);
  pinMode(RST, OUTPUT);
  for (int i = 0; i < 4; i++) pinMode(A0 + i, INPUT);

  // Hold reset through one clock edge: q goes to 0.
  digitalWrite(RST, HIGH);
  pulse(CLK);
  digitalWrite(RST, LOW);
}

void loop() {
  pulse(CLK);                    // one rising edge: q = q + 1
  int q = 0;
  for (int i = 0; i < 4; i++) q |= digitalRead(A0 + i) << i;
  Serial.print("count = ");
  Serial.println(q);
  delay(400);
}

What to try

Select the chip and edit its Verilog: make it count down (q <= q - 1), or add an enable input. Run again to see your hardware change.

Frequently asked questions

How do I wire the Custom Verilog Chip project on an Arduino Uno?

Make 14 connections: Arduino Uno pin 2 to Verilog Chip clk; Arduino Uno pin 3 to Verilog Chip rst; Verilog Chip q[0] to LED Bar Graph A1; Verilog Chip q[1] to LED Bar Graph A2; Verilog Chip q[2] to LED Bar Graph A3; Verilog Chip q[3] to LED Bar Graph A4; Arduino Uno A0 to Verilog Chip q[0]; Arduino Uno A1 to Verilog Chip q[1]; Arduino Uno A2 to Verilog Chip q[2]; Arduino Uno A3 to Verilog Chip q[3]; Arduino Uno GND to LED Bar Graph C1; Arduino Uno GND to LED Bar Graph C2; Arduino Uno GND to LED Bar Graph C3; Arduino Uno GND to LED Bar Graph C4.

What parts do I need for this Arduino project?

An Arduino Uno and a Verilog chip and an LED bar graph.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

A 4-bit counter written in Verilog sits on the board like any other chip. The Uno clocks it and reads its outputs back.

More Arduino Uno projects