Skip to content

Commit 72e41ad

Browse files
Fix PIO count (#211)
Works fine currently for low frequency, breaks down at higher frequency e.g. 1MHz Chased down with a scope to the 3 extra cycles needed for wait+1; mov; jmp so account for these in demo program
1 parent 4d1d533 commit 72e41ad

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pio/pio_blink/blink.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ void blink_pin_forever(PIO pio, uint sm, uint offset, uint pin, uint freq) {
3131
pio_sm_set_enabled(pio, sm, true);
3232

3333
printf("Blinking pin %d at %d Hz\n", pin, freq);
34-
pio->txf[sm] = clock_get_hz(clk_sys) / (2 * freq);
34+
35+
// PIO counter program takes 3 more cycles in total than we pass as
36+
// input (wait for n + 1; mov; jmp)
37+
pio->txf[sm] = (clock_get_hz(clk_sys) / (2 * freq)) - 3;
3538
}

0 commit comments

Comments
 (0)