We use some essential cookies to make our website work.

We use optional cookies, as detailed in our cookie policy, to remember your settings and understand how you use our website.

4 posts • Page 1 of 1
pie_face
Posts: 171
Joined: Sun Aug 04, 2024 11:16 am

TIMER_x documentation

Sat Nov 01, 2025 12:42 pm

Hi,

On RP2040, I'm using a timer event to trigger from core0 data capture in an ISR on core1.

setting up core1 in function run via multicore_launch_core1()

Code: Select all

 irq_set_exclusive_handler(TIMER_IRQ_1, &DATA_ISR); 
 irq_set_enabled(TIMER_IRQ_1, true); // enables hw timer and NVIC entry for this core1

Code: Select all

 #define TIMER_NUM 1
 #define TIMER_MASK (1<<TIMER_NUM)
on core0 I trigger data capture

Code: Select all

 hw_set_bits(&timer_hw->intf, TIMER_MASK); // force trigger ISR on core1
in the ISR , running on core1, turn it off

Code: Select all

 hw_clear_bits(&timer_hw->intf, TIMER_MASK); // disable in NVIC of core0
This doesn't really use the timer as such , it's just a hack to get core0 to trigger core1 without having to faff around with FIFOs on which I wasted far too much time and were a bit overkill for this simple task.

In the ref manual
4.1.27.1. Detailed Description
RP2040 only has one tick generator, and it is part of the watchdog hardware.
So RP2040 only has one timer, set at 1MHz, which we probably don't want to mess with.
I also find enums

Code: Select all

TIMER_IRQ_0
....
TIMER_IRQ_3
these enums are and index into the IRQ table.

What I have trouble finding is what controls the period of these IRQs. Do they all fire every 1us once enabled?
4.1.28.1. Detailed Description

The timer has 4 alarms, and can output a separate interrupt for each alarm. The alarms match on the lower 32 bits of
the 64 bit counter which means they can be fired a maximum of 2^32 microseconds into the future. This is equivalent
to:
• 2^32 ÷ 10^6: ~4295 seconds
• 4295 ÷ 60: ~72 minutes
The timer is expected to be used for short sleeps, if you want a longer alarm see the hardware_rtc functions.
I know there are some utility fn in SDK which provide "alarms" and an alarm pool but I want find the doc on the processor.
The "4 alarms" do not appear to be part of the vocabulary of RP2040 manual. Neither is this anything to do with "sleeps", timers to not sleep the processor.

It seems there is some bleed over and confusion in this writing.

Where do I find the doc on the timing of these TIMER_IRQ_x events?

TIA.

gmx
Posts: 1845
Joined: Thu Aug 29, 2024 8:51 pm

Re: TIMER_x documentation

Tue Nov 11, 2025 5:39 pm

pie_face wrote: I know there are some utility fn in SDK which provide "alarms" and an alarm pool but I want find the doc on the processor.
The "4 alarms" do not appear to be part of the vocabulary of RP2040 manual. Neither is this anything to do with "sleeps", timers to not sleep the processor.
It seems there is some bleed over and confusion in this writing.
Where do I find the doc on the timing of these TIMER_IRQ_x events?
Look in RP2040 Datasheet:
4.6. Timer
4.6.1. Overview
The system timer peripheral on RP2040 provides a global microsecond timebase for the system, and generates
interrupts based on this timebase. It supports the following features:
• A single 64-bit counter, incrementing once per microsecond
• This counter can be read from a pair of latching registers, for race-free reads over a 32-bit bus.
Four alarms: match on the lower 32 bits of counter, IRQ on match.
...
4.6.3. Alarms
...
4.6.4. Programmer’s Model
... 4.6.4.4. Complete example using SDK
4.6.5. List of Registers

pie_face
Posts: 171
Joined: Sun Aug 04, 2024 11:16 am

Re: TIMER_x documentation

Tue Nov 11, 2025 10:08 pm

OK, it does seem that this silly language is used in RP2040 doc too.

Looks like "alarm" is the new word for a comparator, though calling these intervals "sleeps" is still wrong because interrupts to NOT "sleep" the processor.
I'd prefer not have to juggle new terms for every version of a CPU. Other ARM cortex CPUs like STM do not have "alarms" and "sleeps", so I don't know why they come in here.

Anyway , thanks for the point, I have a clearer idea what this is now.

gmx
Posts: 1845
Joined: Thu Aug 29, 2024 8:51 pm

Re: TIMER_x documentation

Tue Nov 11, 2025 10:54 pm

It is used by sleep_ functions in SDK, sets an alarm, the go to sleep by WFE.
Maybe is used also by timeout functions but you have to check.

Yep, alarms are comparators.

I think you can use PWMs as well.

4 posts • Page 1 of 1

Return to "SDK"

AltStyle によって変換されたページ (->オリジナル) /