# Micro PWM
A single-channel PWM with two outputs, drawn in Wokwi and
small enough for a Tiny Tapeout sky130 micro tile (a quarter
of a 1x1 tile, with only clk, rst_n, ui_in and uo_out).
## How it works
A 6-bit counter runs on the clock, and four 6-bit registers are compared with it to shape the two outputs
DATA +-------------------+
----------------------------->|D Frequency | .-.
+----------+ | Shift {pr} +------>| = +-+
STROBE | {pw} +----*---->|en Register Q | '-' | +------------+
------->| ^Edge^ | | +-----------------+-+ ^ *--->|HI {pb} | uo[0]
| ^Detect^ | | +--------------------+ +------+ | | PWM 0 +----->
+----------+ | | +-------------------+ | | +->|LO |
DISABLE | +->|D PWM0 LO | | .-. | | +------------+
-------------+ | | Shift {pr} +--|--->| = +-|-+
v *---->|en Register Q | | '-' |
+-------------+ | +-----------------+-+ | ^ |
| clr|<--|-----------------------|----|------|---+
| 6-Bit | | +--------------------+ | |
| Counter +---|--|-------------------------*------+
| {pt} | | | +-------------------+ |
+-------------+ | +->|D PWM1 HIGH | | .-.
| | Shift {pr} +--|--->| = +---+
*---->|en Register Q | | '-' | +------------+
| +-----------------+-+ | ^ +->|HI {pb} | uo[1]
| +--------------------+ *------+ | PWM 1 +----->
| | +-------------------+ | +->|LO |
| +->|D PWM1 LO | | .-. | +------------+
| | Shift {pr} +--|--->| = +---+
+---->|en Register | | '-'
+-------------------+ | ^
+------+
| Register | Function |
| ------------ | ----------------------------------------------- |
| FREQUENCY | Counter reset compare and PWM0 HIGH |
| PWM0_LOW_CNT | Count where PWM0 out goes LOW |
| PWM1_HI_CNT | Count where PWM1 out goes HIGH |
| PWM1_LOW_CNT | Count where PWM1 out goes LOW |
There are three inputs ... DISABLE, DATA and STROBE. The DISABLE input stops
the counter so new PWM data can be loaded. The DATA and STROBE inputs are used to shift in
new control register data. The next bit of data is presented on DATA and is sampled at the
rising edge of STROBE. Data is shifted MSB first and is shifted in the order: PWM1_LOW_COUNT,
PWM1_HIGH_COUNT, PWM0_LOW_COUNT, FREQUENCY. The FREQUENCY match also sets PWM0 HIGH.
Issuing a reset will pre-load "sane" values into
the control registers and zero the counter so a quick demo / test is possible.
## How to test
Supply a 50 Hz clock and issue a reset. The default reset values will pre-load
frequency and duty cycle values to make two of the 7-segment LEDs blink with different
on/off times.
Disable the PWM, Strobe in different control register values and re-enable to see different 2-output patterns.
## External hardware
7-Segment display and ui_in switches on the demo board. A WebSerial app will be created once the chip is available.
Loading
tt-block-input
tt-block-input
Loading
tt-block-output
tt-block-output
The Counter
Frequency
Duty 0
PWM 0
PWM 1
PWM 1 High
PWM 1 Low
Frequency Compare
PWM0 Low Compare
PWM1 High Compare
PWM1 Low Compare
LOAD Edge Detect