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
This commit is contained in:
Graeme Winter 2022-05-16 21:17:42 +01:00 committed by GitHub
parent 4d1d533122
commit 72e41ad66f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,5 +31,8 @@ void blink_pin_forever(PIO pio, uint sm, uint offset, uint pin, uint freq) {
pio_sm_set_enabled(pio, sm, true);
printf("Blinking pin %d at %d Hz\n", pin, freq);
pio->txf[sm] = clock_get_hz(clk_sys) / (2 * freq);
// PIO counter program takes 3 more cycles in total than we pass as
// input (wait for n + 1; mov; jmp)
pio->txf[sm] = (clock_get_hz(clk_sys) / (2 * freq)) - 3;
}