Datasheet

Table Of Contents
Ê1 .side_set 1 opt ; 1-bit wide side set, with an enable bit.
Ê2
Ê3 .wrap_target
Ê4 out x, 8 ; pin will go high when we count down through this value
Ê5 mov y, isr side 0 ; preload counter to max value, and set pin low (simultaneous)
Ê6 pwm_loop:
Ê7 jmp x!=y skip
Ê8 nop side 1 ; nop with side-set (could also use set, if mapping configured)
Ê9 skip:
10 jmp y-- pwm_loop [14]
11 .wrap
For an autopull threshold of 8, this program will consume one FIFO word per sample; a threshold of 32 will consume one
FIFO word per 4 samples.
'nop' (no operation) is a pseudo-instruction which is assembled as 'mov x, x'.
The above program will stop running the PWM counter when the TX FIFO runs empty. For many applications this would
not be the desired behaviour; we would rather recycle the most recently written value indefinitely. This can be done using
a nonblocking 'pull', which executes as 'mov osr, x' when the TX FIFO is empty:
Ê1 .side_set 1 opt
Ê2
Ê3 .wrap_target
Ê4 pull noblock
Ê5 out x, 8
Ê6 mov y, isr side 0
Ê7 pwm_loop:
Ê8 jmp x!=y skip
Ê9 nop side 1
10 skip:
11 jmp y-- inner_loop [14]
12 .wrap
A third type of PWM is one where the FIFO data is formatted as (high duration, low duration). This is ideal for e.g. a servo
controller:
Ê1 .side_set 1 opt
Ê2
Ê3 .wrap_target
Ê4 out x, 16 side 1
Ê5 loop1:
Ê6 jmp x-- loop1
Ê7 out x, 16 side 0
Ê8 loop0:
Ê9 jmp x-- loop0
10 .wrap_target
Finally, an interesting PWM with a compressed dithering format, which can be used in conjunction with noise shaping on
the processor for relatively high-fidelity audio. It will repeat the same sample a variable number of times, each time adding
either 0 or 1 to the duty value.
Ê1 .side_set 1 opt
Ê2
Ê3 ; FIFO Format:
RP2040 Datasheet
3.7. Outdated Examples 363