timer source from other timer ?

Post here first, or if you can't find a relevant section!
dannyf
Posts: 447
Joined: Sat Jul 04, 2020 7:46 pm

Re: timer source from other timer ?

Post by dannyf »

uart transmissions are slow and I think you will find helpful to just set a flag in the isr and then process it in the main loop.
picclock
Posts: 20
Joined: Sat Aug 14, 2021 8:21 am

Re: timer source from other timer ?

Post by picclock »

@ag123
The problem I have with millis is that they require constant checking. So if I am using 4 things that require delays I these will get checked millions of times before they actually timeout. The other issue is that nothing is done until the check for millis is made, so its impossible to resolve a sequence of timeouts without substantial random delays. The accuracy of millis is also limited to milliseconds which is quite long.
Using a hardware timer interrupt is precise and accurate with no software checking overhead. It seems a bit of a shortcoming that the Arduino defaults to settings of Hertz and Microseconds for loading the timer(s), limiting their perceived range unless you dive into prescalers and datasheets.
The snag I have found with the internal timers is that they are clocked and linked to the peripheral bus, whose speed can be changed by driver libraries (e.g TFT_eSPI).

Best Regards

picclock
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: timer source from other timer ?

Post by ag123 »

What you are doing isn't very 'different' from apps such as Marlin firmware (for 3d printing). Marlin firmware runs the steppers on hardware timer interrupts.
A reason is that if millis() came late for some reasons, perhaps there'd be a blob of molten plastic deposited on the print.
So hardware timers are indeed used for various purposes.
JimEli
Posts: 20
Joined: Sat Apr 17, 2021 11:33 pm

Re: timer source from other timer ?

Post by JimEli »

Cascade mode of TIM1 (master) and TIM3 stm32f401 nucleo example from the book Mastering STM32.
dannyf
Posts: 447
Joined: Sat Jul 04, 2020 7:46 pm

Re: timer source from other timer ?

Post by dannyf »

So if I am using 4 things that require delays
it is a good programming habbit to reduce the use of delays.

if you have to, check out protothreads as a possible way to get around it.
The accuracy of millis is also limited to milliseconds which is quite long.
you can use DWT or SysTick then.
victoriaaustine
Posts: 1
Joined: Tue Jun 28, 2022 3:24 pm

Re: timer source from other timer ?

Post by victoriaaustine »

I am struggling a bit with the timers on the STM32f4011. Max time for Tim2 32 bit seems to be between 30-60 seconds.
I would like to use the output of one timer as the clock source for several others, like an additional prescaler.
I'd prefer to do it this way as it will have minimum impact on system performance.

Not sure if its possible though
Any examples or pointers to code about this much appreciated, tried googling but all I got was std timer stuff.
Any help much appreciated.
dannyf
Posts: 447
Joined: Sat Jul 04, 2020 7:46 pm

Re: timer source from other timer ?

Post by dannyf »

you can use one timer to trigger another timer - aka chain them together. I wrote a page on this a while ago and can post it if you want. It is fairly simple.
- I never tried to chain more than two timers together. but I would imagine that you can. that could produce some extremely long duration: think about a 64bit or 96 bit or 128 bit timer :)

But the bigger question for you is: do you really need that? many times a "composite timer" (aka a hardware timer + a software counter) would work.

and I usually do this with a free running timer.
Post Reply

Return to “General discussion”