802 MNIST Digit Recognition

802 : MNIST Digit Recognition

Design render

How it works

This project is a fully self-contained MNIST handwritten-digit classifier. All neural-network weights live on-chip: they are ternary ({-1, 0, +1}) and are baked into the netlist as Verilog constants, so synthesis constant-folds them into plain logic — no RAM, no ROM macros, no weight loading.

The network is an MLP 64 -> 32 -> 10 with binary {0,1} hidden activations (a linear 64 -> 10 and an MLP 64 -> 16 -> 10 are selectable at synthesis time via the MLP / HIDDEN parameters). It was trained with quantization-aware training (straight-through estimators for the ternary weights and binary activations) on MNIST images that were average-pooled from 28×28 to 8×8 and binarized at a fixed threshold (0.15 of full scale). Test-set accuracy of the exact integer model (10,000 images):

Variant Accuracy
MLP 64→32→10 (default, this submission) 80.3 %
linear 64→10 78.3 %
MLP 64→16→10 76.0 %

The default variant hardens to ~31 % utilization of a 2×2 tile (sky130A).

Operation is bit-serial and takes about 24 µs per digit at 10 MHz:

  1. Load — the host strobes START, then shifts 64 pixel bits in through ui[0]/ui[1] (pixel 0 = top-left, row-major, LSB first). The bits land in a 64-bit shift register.
  2. Layer 1 — 64 cycles: the input register rotates; each pixel bit add/sub/skips into 16 parallel 8-bit accumulators (the 32-hidden-unit default runs two 16-lane passes). Biases are preloaded so the hidden activation is simply the accumulator sign bit.
  3. Layer 2 — hidden bits are binarized, then fed serially (one per cycle) into 10 class accumulators.
  4. Argmax — a 10-cycle sequential scan finds the best class (ties go to the lower digit). DONE rises; the digit appears on uio[3:0] and on the 7-segment display, with the decimal point lit.

Compute starts automatically after the 64th bit; DONE rises 172 clock cycles later (74 for the linear variant, 91 for the 16-hidden MLP). A new START strobe — or a hardware reset — cleanly abandons any load or result in progress.

How to test

Serial protocol on ui_in (all signals sampled on the rising edge of clk; clk may run continuously, up to 10 MHz):

  • ui[0] DATA — pixel bit
  • ui[1] SHIFT_EN — when high, DATA is shifted in on this clock edge
  • ui[2] START — one-cycle strobe: clear the bit counter, begin a new image
            ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐ ┌─┐   ┌─┐ ┌─┐ ┌─┐ ┌─┐
clk       ──┘ └─┘ └─┘ └─┘ └─┘ └─┘ └───┘ └─┘ └─┘ └─┘ └──
            ┌───┐
START     ──┘   └───────────────────────────────────────
                    ┌───────────┐     ┌───┐        (64 bits total)
SHIFT_EN  ──────────┘           └─────┘   └─────────────
                    ╔═══╗╔══════╗     ╔═══╗
DATA      ──────────╣p0 ╠╣ p1   ╠─────╣p2 ╠─────────────
                    ╚═══╝╚══════╝     ╚═══╝
                     bit0  bit1        bit2  ... gaps are fine:
                                             DATA only sampled when SHIFT_EN=1

After the 64th bit the chip computes on its own; poll DONE (uio[4] or uo[7]). DONE stays high, and the digit stays valid, until the next START.

              ... last bit          compute (~172 cycles)
SHIFT_EN  ────────┐┌──┐
                  └┘  └─────────────────────────────────
DONE      ──────────────────────────────┌───────────────
                                        └→ read uio[3:0]

Outputs:

  • uio[3:0] — predicted digit, binary 0–9 (uio pins are always outputs)
  • uio[4] — DONE, uio[5] — BUSY (high while computing)
  • uo[6:0] — 7-segment a–g (matches the TT demo board display), uo[7] — DONE / decimal point. The display is blank after reset until the first result.

Image preprocessing (host side): average-pool the 28×28 grayscale image to 8×8 (bin r spans rows ⌊r·28/8⌋ to ⌈(r+1)·28/8⌉−1, same for columns), then set each pixel to 1 if its mean is greater than 0.15 (pixel range 0–1). Send row-major, top-left pixel first. See demo/rp2040_demo.py in the project repo for a ready-made MicroPython demo, and test/test.py for the cocotb testbench that verified 200 MNIST images bit-exact against the training pipeline.

To reproduce training / regenerate weights: train/train.py (PyTorch QAT) then train/gen_weights.py (emits src/weights.v).

External hardware

None required — the on-board 7-segment display shows the digit. Drive the inputs from the TT demo board's RP2040 (see demo/rp2040_demo.py) or any microcontroller.

IO

#InputOutputBidirectional
0DATA (serial pixel bit)SEG_ADIGIT[0] (output)
1SHIFT_EN (sample DATA on rising clk)SEG_BDIGIT[1] (output)
2START (begin new image)SEG_CDIGIT[2] (output)
3SEG_DDIGIT[3] (output)
4SEG_EDONE (output)
5SEG_FBUSY (output)
6SEG_G
7DONE (7-seg decimal point)

Chip location

Controller Mux Mux Mux Mux Mux Mux Mux Mux Mux Mux Analog Mux Mux Mux Mux Mux Mux Mux Mux Mux Mux Analog Mux Mux Mux Mux Mux Mux Mux Mux Mux Mux tt_um_chip_rom (Chip ROM) tt_um_factory_test (Tiny Tapeout Factory Test) tt_um_teuscher_eml_fabric (EML Fabric — analog exp/ln compute cells) tt_um_wokwi_465656663515438081 (Convert binary to hex on 7 segments) tt_um_nikita_face_detect (FPGA Face Detection) tt_um_obstacle_avoider (Obstacle Avoider State Machine) tt_um_poket_animal (Poket Animal) tt_um_drewbabel_uart (Configurable FIFO-buffered UART with APB CSR) tt_um_wokwi_469163916296039425 (TT Workshop Test) tt_um_jonahsaunders_slsvga (tt_um_jonahsaunders_slsvga) tt_um_fatigue_monitor (Fatigue Monitor (PPG Pulse-Interval Variability)) tt_um_vedam_dual_port_ram (Dual Port RAM) tt_um_wokwi_469739097665887233 (Tiny Tapeout Template Copy) tt_um_spdif_to_i2s_kilpelaj (S/PDIF to I2S receiver) tt_um_morse_converter (ASCII to Morse Code Converter) tt_um_wokwi_469806914724000769 (Spin, Text and VGA) tt_um_wokwi_469701770572338177 (TinyTapeout) tt_um_garnetkoebel_communotron (Communotron) tt_um_wokwi_469449970323169281 (full adder) tt_um_duzabf_2026_ow (A WIP Online Workshop 2026 project) tt_um_wokwi_469807513638180865 (Tiny Tapeout NAK) tt_um_ttsky26c_oguz (ttsky26c-202607-mehmetoguzderin by Oguz) tt_um_kashif_fp4_sparse_tpu (FP4 Sparse Mini-TPU) tt_um_moein_maleki_arm16 (arm16) tt_um_wokwi_469453454643027969 (ON Check System) tt_um_felixcheng_neural_core (Neural Compute Core (V0.15)) tt_um_wokwi_469788774011248641 (Spin Display - select-reset-reverse) tt_um_wokwi_469449443070765057 (Samuel's first chip) tt_um_wokwi_469449007236383745 (testinttrsv01) tt_um_vga_ca (VGA cellular Automaton) tt_um_dosci_500hz (Digital Oscillator 500 Hz) tt_um_wokwi_469747443569078273 (XOR test project - Tiny Tapeout workshop) tt_um_wokwi_469585758593419265 (spinner) tt_um_fp16_mac (FP32 Math Unit) tt_um_1DC_vga_dyoa (VGA Design Your Own ASIC) tt_um_haydenevans_top (Systolic Processing Element) tt_um_wokwi_469806252715961345 (TT_Proj_SA) tt_um_wokwi_469448996577604609 (Tiny Tapeout - Reto) tt_um_ehofmannbr_pmodvga_06 (VGA Color Tiles) tt_um_lfglabs_lsc1u (leanSilicon LSC-1 Micro arithmetic kernel) tt_um_wokwi_469804280240495617 (Zetterling SRAM) tt_um_wokwi_469806066852696065 (TileTestchase) tt_um_wokwi_469449118072978433 (binary_add_v1) tt_um_voltage_amplifier_neuron (Voltage Amplfier Neuron) tt_um_wokwi_469449686545956865 (Tiny Tapeout Template Copy_JinoShiono) tt_um_wokwi_469448887171240961 (Tiny Tapeout - Mini CORDIC) tt_um_wokwi_469809033878555649 (Tiny Tapeout Yummy Chip - bgianfo) tt_um_sirajmuhammad_bpsk_mod (BPSK Baseband Modulator) tt_um_K_coder_9 (TENs device frequency controller) tt_um_wokwi_469758119198926849 (LL_6BitShiftRegister_ToggleEnabledFeedback) tt_um_Asaadkhex_6x6u (6x6 UART Bussbar Switch) tt_um_wokwi_469809198944364545 (tt8-8bit-cpu Copy) tt_um_wokwi_469710279607305217 (Tiny Tapeout Submission KL - SiliDize) tt_um_wokwi_469629799092815873 (2:1 Mux with differential outputs) tt_um_poundbrad_reciprocal_counter (Two-Channel Reciprocal Counter) tt_um_joonatanalanampa_cordic (CORDIC-1) tt_um_x4ntha_nova (Data General Nova 1200 CPU) tt_um_quick_bus (quick_bus) tt_um_wokwi_470058539448408065 (Nigel's Tiny Tapeout Project) tt_um_wokwi_470058244557293569 (Tiny Tapeout Kabisan) tt_um_wokwi_470058241869790209 (Abdi's desgin) tt_um_wokwi_470060107756808193 (Sukhraj Deol's Chip) tt_um_wokwi_470058578588614657 (The Chip of Master George Stead) tt_um_wokwi_470069286344622081 (Tiny Tapeout ISHA) tt_um_ucl_display (Flashing... lights) tt_um_wokwi_470058746279043073 (Arihant's first Wokwi design) tt_um_wokwi_470060103260512257 (Tiny Tapeout Jabriel Copy) tt_um_wokwi_470069460157662209 (haadi's tiny tapeout) tt_um_wokwi_470058418706939905 (Kitty) tt_um_wokwi_470058490118136833 (Iris) tt_um_wokwi_470060098828179457 (Temz_ tiny tapeout) tt_um_wokwi_470058023187099649 (Osman WOKWI project 1) tt_um_wokwi_470057988621827073 (Viraj Tiny Template Full Adder TEST) tt_um_wokwi_470069802034377729 (Tiny Tapeout Template Copy) tt_um_wokwi_470070136685362177 (full adder) tt_um_wokwi_470070449402211329 (Anastasia Copy (2)) tt_um_wokwi_470059864883484673 (Keyaan’s first Wokwi design) tt_um_wokwi_470071200164912129 (full adder tiny tapeout Copy) tt_um_wokwi_470060671178857473 (SBUSixth First Chip Design Mentored by Tiny Tapeout) tt_um_wokwi_470099562753182721 (Isaac Tiny Tapeout) tt_um_wokwi_470120538476737537 (efwz8voices) tt_um_lelo_gr01_analogicus (LELO-GR01) tt_um_lelo_gr04_analogicus (LELO-GR04) tt_um_lelo_gr02_analogicus (LELO-GR02) tt_um_pump_out (60 Hz RMS Pump-Out Controller) tt_um_urish_simon (Simon Says memory game) tt_um_lelo_gr03_analogicus (LELO-GR03) tt_um_wokwi_470299374901578753 (Shrimp) tt_um_vga_clock (VGA clock) tt_um_frequency_counter (Frequency counter) tt_um_z2a_rgb_mixer (RGB Mixer demo) tt_um_mattvenn_r2r_dac_3v3 (Analog 8 bit 3.3v R2R DAC) tt_um_rebeccargb_universal_decoder (Universal Binary to Segment Decoder) tt_um_rebeccargb_hardware_utf8 (Hardware UTF Encoder/Decoder) tt_um_rebeccargb_intercal_alu (INTERCAL ALU) tt_um_rebeccargb_vga_pride (VGA Pride) tt_um_ogggggish_ota_ldo (SSF Capless LDO) tt_um_hariri4534_audioplayback (audioplayback) tt_um_wokwi_470637150792846337 (Joni - Tiny Tapeout Teardown2026 Workshop) tt_um_wokwi_470635013242210305 (Tom's first Wokwi design) tt_um_wokwi_470635780983408641 (Tiny Tapeout-AyeshaTeardown26) tt_um_wokwi_470639152626282497 (KeKoaM Tiny Tapeout) tt_um_wokwi_470637073520124929 (Tiny Tapeout workshop) tt_um_toby43479_iox (IO Expander with PWM) tt_um_wokwi_470635764113915905 (Divider Demo) tt_um_wokwi_470635580461052929 (Mann-teardown-project) tt_um_wokwi_470639672984256513 (KCs 001 TinyTapeout Design) tt_um_wokwi_470635507665754113 (Tiny Tapeout Template Copy) tt_um_wokwi_470637047364443137 (Pixel-Curio-Chip) tt_um_terihear_tinytearout (TinyTearout) tt_um_wokwi_470643025042834433 (TT 2026) tt_um_wokwi_470637360757626881 (Tiny Tapeout Template Copy) tt_um_wokwi_470635627278929921 (Tiny Tapeout Workshop) tt_um_wokwi_474471160110403585 (Cylon-Scanner) tt_um_wokwi_470646659230201857 (bloopbloop) tt_um_pthomas_sigma_delta (Continuous-Time Sigma-Delta ADC (1st order)) tt_um_sky_tpu_3x3 (Sky TPU 3x3) tt_um_tpcannon7_fir (tinyfir) tt_um_bruniliomuy_top (Fir_Filter) tt_um_semiqa_diff_opamp (Diff-In-Diff-Out-OpAmp) tt_um_TinyProcessor_naiyar_ (TinyProcessor) tt_um_CCDmos3D (ADC for CCDmos3D pixel) tt_um_snn_lif_neuron (snn_lif_neurons) tt_um_galaguna_NanoSys_fit (Nano-120_CPU@ler.uam.mx) tt_um_rowles_regime (Single-Bit Macro Regime Classifier) tt_um_rowles_fedmodel (The Fed Model (F1/F2)) tt_um_sky26c (tt_sky26c) tt_um_aka_regfile_ecc (regfile_ecc) tt_um_fwilson12_mac (int8 MAC) tt_um_davidbroughsmyth_ecg_sar12 (heart_monitor_adc_art) tt_um_foxworks_picorv32 (TCD Foxworks PicoRV32) tt_um_saltworks_ndf_c32 (Neural dataflow fabric — bit-serial MAC cells on a self-routing switch) tt_um_yjeum11 (DTMF (Touch-Tone) decoder) tt_um_vedic_mult (4-bit Vedic Multiplier) tt_um_atx_phased_interferometer (Acoustic Interferometer) tt_um_tilesos_dual_adc (Dual-Path Noise-Shaping ADC) tt_um_darga_cirom (Darga CiROM digital read + ternary MAC) tt_um_azara_cirom (Azara CiROM ternary read) tt_um_spi_reg_bank (8-bit Modified RISC-V) tt_um_aialaqili_updown_counter (4-bit Up/Down Counter) tt_um_noahzperez29_riscv_core (Noah RISC-V Core) tt_um_fp8_fpu (FP8 (E4M3) Floating-Point Unit) tt_um_costinemanuelv_gps_daily_trigger (GPS Daily Trigger) tt_um_ja_achtung_1x1 (JA Achtung Compact) tt_um_ja_achtung_1x2 (JA Achtung Full) tt_um_pwm_spice (spice-pwm-tapeout) tt_um_wecallemjazzyfact_bgr_ldo (BGR + LDO 3.3V/1.8V Integrated IP) tt_um_lelo_temp_wulffern (LELO-TEMP) tt_um_wokwi_472389622799861761 (3-Bit 101 Pattern Detector) tt_um_LnL_SoC (Lab and Lectures SoC) tt_um_dash_lucas_risc (risc_processor) tt_um_serdes_ephotonics (UCIe-style SERDES with analog TX driver & RX slicer) tt_um_joram200 (Kalman Filter Hardware Accelerator) tt_um_colbywonn_poly_synth (Poly Synth v1.0) tt_um_nobleg30_uart_vga_scroller (UART VGA Text Scroller) tt_um_multi_precision_mult (Multi-Precision Multiplier) tt_um_pratibha_munnangi_qkt_mac (QKT MAC Accelerator) tt_um_akankaan_bf16_fma (BF16 Fused Multiply-Add (FMA)) tt_um_rtfce (RTFCE - Reconfigurable Temporal Fault/Constraint Engine) tt_um_hdc_classifier (HDC Classifier) tt_um_preethi8a_adaptive_lfsr_prng (Self-Seeding Adaptive 16-bit Galois LFSR PRNG) tt_um_dilip951_cpu_systolic_array (Reconfigurable mixed-precision 2x2 systolic MAC array) tt_um_pqc_ntt_bfly (Crypto-Agile NTT Butterfly (ML-KEM / ML-DSA / FN-DSA)) tt_um_mlkem_coefficient_integrity (Fault-Aware Constant-Time FO Backend for ML-KEM) tt_um_vital_ap (VITAL-AP: Adaptive Pixel Register) tt_um_olaf8 (OLAF-8: Bounded-Memory Online Adaptive Fuzzy Inference) tt_um_Median_MAD (Streaming Median-MAD Estimator) tt_um_tnt_mosbius (tnt's variant of SKY130 mini-MOSbius) tt_um_undip_ann_q610 (UNDIP ANN Accelerator (SPI + bring-up self-test)) tt_um_cpu8 (CPU8) tt_um_vaishnavipatil5_configurable_cam (Configurable CAM with Masked Pattern Matching and Priority Resolution) tt_um_gina_env_monitor (Environmental Mapping Processor) tt_um_manasvibhat_bloom_filter (Bloom Filter Membership Tester) tt_um_amazing_sage_snn (LIF Neuron SNN) tt_um_nkanderson_lut_snn (LUT Spiking Network Classifier) tt_um_bigmanraffa_clm (Clementine: 4-lane int8 SIMT GPU) tt_um_adityarprasad_fft (Adaptive-Precision FFT) tt_um_oscillating_bones (Oscillating Bones) tt_um_silicon_edge_ns_sar_adc (NS SAR ADC) tt_um_sishi888_tinymind (TinyMind SoC) tt_um_afra_123_ecc_memory (Runtime-Reconfigurable ECC Memory) tt_um_kenchangh_mnist (MNIST Digit Recognition) tt_um_ece298a_8_bit_cpu_top (8-Bit CPU) tt_um_libormiller_SIMON_V2 (SIMON V2) tt_um_WaiMingLee888_nanov_1tile (NanoV RV32E one-tile RISC-V processor) tt_um_four_bit_nn_accel (4-bit Neural Network Accelerator) tt_um_rsa_simple (RSA Simple Encryptor) tt_um_synapticrw_lif_neuron (LIF Neuron (SynapticRW Teardown 2026)) tt_um_smunigan_ipv4_filter (IPv4 Header Filter) tt_um_jjy_spi_watchdog (SPI-Configurable Watchdog Timer) tt_um_osian_beam_controller (Programmable Metasurface Beam Controller) tt_um_namramazhar_popcnt_shiftreg (17-bit Wallace-tree POPCNT with shift-register input) tt_um_obookstay_puf (An arbiter PUF) tt_um_arminkardovic_montenegro_securekey (Montenegro SecureKey) tt_um_rcyaon_droop (All-Digital Supply Droop Detector) tt_um_ctw_spms (CTW-SPMS — Programmable Smart Power Management & Supervisor) tt_um_taiwoopesade_tempo_detector_sky26c (Hardware Audio Tempo Detector) tt_um_wokwi_470059878406973441 (Ehan's first TinyTapeout Project) tt_um_wokwi_470637170309995521 (My First Wokwi Thing!) tt_um_wokwi_470637401137246209 (Teardown Tiny Tapeout) tt_um_wokwi_469443433165025281 (Tiny Tapeout First Design Beth Plummer) tt_um_wokwi_472423526521678849 (4-bit to 5x7 Matrix Decoder for Tiny Tapeout) tt_um_wokwi_470057961258181633 (Tiny Tapeout Template Kavana) tt_um_wokwi_470057993933917185 (ivane- Tiny Tapeout (full adder)) tt_um_wokwi_470088776251343873 (training_project_kaylem) tt_um_neuropong (NeuroPong) tt_um_tamagotchi (TamaGotThis) tt_um_group02_seethebeat (SeeTheBeat) tt_um_kul_chromechain (Chrome Chain) tt_um_baked_weights (Baked-Weights Shakespeare GPT) tt_um_gilangfajrul_sar_adc (sar-adc) tt_um_Logy_FMAC (FMAC) tt_um_porkfreezer_rrio_opamp (RRIO Op-amp) tt_um_diff_engine (DSLX finite_difference) tt_um_dragonochi (WISH) tt_um_siliconsonics (ultrasonic sonar: range and bearing) tt_um_kul_conway (Interactive Conway's Game of Life) tt_um_algofoogle_ttsky26c_analog (Assorted analog in 1 tile) tt_um_mariavictoriaalm_qubit_sim ( tt-2qubit-sim) tt_um_andre_dpe (Dot product engine) tt_um_rmranjitkarNULL_pong_top (last_minute_Pong) tt_um_SAR_ADC (CTW LDO and Dynamic Comparator) tt_um_fabulous_sky_26c (Tiny FABulous FPGA) tt_um_tomvdsch_tiny32_soc (Tiny32 RV32IMA Zephyr-target SoC) tt_um_np523_pong (Pong) tt_um_usfq_adc_procmon (USFQ 8-bit Tracking ADC and Process Variation Monitor) tt_um_rangfuu_alu (Tiny ALU PD) tt_um_wokwi_473800139156677633 (Tiny Snake with PRISM 8) tt_um_mini_nn (Four-MAC Core Neural Network Inference Engine) tt_um_kianv_rv32_regfile (KianV uLinux RISC-V regfile edition) tt_um_2048_vga_game (2048 sliding tile puzzle game (VGA)) tt_um_urish_rings (VGA Rings) tt_um_silicon_art_vga_screensaver (VGA Screensaver with Silicon Art ROM) tt_um_rom_vga_screensaver (VGA Screensaver with embedded bitmap ROM) tt_um_krisjdev_manchester_baby (Manchester Baby) tt_um_urish_sic1 (SIC-1 8-bit SUBLEQ Single Instruction Computer) tt_um_ThomasCowieEngineering_LMC (Little Man Computer CPU) tt_um_pranavUl_ascon_aead128 (Ascon bit-serial permutation engine) tt_um_orca (ORCA — Online Reconfigurable Circuit with Adaptation) tt_um_krisjdev_artwork (Silicon Artwork) tt_um_htfab_caterpillar (Simon's Caterpillar) tt_um_htfab_vga_tester (Video mode tester) Available Available Available Available Available Available Available Available Available Available