IntervalTimer faster than 2us on Teensy 4.0

Status
Not open for further replies.

ossi

Well-known member
The highest interrupt rate using a IntervalTimer is (as far as I know) 500000 interrupts/second. Is there a possibility to get a higher rate, perhaps by clocking the timer faster?
 
First to answer your question, yes, if you want more you can edit IntervalTimer.h to remove this limit.

Code:
                if (cycles < 17) return false;

But now that you have your answer, maybe a better question is whether you should consider some other approach. Interrupts have overhead. Without this safety limit, you can easily overtax your CPU, leaving little or no CPU time left for other work.

Usually creative ways to use timers, DMA and specific peripherals should be used for efficient way to do things at higher speeds. Trying to run so many interrupts per second is rarely a good idea.
 
Edit: Crosspost...

Here a link showing how to get higher frequencies with the IntervalTimer https://forum.pjrc.com/threads/5922...4-0-versus-3-6?p=228049&viewfull=1#post228049
(the mentioned pull request from Kurt might be in the current Teensyduino already but I don't really know)

You can also use the TeensyTimerTool (https://github.com/luni64/TeensyTimerTool) and use one of the TMR (150MHz) or GPT (24/150MHz) based periodic timers. IIRC you should be able to go down to 2-3MHz (but this will generate a significant processor load). The chapter 'configuration' in the README shows how to switch the GPT based timers to the 150MHz clock.
 
Last edited:
@Paul: I want to generate signals as fast as possible. The CPU has no other work to do after the parameters have been setup. Of course you are right that normally fast interruopts should be avoided.
@luni: I got the following line from your hints:
CCM_CSCMR1 &= ~CCM_CSCMR1_PERCLK_CLK_SEL; //<-------- Switch Clock to 150MHz
This does the trick and gives me the right place where to look for. So thanks for your help!
 
Status
Not open for further replies.
Back
Top