Home / Learn Verilog / Project 6: SPI ADC Voltmeter

Project 6: SPI ADC Voltmeter

Read a potentiometer with an MCP3008 and show the value.

The short versionRead a potentiometer with an MCP3008 and show the value.

Theory in plain words

ADC voltmeterpotMCP3008SPI master10-bit valuedisplay
ADC voltmeter

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.

LevelTimeWorks in simulation only?
Intermediate4 hoursSimulation 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.

ItemWhat it is (in simple words)Why you need itApprox. 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 wiresA 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
MultimeterMeasures 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

SignalDirectionGoes toNote
sclkoutputADC CLK
mosioutputADC DIN
misoinputADC DOUT
cs_noutputADC CSactive low
VREF, VDD-3.3 VADC reference = full scale
CH0inputpotentiometer middle pinouter pins to 3.3 V and GND

Step 1: simulate the design

MCP3008 transaction against a modelVerilog: edit and run

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

  1. Read the datasheet frame: start bit, SGL/DIFF, 3 channel bits, then 10 data bits.
  2. Simulate with the model above (the model is simplified, check timing with the datasheet).
  3. Keep SCLK under 1 MHz at 3.3 V (the chip limit is about 1.35 MHz).
  4. Show the 10-bit value on 10 LEDs, then on 7-segments as millivolts.
  5. Compare with a multimeter reading on the pot.

If it does not work

SymptomLikely causeFix
Board not detected by the PCCharge-only USB cable or missing driverTry another data cable; install the vendor/FTDI driver; check dmesg or Device Manager
Nothing happens after programmingWrong clock pin or wrong pin constraintsCompare every pin with the board schematic; first test with a blinking LED
Always 0 or 1023Wrong channel or VREF not connectedTie VREF to 3.3 V and check CH0 wiring
Noisy readingsLong wires, no decouplingAdd a 100 nF capacitor VDD to GND, average 8 readings
Tip:Keep your first board test tiny: if the LED blinks, the toolchain, cable and clock are fine. Then add your project piece by piece.

Quick check

1. 10-bit ADC on 3.3 V: one step is about...