
The one-bit PLC is a programmable logic controller for four digital inputs and four outputs. Its accumulator (ACC) holds one Boolean result, such as whether two inputs are both high. A program has up to 16 instructions and runs repeatedly at a target clock of 1 MHz.
At the start of each scan, the PLC samples its synchronized inputs, clears ACC
and copies the four current outputs into working bits. It executes one
instruction per clock from address 0. Later instructions can read earlier
writes to working outputs or to the four internal marker bits. After END or
slot 15, the next clock copies all four working bits to the output pins
together and pulses SCAN. A scan that executes N instructions takes N + 2
clocks, counting END if present.
| Pins | Use |
|---|---|
ui_in[3:0] |
Program address while loading, process inputs I3 through I0 while running |
ui_in[4] |
PROG_WRITE. A rising edge writes one byte in programming mode |
ui_in[5] |
PROG_MODE. High to load a program |
ui_in[6] |
RUN. High to scan, low to stop |
ui_in[7] |
Reserved. Hold low |
uio_in[7:0] |
Instruction byte. These pins are always inputs to the PLC |
uo_out[3:0] |
Committed outputs Q3 through Q0 |
uo_out[4] |
ACC, the live accumulator |
uo_out[5] |
SCAN, high for one clock when outputs update |
uo_out[6] |
READY, high once all 16 distinct addresses have been written |
uo_out[7] |
FAULT, high after an invalid instruction or operand |
Use a 16-byte hex file such as examples/boolean_demo.hex.
Line 1 goes to address 0 and line 16 to address 15. Keep the clock running
throughout. Each wait below is at least four rising clock edges (4 µs at
1 MHz).
ena high). Set RUN, PROG_MODE and PROG_WRITE low.
Hold rst_n low for four clocks, then high for four clocks.Lowering RUN aborts the scan and clears the outputs. Completed marker writes,
the program and FAULT survive a pause while the tile stays powered. Driving
ena low on a clocked, powered tile has the same effect. Reset or entry into
programming clears outputs, markers, READY and FAULT. After power-up, reset
and reload all 16 bytes.
Each byte holds the opcode in bits 7–4 and the operand in bits 3–0.
| Opcode (hex) | Assembly | Effect |
|---|---|---|
| 0 | NOP |
Leave state unchanged |
| 1 | LD s |
Load s into ACC |
| 2, 3, 4 | AND s, OR s, XOR s |
Combine ACC with s and keep the result in ACC |
| 5 | NOT |
Invert ACC |
| 6, 7 | ST d, STN d |
Write ACC or its inverse to d, respectively |
| 8 | END |
Finish this scan |
| 9–F | Reserved | Set FAULT and continue |
Source operands (hex) are 0–3 for I0–I3, 4–7 for Q0–Q3, 8–B for
M0–M3, and C/D for constants 0/1. Only Q and M are writable. Reading E
or F returns zero and sets FAULT. An invalid store sets FAULT and leaves the
destination unchanged. NOP, NOT and END ignore the operand bits.
Execution and output updates continue after a fault.
Load examples/boolean_demo.hex as above. Its four outputs are I0 AND I1
(Q0), I0 OR I1 (Q1), I0 XOR I1 (Q2) and NOT I0 (Q3). With both inputs low,
only Q3 is high. Raise I0 alone and Q1 and Q2 go high while Q3 goes low.
At 1 MHz, hold each input setting for 30 µs before reading the pins. This
allows time for input synchronization and a full scan. SCAN pulses every
14 clocks with this program.
To run the examples in simulation, install Python 3 and Icarus Verilog and
run make -C test from the repository root. To assemble your own program,
run python3 tools/assemble.py program.plc -o program.hex. The assembler
pads unused slots with NOP.
A Tiny Tapeout demo board or compatible host supplies logic-level pins, clock and reset. Use LEDs to read steady outputs or a logic analyzer to see SCAN. The PLC reads a snapshot once per scan and can miss short input pulses. Use a suitable driver or level shifter for external loads.
| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | I0 / program address bit 0 | Q0 | Program instruction bit 0 (input only) |
| 1 | I1 / program address bit 1 | Q1 | Program instruction bit 1 (input only) |
| 2 | I2 / program address bit 2 | Q2 | Program instruction bit 2 (input only) |
| 3 | I3 / program address bit 3 | Q3 | Program instruction bit 3 (input only) |
| 4 | PROG_WRITE (rising-edge strobe) | Accumulator | Program instruction bit 4 (input only) |
| 5 | PROG_MODE | SCAN (one clock pulse at commit) | Program instruction bit 5 (input only) |
| 6 | RUN | READY (all 16 addresses loaded) | Program instruction bit 6 (input only) |
| 7 | Reserved; hold low | FAULT (sticky) | Program instruction bit 7 (input only) |