Electronic – On STM32F4xx: Can I trigger a timer by itself so it goes through a list of periods updated from an array

stm32f4timer

I need things to happen at precise (down to the clock, ~5.5ns at 180MHz) 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?

Thank you for answers so far but soft timers are out of the question.
Also, I don't need many; I need 3-4.
I'd prefer hard answers from somebody that actually did trigger one timer from another.

Best Answer

I'm not sure what exactly you mean by "triggering itself", do you mean up- or down-counting, from a fixed clock?

I have not done this myself, but if I'm understanding your question correctly then you're looking for the auto-reload register (ARR). The counter can be configured to be reset once it reaches the ARR value, and this also sets an event flag (UDE or UIE bit in TIMx_DIER). You can service this flag either in an ISR or with a DMA channel, each time updating ARR from a table of periods. "Stopping" can be achieved with ARR = 0.

Also see ST's appnote AN4013 about the STM32 timers, which includes example setups for some common use cases.