Datasheet

Table Of Contents
16 pio_sm_put_blocking(pio, sm, period);
17 pio_sm_exec(pio, sm, pio_encode_pull(false, false));
18 pio_sm_exec(pio, sm, pio_encode_out(pio_isr, 32));
19 pio_sm_set_enabled(pio, sm, true);
20 }
Once this is done, the state machine can be enabled, and PWM values written directly to its TX FIFO.
Pico Examples: https://github.com/raspberrypi/pico-examples/tree/master/pio/pwm/pwm.c Lines 23 - 25
23 void pio_pwm_set_level(PIO pio, uint sm, uint32_t level) {
24 pio_sm_put_blocking(pio, sm, level);
25 }
Pico Examples: https://github.com/raspberrypi/pico-examples/tree/master/pio/pwm/pwm.c Lines 27 - 51
27 int main() {
28 stdio_init_all();
29 #ifndef PICO_DEFAULT_LED_PIN
30 #warning pio/pwm example requires a board with a regular LED
31 puts("Default LED pin was not defined");
32 #else
33
34 // todo get free sm
35 PIO pio = pio0;
36 int sm = 0;
37 uint offset = pio_add_program(pio, &pwm_program);
38 printf("Loaded program at %d\n", offset);
39
40 pwm_program_init(pio, sm, offset, PICO_DEFAULT_LED_PIN);
41 pio_pwm_set_period(pio, sm, (1u << 16) - 1);
42
43 int level = 0;
44 while (true) {
45 printf("Level = %d\n", level);
46 pio_pwm_set_level(pio, sm, level * level);
47 level = (level + 1) % 256;
48 sleep_ms(10);
49 }
50 #endif
51 }
If the TX FIFO is kept topped up with fresh pulse width values, this program will consume a new pulse width for each
pulse. Once the FIFO runs dry, the program will again start reusing the most recently supplied value.
3.6.9. Addition
Although not designed for computation, PIO is quite likely Turing-complete, provided a long enough piece of tape can be
found. It is conjectured that it could run DOOM, given a sufficiently high clock speed.
Pico Examples: https://github.com/raspberrypi/pico-examples/tree/master/pio/addition/addition.pio Lines 1 - 19
Ê1 .program addition
Ê2
Ê3 ; Pop two 32 bit integers from the TX FIFO, add them together, and push the
Ê4 ; result to the TX FIFO. Autopush/pull should be disabled as we're using
Ê5 ; explicit push and pull instructions.
RP2040 Datasheet
3.6. Examples 385