Skip to main content
BFox.1
Associate II
May 31, 2023
Question

In the RM0090 TIM2-TIM5 describes master / slave. Is TRGO1 always only from TIM_CHANNEL_1? I'm not able to get the simple example in Figure 174 for timer acting as a prescaler to work.

  • May 31, 2023
  • 9 replies
  • 3126 views

..

This topic has been closed for replies.

9 replies

waclawek.jan
Super User
May 31, 2023


_legacyfs_online_stmicro_images_0693W00000blFppQAE.pngDescribe your hardware and the way how you check "it works"; read out and check/post timers' registers content.

JW

BFox.1
BFox.1Author
Associate II
May 31, 2023

JW, thanks for the reply. Sorry for the delay in answering, had to drive an hour after I saw your first response.

I'm using the STM32F429zi on an ST Nucleo board. We've been using that for about five years and have working product, but I'm working on a new feature for us to drive a stepper motor using two timers. One is tim4 that generates the pulses and tim2 counts the pulses (steps).

I'm attaching two files, the master timer (tim4) and the slave timer (tim2) MX init files.

I know that TIM4 is doing what I expect because I have ch 4 going to a pin and observing the 50% PWM on my scope when I start this up.

I have a logging system to a serial port, so I'm dumping the contents of tim2->instance->CNT. It remains at zero (with is what I initialize it to) even though I see tim4 outputting the pulses.

Note the #if 0 is to take out trying make tim4 be a slave so it will always run. Eventually the two timers will also be in the converse master slave relationship so that tim4 will only output pulses when tim2 CNT compares to CCR and we have reached target.

I'm able to run this in IAR, so let me know which post registers you want to see.

Thanks for your assistance,

Bill

BFox.1
BFox.1Author
Associate II
May 31, 2023

Sorry, I should note that I have set

sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC4REF;

But it was originally set to TIM_TRGO_UPDATE, but no difference in functioning.

waclawek.jan
Super User
June 1, 2023

I don't use Cube so I don't quite know (and don't want to know) what for example HAL_TIM_SlaveConfigSynchronization() does.

You also call it twice, which I don't think you are supposed to, and you also don't fill in the struct it uses completely, and as it's a local variable, so that may be a problem, too.

Nonetheless, the mcu does not work out of source code let alone some "libraries", so yes, I (and, more importantly, you) want to see the registers. All of them, for both timers.

JW

BFox.1
BFox.1Author
Associate II
June 1, 2023

Thanks for the reply.

The main thing the slaveModeSyncrhonization is write the SMCR register SMS field. The description of the "Using one time as prescaler for another timer" specifically states one must write two values to SMS field, i.e., they seem to be commands, not simply configuration bits. Perhaps I should only write the second SMS by simply writing updating the SMS field in the second write.

I will work on getting the register dumped.

What is your timezone, I'm GMT-7.

waclawek.jan
Super User
June 1, 2023

> The main thing the slaveModeSyncrhonization is write the SMCR register SMS field.

Details do matter.

> What is your timezone, I'm GMT-7.

Slovakia, Central Europe.

JW

BFox.1
BFox.1Author
Associate II
June 1, 2023

Thanks, I'm looking at the function and breaking out the SMS register writes now.

BFox.1
BFox.1Author
Associate II
June 1, 2023

So, clearly a novice mistake as I see the mx init for tim2 is leaving the registers all 0. Not so for tim4. Now I have something I can debug. I've learned my lesson.

Thanks, hopefully I can fix this now.

Visitor II
June 26, 2023

can you plz guide me???/

 

waclawek.jan
Super User
June 27, 2023

Don't hijack others threads. Start your own, stating the STM32 and hardware you are using, and the problem you came across. You can link to this thread if you think it's relevant.

JW