Home / Learn Verilog / Project 6: SPI ADC Voltmeter
Project 6: SPI ADC Voltmeter
Read a potentiometer with an MCP3008 and show the value.
Theory in plain words
The basic idea
You will read a 10-bit analog voltage through SPI and show it on LEDs or the 7-segment display as a voltage.
Why this comes up
Projects turn knowledge into skill: you design, simulate, debug and finally see real hardware react.
The mechanics
Simulate in the browser, then build for your board following the steps.
Where it is used
- Portfolio
- Interviews
- Learning by doing
What you will build
You will read a 10-bit analog voltage through SPI and show it on LEDs or the 7-segment display as a voltage.
| Level | Time | Works in simulation only? |
|---|---|---|
| Intermediate | 4 hours | Simulation with a model; real chip needs 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.
| Item | What it is (in simple words) | Why you need it | Approx. 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 |
| Free software: Icarus Verilog + GTKWave (simulation), Yosys + nextpnr or the vendor IDE (build), openFPGALoader (program) | The programs that compile and simulate your design. | Everything in this course can be simulated with only these free tools. | free |
| 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) |
| SPI ADC chip or module (MCP3008 / MCP3202) | Analog-to-digital converter: turns a voltage (0-3.3 V) into a number (0-1023) and sends it over SPI. | The FPGA has no analog input, so this chip reads sensors for it. | $3 |
| Potentiometer (10 kohm) | A knob whose middle pin gives a voltage between 0 and 3.3 V depending on the knob position. | A simple analog test signal for the ADC. | $1 |
| Breadboard + jumper wires | A plastic board with holes connected in rows; wires plug in without soldering. | Connect the FPGA pins to buttons, LEDs and modules quickly and safely. | $5 |
| Multimeter | Measures voltage, resistance and continuity. | Check that a pin is 3.3 V, that wires connect, and that power is correct. | $10 |
| 7-segment display module (4 digits) | Four digits made of seven LED bars each. One shared set of segment lines, one select line per digit. | Shows numbers such as a clock or counter. | $2 |
Connections
| Signal | Direction | Goes to | Note |
|---|---|---|---|
| sclk | output | ADC CLK | |
| mosi | output | ADC DIN | |
| miso | input | ADC DOUT | |
| cs_n | output | ADC CS | active low |
| VREF, VDD | - | 3.3 V | ADC reference = full scale |
| CH0 | input | potentiometer middle pin | outer pins to 3.3 V and GND |
Step 1: simulate the design
The model returns 682 which is 2.2 V at a 3.3 V reference. Compare with the real chip using a multimeter.
Step by step
- Read the datasheet frame: start bit, SGL/DIFF, 3 channel bits, then 10 data bits.
- Simulate with the model above (the model is simplified, check timing with the datasheet).
- Keep SCLK under 1 MHz at 3.3 V (the chip limit is about 1.35 MHz).
- Show the 10-bit value on 10 LEDs, then on 7-segments as millivolts.
- Compare with a multimeter reading on the pot.
If it does not work
| Symptom | Likely cause | Fix |
|---|---|---|
| Board not detected by the PC | Charge-only USB cable or missing driver | Try another data cable; install the vendor/FTDI driver; check dmesg or Device Manager |
| Nothing happens after programming | Wrong clock pin or wrong pin constraints | Compare every pin with the board schematic; first test with a blinking LED |
| Always 0 or 1023 | Wrong channel or VREF not connected | Tie VREF to 3.3 V and check CH0 wiring |
| Noisy readings | Long wires, no decoupling | Add a 100 nF capacitor VDD to GND, average 8 readings |
Quick check
1. 10-bit ADC on 3.3 V: one step is about...
3.3 / 1024.