
This project is a three-channel RGB Pulse Width Modulation (PWM) controller designed for TinyTapeout.
The design stores independent brightness values for red, green, and blue LED channels and continuously generates PWM waveforms on the outputs. The PWM duty cycle determines the effective brightness of each color channel.
The 8-bit input bus is divided into:
| Bits | Purpose |
|---|---|
| ui_in[7:6] | Mode selection |
| ui_in[5:0] | Value data |
The mode bits determine which internal register is updated.
| Mode | Function |
|---|---|
| 00 | Set RED brightness |
| 01 | Set GREEN brightness |
| 10 | Set BLUE brightness |
| 11 | Set PWM clock divider |
The PWM engine operates using:
Each output compares the PWM counter against its stored duty-cycle register:
PWM output HIGH when:
counter < duty_cycle
This creates variable duty-cycle square waves suitable for LED brightness control.
ui_in[7:0]
│
▼
┌────────────┐
│ Decoder │
└─────┬──────┘
│
┌─────────────┼─────────────┐
▼ ▼ ▼
RED REG GREEN REG BLUE REG
│ │ │
└─────────────┼─────────────┘
▼
PWM Comparators
│
▼
RGB Outputs
A programmable clock divider slows the incoming TinyTapeout clock to generate a visible PWM frequency.
A 6-bit counter continuously ramps:
0 → 1 → 2 → ... → 63 → repeat
The RGB outputs turn on whenever the counter value is below the stored duty-cycle value.
Example:
Duty = 32
counter < 32 → HIGH
counter ≥ 32 → LOW
This creates a 50% duty cycle.
The design is tested using cocotb and Icarus Verilog simulation.
The user controls the design through the ui_in[7:0] bus.
mode = 00
value = 63
ui_in = 00111111
mode = 01
value = 32
ui_in = 01100000
mode = 10
value = 8
ui_in = 10001000
mode = 11
value = 4
ui_in = 11000100
Simulation is performed using:
cd test
make
Waveforms can then be viewed using GTKWave or Surfer.
The testbench verifies:
The outputs are intended to drive:
For direct LED use:
Typical usage:
uo_out[0] → Red LED
uo_out[1] → Green LED
uo_out[2] → Blue LED
The design may also interface with:
| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | value bit 0 | PWM Red | |
| 1 | value bit 1 | PWM Green | |
| 2 | value bit 2 | PWM Blue | |
| 3 | value bit 3 | ||
| 4 | value bit 4 | ||
| 5 | value bit 5 | ||
| 6 | mode bit 0 | ||
| 7 | mode bit 1 |