2

Is there a way to set a one time timer interrupt on the Raspberry Pi Pico? I.e. in code, I would be able to tell the hardware timer to interrupt me in a specified period of time. Example pseudocode would look something like this:

do_stuff();
interrupt_me_in(10ms, &isr);  // relatively high precision required (edited - said 1000ms before)
do_more_stuff();

The idea is that the program would receive an interrupt which is serviced by isr 1 second after the line interrupt_me_in(1000ms, &callback) was executed.

Every resource online seems to only deal with regular interrupts (e.g. timer interrupt every 1 second), not one-time interrupts.

I'm not using timer interrupts for anything else, so I wouldn't mind hijacking functionality from the regular timer interrupts to achieve this goal. However, I would rather avoid having a regular timer interrupt going off very frequently with a routine checking whether it should set off my one-time interrupt above.

alex
  • 41
  • 5

2 Answers2

1

For those who see the in the future: I found a solution. The add_repeating_timer_ms and add_repeating_timer_us functions take callbacks which return a boolean value: if that bool is false, they stop the regularly firing timer. So you can set a repeating timer and cancel it after the first interrupt by returning false from the interrupt handler.

alex
  • 41
  • 5
0

If there are only regular timer interrupts you will need to cancel the regular timer after the interrupt.

joan
  • 71,852
  • 5
  • 76
  • 108