Timer Synchronization does not work.
- August 12, 2023
- 3 replies
- 5626 views
Hello, hope this message finds you well.
So, I'm on a project that requires multiple timers to generate 7 variable pulse waveforms in master/slave mode and I'm hoping to get parallel synchronization at startup, I'm using timer 1 as master, and timer 2 as a slave.
I have done things as per Reference Manual and ST knowledge base videos and articles, so can't see any extra detail that might cause this issue described below.
The device is STM32F103C8T6, and I am using HAL libraries.
The issue:
Tim2 does not align with Tim1, seems to me their alignment is code dependent, so sometimes they align perfectly, and when you change the code even in non-timer-related sections they get out of alignment.
more useful info for you:
TIMER 1 (Master) settings:
CH1,2,3 are "PWM Generation" and CH4 is either "PWM Generation NO Output" or "Output Compare NO output" have tried both, does not make a difference.
No Prescaler is used so Clock is 72Mhz, only using ARR for Frequency adjustments. RCR => 50.
Trigger Event Selection => Output Compare(OC4REF)
TIMER 2(Slave) settings:
Slave Mode => Trigger mode, Trigger Source = > ITR0, Clock Source for both timers => internal Clock, CH1,2,3,4 => PWM Generation.
just to note that timer2 is using DMA in DMA-Burst-Multi-write mode and it changes the ARR value as well as all the channel's CCR value 5 times in every TIM 1 period(TIM1 ARR = TIM2_ARR1 + TIM2_ARR2 + ....+ ARR5), and also all the values related to TIM1/TIM2 registers might change on the fly.
See Attachment section.
Long story short, It's been a long time since I'm tackling this, and have tried many things along the way but can not reliably synch both timers, At first TIM1 used a 9Mhz clock, and TIM2 72Mhz (8 times more) but now I changed TIM1 to use 72Mhz clock, however, no progress has been observed.
tried starting TIM2 channels first and TIM1 second and vice versa, it changed the delays but was not aligned to the required delay.
There is a visual scheme for you in the attachment section.
if you need any specific information or detail, please let me know.