Hi,
I downloaded the timer interrupt examples and thought it all looked straight forward. The problem came when I changed the device to a Raspberry Pi, the only option is "Custom" and no idea what to do now. The help gave some examples for Custom interrupts and there was an ARM option which I believe the Pi is but the only help is for AT91.
Does anyone have any idea how to create a 1 second timer interrupt for the Pi?
Regards,
Bob
Raspberry Pi interupt on timer
-
- Posts: 283
- http://meble-kuchenne.info.pl
- Joined: Sat Mar 19, 2022 4:53 pm
- Has thanked: 25 times
- Been thanked: 32 times
-
- Valued Contributor
- Posts: 447
- Joined: Mon Dec 07, 2020 1:00 pm
- Has thanked: 81 times
- Been thanked: 243 times
Re: Raspberry Pi interupt on timer
Hi Bob,
Attached is an example of one way to add a timer interrupt.
This example uses a little C code to flash a LED (500ms on/off)
I've not yet tried customise option, but Ben might be able to integrate this into Timer component.
Hopefully it's a start
Leigh
Attached is an example of one way to add a timer interrupt.
This example uses a little C code to flash a LED (500ms on/off)
I've not yet tried customise option, but Ben might be able to integrate this into Timer component.
Hopefully it's a start

Leigh
- Attachments
-
- RPI4_TIMER_LED_FLASH.fcfx
- (7.63 KiB) Downloaded 602 times
Re: Raspberry Pi interupt on timer
Hi Leigh,
Thanks, I have looked at SIGALRM and cannot quite make out what the parameters are/do. If I wanted to run a macro every second would I need to have ualarm(0,1000) or the other way round. I assume all the other code I want to run goes where your loop is.
Do I need a return or some method to return to where it was before the interrupt or is that automatic?
Bob
Thanks, I have looked at SIGALRM and cannot quite make out what the parameters are/do. If I wanted to run a macro every second would I need to have ualarm(0,1000) or the other way round. I assume all the other code I want to run goes where your loop is.
Do I need a return or some method to return to where it was before the interrupt or is that automatic?
Bob
-
- Valued Contributor
- Posts: 1466
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 136 times
- Been thanked: 713 times
Re: Raspberry Pi interupt on timer
From the ualarm docs:
The ualarm() function causes the signal SIGALRM to be sent to the
invoking process after (not less than) usecs microseconds. The
delay may be lengthened slightly by any system activity or by the
time spent processing the call or by the granularity of system
timers.
Unless caught or ignored, the SIGALRM signal will terminate the
process.
If the interval argument is nonzero, further SIGALRM signals will
be sent every interval microseconds after the first.
So - the first parameter is delay until first signal and then second parameter the interval to subsequent signals (unless 0)
In the example this will call LED_Flash automatically after 500000us and then every 500000us (0.5 seconds) - your program then can do whatever....
Martin
The ualarm() function causes the signal SIGALRM to be sent to the
invoking process after (not less than) usecs microseconds. The
delay may be lengthened slightly by any system activity or by the
time spent processing the call or by the granularity of system
timers.
Unless caught or ignored, the SIGALRM signal will terminate the
process.
If the interval argument is nonzero, further SIGALRM signals will
be sent every interval microseconds after the first.
So - the first parameter is delay until first signal and then second parameter the interval to subsequent signals (unless 0)
In the example this will call LED_Flash automatically after 500000us and then every 500000us (0.5 seconds) - your program then can do whatever....
Martin
-
- Valued Contributor
- Posts: 447
- Joined: Mon Dec 07, 2020 1:00 pm
- Has thanked: 81 times
- Been thanked: 243 times
Re: Raspberry Pi interupt on timer
And to add, the signal will interrupt whatever is in the main loop, run the macro LED_Flash (in the example case) then return back onto the main loop wherever it left off
Re: Raspberry Pi interupt on timer
Hi,
I am not sure if this is working for me, whenever I first tried to implement it (with 0,1000000) the web server din not seem to be available. I then tried with (1000000, 1000000) and the web server was back but the macro was not being called.
I may be doing it wrong but from the example I assume I needed to add FCM_ to the macro to be called?
Regards,
Bob
I am not sure if this is working for me, whenever I first tried to implement it (with 0,1000000) the web server din not seem to be available. I then tried with (1000000, 1000000) and the web server was back but the macro was not being called.
I may be doing it wrong but from the example I assume I needed to add FCM_ to the macro to be called?
Regards,
Bob
-
- Valued Contributor
- Posts: 447
- Joined: Mon Dec 07, 2020 1:00 pm
- Has thanked: 81 times
- Been thanked: 243 times
Re: Raspberry Pi interupt on timer
Yes, re the FCM.
The code in the interrupt macro should be as short as possible, and not involve any waiting for other events.
What about testing by first just having the interrupt macro to flash a LED? Then build up from there.
The code in the interrupt macro should be as short as possible, and not involve any waiting for other events.
What about testing by first just having the interrupt macro to flash a LED? Then build up from there.
Re: Raspberry Pi interupt on timer
That would be the most sensible thing to do but the target is in a remote location and possibility of adding LED as it has a shield on top without pass though pins.What about testing by first just having the interrupt macro to flash a LED?
I do have a Zero somewhere so will have to dig that out. The macro is quite large so I wonder if it is possible to just set a bit and use that in the main program and reset it in the macro once it has been run. Or would I need to create a macro just to set the bit.
Scrap that idea, Zero is not supported.I do have a Zero somewhere so will have to dig that out.
Bob
-
- Valued Contributor
- Posts: 1466
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 136 times
- Been thanked: 713 times
Re: Raspberry Pi interupt on timer
A simple example:
The interrupt routine updates a variable - which is sent to the console in FC. Seems to work reliably - but an oddity, if you change the delay in ualarm (say 500000, 100000) - then the delay in the print loop seems to run at the speed of this (ie 10 times a second, rather than waiting 0.5s) - using this seems to 'break' FC's delay?
Martin
The interrupt routine updates a variable - which is sent to the console in FC. Seems to work reliably - but an oddity, if you change the delay in ualarm (say 500000, 100000) - then the delay in the print loop seems to run at the speed of this (ie 10 times a second, rather than waiting 0.5s) - using this seems to 'break' FC's delay?
Martin