Skip to content
4. Up/Down Counter & Stopwatch

4. Up/Down Counter & Stopwatch

Three 7-segment digits alongside Soan Papdi

This project turns the Soan Papdi board into a 3-digit counter that displays on a common-cathode 7-segment display. It can count up, count down, or act as a stopwatch (counting in 0.1 second steps). You can start/pause it and reset it back to zero using the onboard switches and buttons.


What You Need

  • Soan Papdi board (iCE40 UP5K)
  • 3-digit common-cathode 7-segment display
  • 7 × 220–330 Ω current-limiting resistors

Hardware Connections

FPGA → 7-Segment Display

SignalFPGA PinDescription
clk35Onboard 12 MHz clock
mode[0]3Mode select bit 0
mode[1]48Mode select bit 1
run4Run / Pause button
reset12Reset button
comm[0]18Digit 1 common (rightmost digit)
comm[1]19Digit 2 common (middle digit)
comm[2]20Digit 3 common (leftmost digit)
seg[0]28Segment g
seg[1]27Segment f
seg[2]26Segment e
seg[3]25Segment d
seg[4]23Segment c
seg[5]13Segment b
seg[6]21Segment a

7-segment display wired on breadboard

comm is active-low (a digit turns on when its line goes low), seg is active-high. Put a 220–330 Ω resistor on each of the 7 segment lines to limit current.

Need to check another pin? See the full Pin Diagram.

Clone the Example Project

git clone https://github.com/hardik1975/soan-papdi-examples.git
cd soan-papdi-examples/04-counter

Project Files Explained

FileWhat it does
top.vComplete design: clock dividers, the actual counter, digit multiplexing, and 7-segment decoding
pin.pcfMaps all signal names to the real pins on the Soan Papdi board

Understanding the Hardware Logic

The whole design lives in a single file (top.v) and is divided into four clear parts.


1. Clock Divider

The board clock runs at 12 MHz. We need much slower ticks:

  • 1 Hz tick → for normal up/down counting (once per second)
  • 10 Hz tick → for stopwatch mode (tenths of a second)

Two counters divide the 12 MHz clock down to these two rates. A simple multiplexer chooses which tick to use depending on the mode.

wire pulse = (mode == 2'b10) ? clk_10hz : clk_1hz;

2. The Counter (BCD)

Three 4-bit registers hold the digits:

  • d0 → ones (0–9)
  • d1 → tens (0–9)
  • d2 → hundreds (0–9)

Behaviour according to mode

modeBehaviour
00Count up once per second
01Count down once per second
10Stopwatch – count up 10 times per second

When run is high and a pulse arrives, the counter updates. When reset is pressed, all three digits go back to 0.

The counting logic correctly handles the carry (9 → 0 and increment next digit) for both up and down directions.


3. Digit Multiplexing

A 7-segment display has only one set of 7 segment pins, but we have 3 digits. The solution is time-division multiplexing:

  1. Light digit 0 (right) for a short time
  2. Light digit 1 (middle) for a short time
  3. Light digit 2 (left) for a short time
  4. Repeat very fast

The comm signals select which digit is currently active (active-low).


4. 7-Segment Decoder

Whatever digit is currently selected is converted from its BCD value (0–9) into the correct pattern of the 7 segments (a–g):

   ── a ──
  |       |
  f       b
  |       |
   ── g ──
  |       |
  e       c
  |       |
   ── d ──

Example patterns (abcdefg):

0 → 1111110
1 → 0110000
2 → 1101101
...
9 → 1110011

Mode Selection

Use the two mode switches:

mode[1:0]Function
00Count up (1 second steps)
01Count down (1 second steps)
10Stopwatch (0.1 second steps)

Count up

Count up mode

Count down

Count down mode

Stopwatch

Stopwatch mode

  • run = 1 → counter runs
  • run = 0 → counter pauses
  • reset = 1 → everything goes back to 000

Build & Flash

  1. Connect the Soan Papdi board to your computer via USB.
  2. Put the board into Programming Mode.
  3. Build the design:
apio build
  1. Upload the bitstream:
apio upload
  1. Press the Reset button on the Soan Papdi.

How to Use It

  1. Set the mode switches to choose Up / Down / Stopwatch.
  2. Press the run button to start counting.
  3. Press run again to pause.
  4. Press reset to go back to 000.

Bonus: Visualize Your Logic

apio graph --pdf

This generates a diagram of the counters, multiplexers, and decoder in the _build folder.

Counter Logic Graph