

This is a Wokwi design that fits in a sky130 'micro' tile and implements a single-channel, dual output PWM. It uses four 6-bit registers to set the two PWM output characteristics and a 6-bit counter. The registers are:
| 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 eight inputs ... DISABLE, DATA, STROBE, COUNT_EN, PWM0_INV, PWM1_INV, TRIGGER and ONESHOT. The DISABLE input holds the counter at zero and both outputs LOW 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.
The 6-bit counter is also available on uo_out[7:2] (counter bit 0 on uo_out[2]) when COUNT_EN (ui_in[3]) is HIGH. With COUNT_EN LOW those six outputs are LOW.
The two upper outputs can carry the inverted PWM signals instead. PWM0_INV (ui_in[4]) HIGH puts the inverse of PWM0 on uo_out[6] in place of counter bit 4, and PWM1_INV (ui_in[5]) HIGH puts the inverse of PWM1 on uo_out[7] in place of counter bit 5, with COUNT_EN HIGH or LOW. So there can be an inverted PWM1 output plus a 5-bit count, or both inverted outputs plus a 4-bit count, and an external circuit can still know the phase of the period if FREQUENCY is limited to 5 or 4 bits (31 or 15) in that mode.
| Output | PWMn_INV HIGH | PWMn_INV LOW, COUNT_EN HIGH | both LOW |
|---|---|---|---|
| uo_out[5:2] | (not affected) | count[3:0] | LOW |
| uo_out[6] | NOT PWM0 | count[4] | LOW |
| uo_out[7] | NOT PWM1 | count[5] | LOW |
With ONESHOT (ui_in[7]) HIGH the counter does not restart at the FREQUENCY count: it halts there, and PWM1 is held LOW while it is halted. A rising edge on TRIGGER (ui_in[6], sampled by the clock) clears the counter AND sets PWM0 HIGH, two clocks after the edge. The counter then runs once more to FREQUENCY: PWM0 goes LOW at PWM0_LOW_CNT, PWM1 goes HIGH and LOW at its two counts, and the counter halts again. Each trigger therefore gives one pulse on each output. A trigger while the counter is running restarts the sequence from zero.
After a reset or DISABLE in one-shot mode the counter runs once to FREQUENCY without a trigger; PWM1 makes its pulse in that run and PWM0 does not.
TRIGGER also works with ONESHOT LOW: it restarts the period, which can synchronize the PWM to an external signal.
Issuing a reset will pre-load "sane" values into the control registers and zero the counter so a quick demo / test is possible.
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.
Set COUNT_EN (ui_in[3]) HIGH to see the counter on the other six segments: it counts from 0 to FREQUENCY and starts again.
Set PWM0_INV (ui_in[4]) or PWM1_INV (ui_in[5]) HIGH to see segment G or the decimal point blink opposite to segment A or B.
Set ONESHOT (ui_in[7]) HIGH and the blinking stops. Each rising edge on TRIGGER (ui_in[6]) then gives one blink of each of the two segments.
7-Segment display and ui_in switches on the demo board. A WebSerial app will be created once the chip is available.
| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | DATA | pwm_0 | |
| 1 | STROBE | pwm_1 | |
| 2 | DISABLE | count[0] (when COUNT_EN is high) | |
| 3 | COUNT_EN | count[1] (when COUNT_EN is high) | |
| 4 | PWM0_INV | count[2] (when COUNT_EN is high) | |
| 5 | PWM1_INV | count[3] (when COUNT_EN is high) | |
| 6 | TRIGGER | inverted pwm_0 (when PWM0_INV is high), else count[4] (when COUNT_EN is high) | |
| 7 | ONESHOT | inverted pwm_1 (when PWM1_INV is high), else count[5] (when COUNT_EN is high) |