2022-03-10 07:57 AM
Hello,
I'm working with the NUCLEO-G0B1RE, controlling some motors.
In order to correctly control motor I need to synchronize to timers. For this, I chose to use TIM3 and TIM15 TIM15 on Slave-Gated mode
My issue is that when the TIM3 and TIM15 start running they have nearly, but not the same, CNT.
However, after some time the TIM3 and TIM15 are clearly not synch. They seem to follow each other but with a difference of ~700 ticks.
Clock Tree is not the same for both Timers, but the frequency is configured to be the same.
I attach some print screens of the configuration. I can post completly the code, or clock tree...etc. if required.
Thank you for your help!
Solved! Go to Solution.
2022-03-14 12:23 AM
Hello KnarfB ,
Thank you for the answer, yes you are right, the description of the Gated mode is as you describe.
I'll perform some tests today with you proposed solution.
PS: Sorry for the delay. I did not get any notification on the email about the answer.
Is this something to activate?
Have a nice day!
2022-03-10 12:23 PM
Why gated mode? This is pause/resume for the slave. Wouldn't fit reset mode better here?
2022-03-14 12:23 AM
Hello KnarfB ,
Thank you for the answer, yes you are right, the description of the Gated mode is as you describe.
I'll perform some tests today with you proposed solution.
PS: Sorry for the delay. I did not get any notification on the email about the answer.
Is this something to activate?
Have a nice day!
2022-03-22 05:05 AM
Hello,
Regarding the proposed solution.
It was not successful, I still have the timers which are mant to be synch on their CNT value but little by litlte they finish with a delta. I see this behavior still with the trigger mode.
We found another technical solution, although i'm still curious about how to synch both timers
If you have any insight on how to do it please tell me.
Thank you for your previous answer!
Have a nice day!
2022-03-22 11:53 PM
Hi, I spent a little more time on that, having a Nucleo-G071RB though. Did never observe that TIM3 and TIM15 run out of sync dynamically, i.e. their counter difference stayed constant all the time. The only reason for a dynamic change could IMHO be that you are using a different clock for TIM15, PLLQ clock?
What I observed is however, that the counter differences could be different for different debug/run sessions. It turned out that, by default, the slave is initialized first:
MX_TIM3_Init();
MX_TIM15_Init();
and may catch a trigger event during its master's init. So I reverted the init sequence and now the timers run in perfect sync. Another argument pro register-level and against auto code generation, hmm. The init sequence can be reorderd in the GUI by using the obscure blue icons in Project Manager > Advanced Settings > Generated Function Calls.
For reading the two CNT registers in parallel, I used a debug session and let the timers freeze on debug pause by calling
__HAL_DBGMCU_FREEZE_TIM15();
__HAL_DBGMCU_FREEZE_TIM3();
in the very beginning of main(). For your reference:
and main.c attached.
hth
KnarfB
2022-03-23 01:50 AM
@KnarfB , hi,
a few comments:
Jan
2022-03-23 09:06 AM
Hello,
Thank you both for your answers,
I did learn something too!
MMM... regarding my issue, I must be doing something wrong because
I keep getting a different CNT between TIM3 and TIM15
Have a nice day!
PS : My configuration is the following and please find attached the code I used to test (Core):
2022-03-24 12:44 AM
Hi @Sego2 ,
I diffed your code with mine. If you swap the two init lines to
MX_TIM15_Init();
MX_TIM3_Init();
th timers run in sync. As @Community member pointed out, TIM15 is master and TIM3 is slave in my setup, but vice versa in yours. Sorry for the confusion.
hth
KnarfB
2022-04-05 11:53 AM
Hello @KnarfB and @Community member ,
The first proposition solved the issue.
An other friend proposed me to use a PWM output in order to visualize the fact that the CNT were exactly the same.
I wish you the best and thanks again for the help
Best regards! :)