.program pio_blink ; Turn on LED for 1002 cycles and off for 1002 cycles. ; Large delays are required to allow the State Machine to toggle at frequencies as low as 1Hz. ; Note: Oscilloscope shows this runs about 2% fast indicating an issue with the cycle count. .wrap_target set pins, 1 ; Turn LED on set x,25 ; 2 cycles to this point label01: nop [19] ; 20 cycles nop [18] ; 19 cycles jmp x--, label01 ; 1 cycles ; ; 2 + 25*(20+19+1) = 1002 cycles to this point ; (restart cycle count) set pins, 0 ; Turn LED off set x,25 ; 2 cycles to this point label02: nop [19] ; 20 cycles nop [18] ; 19 cycles jmp x--, label02 ; 1 cycles ; ; 2 + 25*(20+19+1) = 1002 cycles to this point .wrap ; Blink forever! % c-sdk { // this is a raw helper function for use by the user which sets up the GPIO output, and configures the SM to output on a particular pin void blink_program_init(PIO pio, uint sm, uint offset, uint pin) { pio_gpio_init(pio, pin); pio_sm_set_consecutive_pindirs(pio, sm, pin, 1, true); pio_sm_config c = pio_blink_program_get_default_config(offset); sm_config_set_set_pins(&c, pin, 1); pio_sm_init(pio, sm, offset, &c); } %}