A fully combinational, runtime-programmable 16×16 binary multilayer perceptron in VHDL, targeting the Intel Cyclone 10 LP on the Arduino MKR Vidor 4000.
No multipliers, no floating point, no clock inside the network: every perceptron is a mask, a popcount and a comparator. Inputs flow through all 16 layers asynchronously, and the weights (a 16-bit sensitivity mask plus a 4-bit activation threshold per perceptron) are written over a small address/data/load bus while the design is running.
Built as the semester project for Digitaldesign at Ernst-Abbe-Hochschule Jena (2021). Verified module-by-module, in integration and as a full system with ModelSim testbenches; the German project report is in Documentation/perceptron.pdf.
- The idea
- System architecture
- The perceptron
- Programming interface
- Repository layout
- Running the simulations
- Verification
- Status and known limitations
- Author
- License
A textbook perceptron computes ŷ = g(w₀ + Σ xᵢ·wᵢ) — a weighted sum followed by an activation function. On an FPGA that is expensive: one multiplier per synapse, an adder tree, and a fixed-point activation function per neuron. A 256-neuron network would not fit on a small device.
This project trades precision for area by making everything binary:
| Textbook MLP | This design |
|---|---|
Real-valued inputs xᵢ |
1-bit inputs (an input is active or not) |
Real-valued weights wᵢ |
1-bit sensitivity per input (listen to it or ignore it) |
Weighted sum Σ xᵢ·wᵢ |
Popcount of input AND sensitivity |
Activation g(·) with bias w₀ |
popcount ≥ activation_value (4-bit threshold) |
| Clocked pipeline | Pure combinational logic — outputs settle as soon as inputs change |
The result is a network of 256 perceptrons (16 layers × 16 neurons) plus a 1024-word input memory that fits the Cyclone 10 LP, with every parameter of every neuron addressable from outside.
The Arduino MKR Vidor 4000 pairs a SAM D21 microcontroller with the Cyclone 10 FPGA. The microcontroller is the bridge between a host PC (RS232/USB) and the FPGA fabric, driving five signals into the design: mode, address, data, load and clk.
flowchart LR
PC[Host PC<br/>frontend] -- RS232 --> MCU[SAM D21<br/>microcontroller]
subgraph FPGA["Cyclone 10 LP · top_level_entity"]
direction LR
TLR[top_level_resolver<br/><i>combinational switch</i>]
STO[(storage<br/>1024 × 16 bit)]
subgraph NET["Perceptron network"]
direction TB
LR0[layer_resolver 0] --> L0[Layer 0<br/>16 × perceptron]
LR1[layer_resolver 1] --> L1[Layer 1<br/>16 × perceptron]
LRn["layer_resolver …"] --> Ln["…"]
LR15[layer_resolver 15] --> L15[Layer 15<br/>16 × perceptron]
L0 -- 16-bit axon bus --> L1
L1 -- 16-bit axon bus --> Ln
Ln -- 16-bit axon bus --> L15
end
TLR -- "mode = 1<br/>addr[9:0], data[15:0], load" --> STO
TLR -- "mode = 0<br/>addr[10:0], data[3:0], load" --> LR0 & LR1 & LRn & LR15
STO -- "16-bit word per clk" --> L0
end
MCU -- "mode, address[10:0],<br/>data[15:0], load, clk" --> TLR
L15 -- "result[15:0]" --> MCU
Two data paths share one bus, selected by mode:
mode = 1— fill the input memory.storageholds 1024 16-bit stimulus words. Each rising edge ofclkpresents the next word to layer 0, so a full sweep over the memory replays 1024 input patterns through the network.mode = 0— program the network. The 11-bit address selects a layer, a perceptron inside that layer and one of its five parameter registers; the low 4 bits ofdataare written onload. Eachlayer_resolvercompares the top four address bits against its own layer number and forwards the request only if it matches, which keeps the fan-out to 256 perceptrons manageable.
Both resolvers are purely combinational — they contain no registers and need no clock. Only storage is clocked, and only for the sequential read-out.
Each of the 256 perceptron instances holds two parameters and evaluates them against its 16-bit input (dentrid_port) from the previous layer:
flowchart LR
IN["dentrid_port[15:0]<br/>from previous layer"] --> AND
SENS["sensitivity_value[15:0]<br/><i>which inputs to listen to</i>"] --> AND
AND["bitwise AND"] --> POP["popcount<br/>(count of active,<br/>listened-to inputs)"]
POP --> CMP{"count ≥<br/>activation_value ?"}
ACT["activation_value[3:0]<br/><i>firing threshold</i>"] --> CMP
CMP -- yes --> ONE["axon_port = 1"]
CMP -- no --> ZERO["axon_port = 0"]
The 16-bit sensitivity mask is written as four 4-bit nibbles (sens_1 … sens_4) because the layer data bus is only 4 bits wide; the perceptron reassembles them. On reset the threshold is 15 and the mask is 0, so an unprogrammed network is silent.
The output is only re-evaluated when the input vector actually changes (dentrid_port /= old_value), which suppresses redundant toggling while parameters are being loaded.
bit 10 9 8 7 | 6 5 4 3 | 2 1 0
┌───────────┬────────────┬─────────┐
│ layer │ perceptron │ param │
│ 0…15 │ 0…15 │ 0…4 │
└───────────┴────────────┴─────────┘
param |
Register written with data[3:0] |
|---|---|
0 |
activation_value — firing threshold (0…15) |
1 |
sens_1 — sensitivity mask bits 3…0 |
2 |
sens_2 — sensitivity mask bits 7…4 |
3 |
sens_3 — sensitivity mask bits 11…8 |
4 |
sens_4 — sensitivity mask bits 15…12 |
That gives 16 × 16 × 5 = 1280 programmable 4-bit registers. Example: to make perceptron 3 in layer 2 listen to inputs 0, 1 and 8 and fire when at least two of them are high, write
address (layer·perceptron·param) |
data | effect |
|---|---|---|
0010 0011 000 |
0010 |
threshold = 2 |
0010 0011 001 |
0011 |
mask[3:0] = 0011 |
0010 0011 011 |
0001 |
mask[11:8] = 0001 |
address[9:0] selects one of 1024 words; the full data[15:0] is stored on the rising edge of load. Each rising edge of clk then emits the next word to layer 0, wrapping around at the end.
| Port | Dir | Width | Purpose |
|---|---|---|---|
clk |
in | 1 | advances the storage read pointer |
reset |
in | 1 | async reset of every module |
mode |
in | 1 | 0 = program perceptrons, 1 = write storage |
address |
in | 11 | see address maps above |
data |
in | 16 | value to write (low 4 bits used on the layer branch) |
load |
in | 1 | commits the write |
result |
out | 16 | axon outputs of the last layer |
Code/
VHDL/Modules/ synthesizable design
perceptron.vhdl binary neuron: mask, popcount, threshold
layer_resolver.vhdl per-layer address decoder (generic: layer_count)
top_level_resolver.vhdl mode switch between storage and layer branch
storage.vhdl 1024 × 16-bit stimulus memory with sequential read-out
top_level_entity.vhdl generates 16 resolvers + 256 perceptrons and wires them up
tlr_storage.vhdl integration wrapper (resolver + storage) used by its testbench
VHDL/Testbench/ one *_tb.vhdl per module, plus integration and system testbenches
Python/ early tkinter sketch for a pixel-grid frontend (not functional yet)
SimulationConf/ ModelSim .do scripts: compile, load waves, run — one per testbench
Documentation/
perceptron.pdf / .tex full project report (German)
ModuleDescription/ entity/port diagrams per module
SimulationPictures/ waveform screenshots referenced in the report
Resources/ datasheets (SAM D21, ModelSim reference, VHDL cheat sheet)
PerceptronSim.mpf ModelSim project file
Requirements: ModelSim-Intel FPGA Edition (the Starter Edition works but warns that the 18k-statement design exceeds its recommended capacity, so the system test is slow). Testbenches use VHDL-2008 (std.env.stop).
# inside the ModelSim console, from the repository root
do SimulationConf/top_level_entity.doEach script opens PerceptronSim.mpf, compiles everything, loads the matching testbench, populates the wave window with the interesting signals and runs to completion. Available scripts:
| Script | Exercises |
|---|---|
perceptron.do |
a single neuron: parameter write, mask assembly, threshold |
layer_resolver.do |
address match / mismatch, truncation to 7 bits |
top_level_resolver.do |
both mode branches, width casting |
storage.do |
write, sequential read-out, reset clears memory |
tlr_storage_tb.do |
integration: resolver → storage with random data |
top_level_entity.do |
full system: fill memory, sweep, reprogram, sweep again |
Every module has a dedicated testbench; tlr_storage_tb covers the resolver/storage integration and top_level_entity_tb the complete system. The system test writes random words into storage, sweeps them through the network with default parameters, then generates random sensitivity/threshold values, programs them, and sweeps again to observe the changed response.
The screenshot below (from Documentation/SimulationPictures) shows the system test: a new word arrives from storage and the activation ripples through layer_axon_arr(0…5) within the same clock period, with no intermediate clock edges — the network is combinational end to end.
The report walks through each testbench and its waveform in detail.
This is a finished semester project, not a maintained library. It simulates correctly at RTL; things that were out of scope or left open:
- No training. Parameters are written from outside; there is no on-chip or host-side learning algorithm yet. The natural next step is a host-side optimizer (evolutionary or bit-flip search fits the binary parameter space well) that programs the fabric over the existing bus.
- Storage clocking.
storagereacts to rising edges on bothloadandclkin one process. It works in simulation but is not a clean synchronous design; a single clock with a read/write select would be more robust on hardware. - Popcount width. The per-neuron counter is 4 bits, so a neuron with all 16 inputs active and all 16 mask bits set wraps to 0 instead of 16. In practice thresholds are ≤ 15 so this only matters at the extreme corner.
- Gate-level timing simulation was set up in Quartus but not run to completion; hardware bring-up on the Vidor 4000 is pending.
- Frontend.
Code/Python/perceptronInterface.pyis a placeholder sketch for a pixel-grid input GUI and does not run as-is.
Fabian Franz — Ernst-Abbe-Hochschule Jena, 2021.
