Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6980

SDK • Issue with alarms

$
0
0
I have the following code (minimum reproducible example of a more complicated project):

Code:

#include "pico/stdlib.h"#include "hardware/gpio.h"#define INDICATOR_GPIO_PIN 5#define N_PULSES_TO_OUTPUT 2void set_indicator_pin(bool status) {gpio_put(INDICATOR_GPIO_PIN, status);}void alarm_callback(alarm_id_t id, void *user_data) {set_indicator_pin(true);set_indicator_pin(false);}int main() {stdio_init_all();gpio_init(INDICATOR_GPIO_PIN);    gpio_set_dir(INDICATOR_GPIO_PIN, GPIO_OUT);for (size_t _=0; _<N_PULSES_TO_OUTPUT; _++) {add_alarm_in_us(5, alarm_callback, NULL, false);sleep_ms(1);}while (true);}
loaded in my Raspberry Pi Pico W. I have an oscilloscope connected to GPIO 5. I would expect 2 pulses to come out, separated by about 1 ms, but instead I get an infinite number of pulses, one every second, approximately. If I set `N_PULSES_TO_OUTPUT` to 1, then 0 pulses are outputted. What is wrong?

Statistics: Posted by binary_pie — Thu Sep 19, 2024 2:06 pm — Replies 1 — Views 53



Viewing all articles
Browse latest Browse all 6980

Trending Articles