cancel
Showing results for 
Search instead for 
Did you mean: 

Synch TIMs on G0B1RE

Sego2
Associate III

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!

0693W00000Kc8lCQAR.png0693W00000Kc8p3QAB.png0693W00000Kc8o5QAB.png

1 ACCEPTED SOLUTION

Accepted Solutions
Sego2
Associate III

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!

MSego.2

View solution in original post

8 REPLIES 8
KnarfB
Principal III

Why gated mode? This is pause/resume for the slave. Wouldn't fit reset mode better here?

Sego2
Associate III

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!

MSego.2

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!

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:

0693W00000KdgbMQAR.png0693W00000KdgbWQAR.pngand main.c attached.

hth

KnarfB

@KnarfB​ , hi,

a few comments:

  • you'd recommended Reset slave mode in your first reply, yet used Trigger now. I agree Trigger is more appropriate, but you might've mentioned it as it's quite important here - as is the related fact that only master's counter is enabled explicitly
  • compared to initial post, you reversed the master-slave relationship between TIM3 and TIM15, that might be confusing
  • the initial post uses nonzero prescalers; that shouldn't be an issue in this code (i.e. after reset), but could be something to be remembered should the timers be ever stopped/restarted
  • using the debug-freeze of the timers to observe their CNT synchronicity is a neat trick, thanks! (personally, not being aware of this trick, I would go through the pain of connecting an external signal and using Input capture).

Jan

Sego2
Associate III

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):

0693W00000LvUfHQAV.png 

0693W00000LvUgFQAV.png0693W00000LvUg0QAF.png0693W00000LvUfWQAV.png

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

Sego2
Associate III

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! :)