2018-03-29 04:45 PM
Hi,
I am using a STM32F767Z MCU at the moment, and wanted to understand better understand how update interrupts work. Specifically:
I have a few questions regarding this configuration.
In other words, what type of overhead is associated with update interrupts, is it predictable, and can it cause a race condition in the scenario above?
Solved! Go to Solution.
2018-03-30 08:12 AM
for Q1, the compare match may be missed: TIM2 starts right away while you are still executing TIM1 ISR, setting the CCR1.
the right way to do it is to set up a TIM2 ISR at its end whereby you would update the CCR1, waiting for it to be trigger next time by TIM1.
2018-03-30 03:31 AM
I don't understand what do you want to achieve, perhaps you may want to elaborate on that.
Generally, interrupts take dozens of system clock cycles - at least one dozen to enter, then the compiler generated prologue must be executed and then any code, subject to compiler optimizations. Add latencies and jitters given naturally by the processor core (uninterruptible multicycle instructions), plus those given by code memory latency partially mitigated by the various buffers and pipelines and accelerators, and bus matrix clashes with other masters. The picture is very complex.
Thus, interrupts are not good enough for control in the sub-microsecond realm, even on the multimegahertz system clocks. Depending on the priority of the interrupt in question and the way how it's written and where it is run from, in the best case I'd count on jitter in the range of half to one dozen of system cycles and latency maybe two-three dozens of them.
Timer links are there for such control, but note that the preloaded value gets loaded into the CCRx at every update, i.e. at every beginning of cycle of the running timer, so you can't load a new value into it and then wait indefinitely until the other timer provides the trigger.
JW
2018-03-30 07:35 AM
Hi Jan, thanks for the helpful response.
Here's what I'm trying to accomplish. I have TIM1 set to Encoder Mode, and TIM3 is connected to a light source I would like to trigger (e.g. a LED). However, I would like to trigger TIM3 on a fractional encoder count basis. For example, instead of triggering TIM3 every 7 encoder counts, I want to trigger it every 7.4 encoder counts. I also know ahead of time the average time it takes for an encoder count to occur.
I configure TIM1 to Encoder Mode, set it to Master Mode, where TRGO is configured to the Update Event. Then I configure TIM2 (which is responsible for the fractional encoder count) as Slave Mode - Combined Reset & Trigger (Internal Trigger: ITR0/TIM1), and set it to One Pulse Mode. I setup one channel in Output Compare or PWM Mode 2, so that the compare register corresponds to the average time it takes for the fractional encoder count to occur. Configure TIM3 (which is connected to the LED) to Slave Mode - Combined Reset & Trigger (Internal Trigger: ITR1/TIM2) and set it to One Pulse Mode. So I see two ways of implementing this sub-encoder count feature. Perhaps there is a 3rd that is better, I am all ears!
I am also open to other approaches, these just happen to be the two that I have thought of.
2018-03-30 08:12 AM
for Q1, the compare match may be missed: TIM2 starts right away while you are still executing TIM1 ISR, setting the CCR1.
the right way to do it is to set up a TIM2 ISR at its end whereby you would update the CCR1, waiting for it to be trigger next time by TIM1.
2018-03-30 08:58 AM
Before we discuss this further, let's make this one clear:
I have TIM1 set to Encoder Mode,
Encoder mode is intended for... encoders. The virtue of encoders is 1. possibly changing direction; 2. varying rate; 3. possibly high frequency oscillations at around any point, including 0 (which then implies high update event rate in the timer). This makes encoder mode impractical for any timing-related application; it's good only for... erm... encoders.
So, are you absolutely sure you want to use Encoder mode? Why?
JW
2018-03-30 09:04 AM
Hi Jan, the reason I want to use encoders is that I have a motorized stage whose encoder I can tap into. I would like to synchronize the triggering of my LED with the stage so that every time the stage moves a fixed spatial distance (e.g. 7.4 encoder counts), I trigger the LED. We have done testing of the stage to show that even if we set it to run to constant velocity, it will deviate from that velocity, so it is better if we synchronize the triggering of the LED with the encoder of the stage to the best of our ability.