Added missing parenthesis around the divisor. Verified using a logic analyzer and also in simulation: https://wokwi.com/arduino/projects/300911723685085709
36 lines
903 B
C
36 lines
903 B
C
/**
|
|
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
|
*
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "pico/stdlib.h"
|
|
#include "hardware/pio.h"
|
|
#include "hardware/clocks.h"
|
|
#include "blink.pio.h"
|
|
|
|
void blink_pin_forever(PIO pio, uint sm, uint offset, uint pin, uint freq);
|
|
|
|
int main() {
|
|
setup_default_uart();
|
|
|
|
// todo get free sm
|
|
PIO pio = pio0;
|
|
uint offset = pio_add_program(pio, &blink_program);
|
|
printf("Loaded program at %d\n", offset);
|
|
|
|
blink_pin_forever(pio, 0, offset, 0, 3);
|
|
blink_pin_forever(pio, 1, offset, 6, 4);
|
|
blink_pin_forever(pio, 2, offset, 11, 1);
|
|
}
|
|
|
|
void blink_pin_forever(PIO pio, uint sm, uint offset, uint pin, uint freq) {
|
|
blink_program_init(pio, sm, offset, pin);
|
|
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);
|
|
}
|