cancel
Showing results for 
Search instead for 
Did you mean: 

Stop-start using Master-Slave timer synchronization

primer101
Associate

Hi Community:

I'm working with an STM32F411C to control a stepper motor that requires 3 PWM signals with a 120° phase shift, using Master-Slave timer synchronization between TIM1, TIM3, and TIM4. The second channel is used to trigger the next timer. When the motor stops, I need to maintain a 20kHz PWM signal with a 75% duty cycle on one winding. Everything functions fine until I need to restart the timers in synchronized mode. I've tried using the HAL_TIM_PWM_Stop and Start pair without success. I also attempted to use DeInit functions and reconfigure the timers, but it's still not working. Any ideas on how to solve this would be greatly appreciated. Thank you!

2 REPLIES 2
TDK
Super User

You can use the force/release reset bits for the peripherals to get them to the initial hardware state. If you reinitialize the handles and restart the whole setup after that, it'll work.

If you feel a post has answered your question, please click "Accept as Solution".
waclawek.jan
Super User

I assume you have TIM1->TIM3->TIM4 master-slave relationship with TIM3 and TIM4 slave-mode controller set to Trigger. That setting does nothing but set TIMx_CR1.CEN when the first trigger arrives. So, you stop the motor so that you severe the TRGO-TRGI - e.g. by changing TIMx_SMCR.SMS to Disabled in the slaves - and clearing TIMx_CR1.CEN. You may want to zero TIMx_CNT, too, in anticipation of the future start and also to set the outputs to some defined state.

Then you can reprogram TIM1 as you need, and when motor is to be restarted, program it back, and in the slaves just enable the Trigger mode in TIMx_SMCR.SMS again.  

Sticking to Cube/HAL may make this more complicated than necessary, as this may be not "typical" as deemed by Cube/HAL authors thus go against Cube/HAL's grain. I don't use Cube/HAL/MX.

JW