cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 timing application question

jamesdavis9
Associate
Posted on February 05, 2015 at 19:44

The application is to use a STM32F4, but not allow the core to enter any level of ISR at the time it's supposed to service a TIMER interrupt. The application needs the TIMER events to be repeatable down to clock cycle.

S

o, will the following work?

- Have a list of ''things'' to do at certain time intervals (T1, T2, ...Tn).

- Have a main infinite loop running along, interpreting commands it may get in a buffer unrelated to the list. 

- A TIMER is setup to interrupt at T1. Then the INT handler sets a new T2 and restarts the timer. This operation would continue to Tn based on the list.

- The TIMER interrupt  must always have the same overhead, so it can have the same number of clock cycles. 

Is this possible?

28 REPLIES 28
Cristea.Catalin
Associate III
Posted on February 13, 2015 at 20:08

Neither of these work when the stuff has to be done near rollover.

Thanks for trying anyway :)
Cristea.Catalin
Associate III
Posted on February 26, 2015 at 00:04

Could I do this instead?  Have TIM2 self-trigger itself while I change its period?

And have it trigger other timers as well for the precise pulses I need (Use Output Compare)?  For the other things I need to happen I can tolerate the variable latency of ISRs.

I need things to happen at precise periods of time based on a list; let's say 5 periods of 444444, 555555, 666666, 777777 and 888888 timer clocks (obviously a 32bit timer clock).

I propose the following:

1. I set TIM2 

''

TIM_Period

'' with the first period. I set clock to system clock. I set it to trigger itself (is that possible?). I also set up an ISR to get fired at same time

2. I start TIM2.

3. I pre-load the next

''

TIM_Period

'' in the timer, somehow that it will only be ''effective'' after it ''fires/updates''.

4. In ISR

I increment an index through the array of values

: If a next value exists I pre-load it 

into

''

TIM_Period

'' so TIM2 loads it next time. If no next value I turn off the self triggering. 

Other things might be done in the ISR as long as short enough to end before next timer firing.

If this works, could I (in the ISR, based on some list) also set up other timers to be triggered by this main timer?

Posted on February 26, 2015 at 00:50

''You could have a singular time line, and ascribe or advance timer interrupts to occur along that line with a reasonable amount of precision. Certainly sub micro-second.''

For accurate edges synchronous to the timer clock you could use Toggle mode, pulses of reasonable length could use two toggles sufficiently spaced for interrupt servicing. For close ones, DMA, or slave another timer.

Modulating Period OR Duty (pick ONE) can be done with DMA at a trigger point from a list of new values.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cristea.Catalin
Associate III
Posted on February 26, 2015 at 01:14

How about I use TIM2 just as a time line, no toggle, just (modulated) period, and on each update/trigger (sorry, not sure which term to use) I also trigger (or not) other timers whose outputs I use for my pulses.

Is there any latency-variability in timers triggering each-other?

Posted on February 26, 2015 at 02:21

You should be able to update the period using an IRQ or DMA.

The timer's are synchronous, the internal prescale count is not visible.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cristea.Catalin
Associate III
Posted on February 26, 2015 at 22:17

It's my first time trying to trigger a slave timer from a master.

I found Jan's useful Timer Table in another thread, but I'm still confused a bit:

Can I trigger more than one slave from one master?  If yes, can I trigger ANY three timers form any slave?

Let's say I want to use TIM2 as master, and TIM1,4,8 slaves (I chose these in case ANY above is not true and because they all have TIM2 in the ITR1 line... is that necessary?)

So:

    TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);

    TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);

and then (shown only for TIM1):

    TIM_SelectInputTrigger(TIM1, TIM_TS_ITR1);

    TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_Trigger);

But I don't get what connects the output ''TIM_TRGOSource_Update'' to a certain ITR (0,1 or?)

What else do I need to do (apart from setting up the timers; and is anything tricky in there... trickier-er-er-er?)

Posted on February 26, 2015 at 22:28

I think you'll find the ITRx connectivity called out at a per TIM level in the Reference Manual. Search ''TIMx Internal trigger connection''

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Cristea.Catalin
Associate III
Posted on February 26, 2015 at 22:58

Why do you have to be like this?  I saw that and I don't get it or it's not clear.

You yourself said: ''I've had to comb over the block diagrams to decipher what the heck they might be capable of, and often concluded the solution is a bit of mess.''  Ian said: ''The timers' description in this manual is a bad joke''.

Just help, OK?
Cristea.Catalin
Associate III
Posted on February 26, 2015 at 23:02

Plus that table is in the TIM2 to TIM5 chapter so it may not contain all data for all timers.