0
votes

I'm using two timers tim3 and tim4 for counting motor encoder readings (tim3) and handling hall sensor inputs (tim4. Inputs ch1, ch2 and ch3 XORed into TI1 of TIM4 running in hall interface mode). What I would like to do now is to synchronize the two timers so that when hall toggles, encoder timer is reset. However it seems that there is no way to combine encoder mode (in the SMS register) with reset mode such that the counter tim3 is reset when tim4 TRGO toggles. It seems that I can only choose one mode or the other but not combination of both.

Maybe I'm misunderstanding how the two timers can be combined for rotor position estimation? What is the best way to combine and sync hall sensor readings with encoder readings on stm32 without using an ISR to reset the counter manually? (Preferably I want to do this automatically in hardware. I have the manual solution working, but I'm not 100% happy with it).

The chip is stm32f103.

1
You did not specify the chip.Jeroen3

1 Answers

0
votes

In CR2 each timer has an output signal (MMS). In SMCR each timer has input signal modes (SMS).

When you set the Hall timer to Compare Pulse and the encoder timer to Reset Mode, I think the encoder timer will reset each time input capture on CH1 of Hall timer.

If this is possible in your chip depends on the interconnects between the timers. See TIMx Internal trigger connection (ITR).
SMS bits are already on encoder mode. You can't have both reset and encoder mode.

You can trigger a DMA operation from memory to TIMx->EGR:UG.
TIM3_CH1 can trigger a halfword memory to peripheral operation on DMA1 channel 6 with data 0x0001 to TIM4->EGR.
This will cause TIM4 to re-initialize the counter.