If I've understood your question you can access the timer indirectly via alarm() and signal().
Here is a very simple Hello World program for the Raspberry Pi, using wiringPi, that toggles pin 40 and pin 38. Pin 40 is toggled in the main loop and pin 38 from the alarm interrupt signal.
Compile with: gcc -Wall -o helloworld helloworld.c -lwiringPi
Control+c to quit.
I hope this helps,
JSU
helloworld.c
#include <wiringPi.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
void alarmWakeup(int sig_num);
int main(int argc, char *argv[])
{
unsigned int j;
wiringPiSetupPhys();//use the physical pin numbers on the P1 connector
pinMode(40, OUTPUT);
pinMode(38, OUTPUT);
signal(SIGALRM, alarmWakeup);
ualarm(5000, 5000);
while(1)
{
digitalWrite(40, HIGH); //pin 40 high
for(j=0; j<1000000; j++);//do something
digitalWrite(40, LOW); //pin 40 low
for(j=0; j<1000000; j++);//do something
}
return 0;
}//int main(int argc, char *argv[])
void alarmWakeup(int sig_num)
{
unsigned int i;
if(sig_num == SIGALRM)
{
digitalWrite(38, HIGH); //pin 38 high
for(i=0; i<65535; i++); //do something
digitalWrite(38, LOW); //pin 38 low
}
}
Answer from JSU on Stack OverflowRaspberry Pi Forums
forums.raspberrypi.com › board index › programming › bare metal, assembly language
Using the system timer interrupt at 1MHz - Raspberry Pi Forums
On linux there is no point you can't run 1uS interrupt rate you will struggle with that rate even in baremetal. Tightloop or fancy DMA is the only way you are going to do that rate on a Raspberry Pi.
Timer interrupt example - Raspberry Pi Forums
This question is completely independent from my previous one and is really about plain bare metal programming: I want to use a timer of the fourth CPU-core (Pi 3B) to call an interrupt service routine regularly. The LED-blinking-examples I find in miscellaneous examples mainly use an endles ... More on raspberrypi.org
interrupts - Timer for speedometer - Raspberry Pi Stack Exchange
A few years ago I wrote a c program for the ATMega168 to measure elapsed time between two triggers. Ostensibly to measure slot car speed and pellet speed from an air rifle. The processor ran at 20M... More on raspberrypi.stackexchange.com
raspbian - RaspberryPi Timer Interrupt with WiringPi - Raspberry Pi Stack Exchange
Working with microcontrollers I'm used to start a timer say in main() and get an interrupt when it expires. But how do I set this up with the Raspberry Pi? More on raspberrypi.stackexchange.com
Using the system timer interrupt at 1MHz - Raspberry Pi Forums
I am hoping someone has experience ... an interrupt routine to it. It really should be possible to have something simple as toggling a gpio in that routine, and then I can start from there. I will also take a look at the CPU documentation to find out about it. Thanks again, Sietse ... The baremetal version for generating the IRQ is about 10 post back. In linux you are wasting your time it isn't possible because linux has it own needs for the IRQ system and on the Raspberry Pi it has heavy ... More on raspberrypi.org
Videos
52:23
Raspberry Pi Pico Lecture 3: Timers, timer interrupts, SPI
17:05
How to use Timers on the RPi PICO - YouTube
24:19
Raspberry Pi Pico using C/C++- Tutorial #4: Timers, Alarms and ...
01:45
Raspberry Pi: RaspberryPi Timer Interrupt with WiringPi - YouTube
22:23
Raspberry Pi Bare Metal Tutorial - Part 9 (Timers) - YouTube
raspberry-pi-os
s-matyukevich.github.io › raspberry-pi-os › docs › lesson03 › rpi-os.html
3.1: Interrupts | raspberry-pi-os
Such asynchronous notifications are called “interrupts” because they interrupt normal execution flow and force the processor to execute an “interrupt handler”. There is one device that is particularly useful in operating system development: system timer.
raspberry-pi-os
s-matyukevich.github.io › raspberry-pi-os › docs › lesson03 › linux › timer.html
3.4: Timers | raspberry-pi-os
The most important property here is handler, which points to bcm2835_time_interrupt - this is the function that is called after an interrupt is fired. If you take a look at it, you will see that it redirects all work to the event handler, registered by the clock events framework. We will examine this event handler in a while. ret = setup_irq(irq, &timer->act); if (ret) { pr_err("Can't set up timer IRQ\n"); goto err_iounmap; }
GitHub
github.com › s-matyukevich › raspberry-pi-os › blob › master › docs › lesson03 › linux › timer.md
raspberry-pi-os/docs/lesson03/linux/timer.md at master · s-matyukevich/raspberry-pi-os
This code snippet is used to find Linux irq number, corresponding to the third timer interrupt (Number 3 is hardcoded as DEFAULT_TIMER constant). Just a quick reminder: Raspberry Pi system timer has 4 independent set of timer registers, and here the third one is used.
Author s-matyukevich
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
Timer Interrupt with Python 3 - Raspberry Pi Forums
In my case, i want to check pin states during 1s and then still process in my program. I tried to use this "threading" module and I did this little program : ... import threading def hello(): print('Hello') a=1 t = threading.Timer(5.0, hello) t.start() a=0 while(a==0): print("you're here") print('Good By') The timer method is working, it print a 'Hello' after 5 seconds but unfortunately, as a function,it doesn't save my variable.
Raspberry Pi
raspberrypi.org › board index › programming › bare metal, assembly language
Timer interrupt example - Raspberry Pi Forums
May 20, 2018 - QA7->TimerRouting.Routing = LOCALTIMER_TO_CORE0_IRQ; // Route local timer IRQ to Core0 QA7->TimerControlStatus.ReloadValue = 100; // Timer period set QA7->TimerControlStatus.TimerEnable = 1; // Timer enabled QA7->TimerControlStatus.IntEnable = 1; // Timer IRQ enabled QA7->TimerClearReload.IntClear = 1; // Clear interrupt QA7->TimerClearReload.Reload = 1; // Reload now QA7->Core0TimerIntControl.nCNTPNSIRQ_IRQ = 1; // We are in NS EL1 so enable IRQ to core0 that level QA7->Core0TimerIntControl.nCNTPNSIRQ_FIQ = 0; // Make sure FIQ is zero EnableInterrupts(); // Start interrupts rolling So I leave you the bit I am confused about. Your job is to pick the core up, bring the core up to full speed, bring the caches and memory online, clear the BSS section, make sure the vector table has the interrupt address and enter the C code.
Random Nerd Tutorials
randomnerdtutorials.com › home › raspberry pi pico › raspberry pi pico with interrupts: external and timer interrupts (micropython)
Raspberry Pi Pico Interrupts: External and Timer (MicroPython) | Random Nerd Tutorials
December 3, 2025 - The following example makes use of the Timer class to blink an LED every half a second. # Rui Santos & Sara Santos - Random Nerd Tutorials # Complete project details at https://RandomNerdTutorials.com/raspberry-pi-pico-interrupts-micropython/ from machine import Pin, Timer from time import sleep # LED pin led_pin = 20 led = Pin(led_pin, Pin.OUT) # Callback function for the timer def toggle_led(timer): led.value(not led.value()) # Toggle the LED state (ON/OFF) # Create a periodic timer blink_timer = Timer() blink_timer.init(mode=Timer.PERIODIC, period=500, callback=toggle_led) # Timer repeats every half second # Main loop (optional) while True: print('Main Loop is running') sleep(2)
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › raspberry pi pico › general
Timed interrupt, 1mS - Raspberry Pi Forums
The library documentation is at MBED_RPI_PICO_TimerInterrupt. Following the "Read the documentation" link, below the maintainers name, takes you to the github repository where you will find very well written documentation and examples. I modified the 50ms_HWTimer example sketch and was able to get a stable 1ms interrupt.
Stack Exchange
raspberrypi.stackexchange.com › questions › 143019 › timer-for-speedometer
interrupts - Timer for speedometer - Raspberry Pi Stack Exchange
According to /proc/timer_list, a RPi4 have some clocks with 1 nsec resolution. If you use Python, you can use time.clock_gettime_ns( time.CLOCK_REALTIME) import time t0 = time.clock_gettime_ns( time.CLOCK_REALTIME) t1 = time.clock_gettime_ns( time.CLOCK_REALTIME) duration = t1-t0 # duration is integer with nanosecond resolution ... Thank you. That is exactly what I was looking for to get me started. I had an uncommitted pi zero W that I've started experimenting with.
rpi4-osdev
rpi4os.com › part13-interrupts
Writing a “bare metal” operating system for Raspberry Pi 4 (Part 13) | rpi4-osdev
In fact, handle_timer_1() and ... Timer 3 is configured to progress at 4 times the speed of Timer 1. The interrupt controller is the hardware responsible for telling the CPU about interrupts as they occur....
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › c/c++
wiringPi: featuring a Timer Interrupt? - Raspberry Pi Forums
#include <stdio.h> #include <pthread.h> #include <stdbool.h> #include <unistd.h> #include <stdlib.h> #include <stdint.h> #include <wiringPi.h> void ISR(uint32_t tick) { // do sth specific } uint32_t timerloop() { volatile static uint32_t TimerTick=0; while(true) { if(TimerTick>=100000) TimerTick=0; ISR (TimerTick); TimerTick++; delayMicroseconds(10); } } int main() { const int policy = SCHED_RR; const int minPrio = sched_get_priority_min(policy); const int maxPrio = sched_get_priority_max(policy); sched_param param; pthread thread0; pthread_create(&thread0, NULL, timerloop, NULL); param.sched_priority = maxPrio - 1; pthread_setschedparam(thread0, policy, ¶m); //... }
Raspberry Pi Forums
forums.raspberrypi.com › board index › hardware and peripherals › raspberry pi pico › micropython
How to get a timed interrupt - Raspberry Pi Forums
PWM pin going at the right frequency and connecting this to another pin But the PWM hardware can generate interrupts, according to the datasheet.
Flowcode
flowcode.co.uk › forums › viewtopic.php
Raspberry Pi interupt on timer - Flowcode Support Board
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 ... 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?
GitHub
github.com › khoih-prog › RPI_PICO_TimerInterrupt
GitHub - khoih-prog/RPI_PICO_TimerInterrupt: This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO. These RPI_PICO_TimerInterrupt Hardware Timers, using Interrupt, still work even if other functions are blocking. Moreover, they are much more precise (certainly depending on clock frequency accuracy) than other software timers using millis() or micros(). That's mandatory if you need to measure some data requiring better accuracy. It now supports 16 ISR
January 29, 2023 - This library enables you to use Interrupt from Hardware Timers on RP2040-based boards such as RASPBERRY_PI_PICO. These RPI_PICO_TimerInterrupt Hardware Timers, using Interrupt, still work even if other functions are blocking.
Starred by 37 users
Forked by 18 users
Languages C++ 53.9% | C 45.7% | Shell 0.4%
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › bare metal, assembly language
ARM timer (sp804) interrupts on Pi4 - Raspberry Pi Forums
Below is the code snippet -- #define AT_GIC_IRQ (64) addr = ioremap(0xFE00B400, 0x1000); if(addr == NULL) { printk(KERN_ERR "Failed in ioremap"); goto r_sysfs; } ret = request_irq(AT_GIC_IRQ, irq_handler,IRQF_SHARED,"etx_device", (void *)(irq_handler)); if(ret) { printk(KERN_ERR "my_device: cannot register IRQ %d\n ", ret); goto irq; } printk(KERN_INFO "my_device:register IRQ %d\n", ret); How fast do you want your timer interrupts to fire? Is your linux real time or not? You may want to put it on the FIQ instead of the USB (dwc_otg.fiq_fsm_enable=0 dwc_otg.fiq_enable=0 in this order in the cmdline.txt). IRQs may not be serviced very fast if kernel is already servicing one or executing a critical code section. ... Hello all, I have stumbled into this topic as I am also interested in interfacing with the SP804-like ARMC timer present on the Raspberry-Pi 4b.
Raspberry Pi Forums
forums.raspberrypi.com › board index › using the raspberry pi › troubleshooting
1 mS timed interrupt - Raspberry Pi Forums
Code: int Init_Timer ( void ) { struct sigaction sa; struct itimerval timer; memset (&sa,0,sizeof(sa)); sa.sa_handler = &timer_handler; sigaction(SIGVTALRM,&sa,NULL); //configure timer to expire after 1 mS timer.it_value.tv_sec = 0; timer.it_value.tv_usec = 1000; timer.it_interval.tv_sec = 0; timer.it_interval.tv_usec= 1000; setitimer ( ITIMER_VIRTUAL, &timer, NULL ); } The interrupt works fine it does not matter what value I put into tv.usec I always seem to get a 10 mS interrupt.