cancel
Showing results for 
Search instead for 
Did you mean: 

TIM master trigger question, what is the difference between TRGO = Compare Pulse OC1 and OC1REF?

DKuro.1
Associate III

Hi,

I am synchronizing two timers, actually already succeed but I was stuck two days because the trigger output event TRGO of TIM1 was connected to OC4REF (and CCR4 was accordingly set).

With this configuration I didn't receive a pulse in the slave trigger input, but when I select TRGO = OC1 and I set my value in CCR1 it worked.

I also tried with OC1REF, OC2REF and on.

My question is, what is the difference between TRGO in compare pulse (OC1) and in OCxREF?

I am using STM32G474RE

Thanks!!

Daniel

1 ACCEPTED SOLUTION

Accepted Solutions

The difference between compare pulse (MMS==0b0011) and compare tim_oc*refc (0b0100 <= MMS <= 0b0111) is that

  • Compare pulse occurs when CNT==CCR1
  • Compare tim_oc*refc occurs when the output signal of the channel goes from inactive to active level, according to the output compare mode (OC*M) bits in CCMR. All channels are set to PWM mode 1, in which the signal is active while CNT<CCR. As the timer is in the default upcounting mode, the signal goes active when CNT==0, and inactive when CNT==CCR.

So I think that setting the channel to PWM mode 2 would solve your problem if the red remark at the bottom means that the slave is indeed triggered, but at CNT==0 instead of CNT==CCR

View solution in original post

10 REPLIES 10

Which two of these are you talking about?

0693W000000W2c1QAC.png

They should work the same (except the different channel number). Read out and post content of both timers' registers in the "non-working" setting.

JW

Hi JW,

thanks for your response.

That's what I taught, that they should work the same way.... but for some reason OC1 and OC1REF are named differently. What is the difference between them?

I taught that maybe is the way the CCP1 is initialized?

If I use OC4REF and configure CCP4 to have a '1' in TRGO and if I use OC1REF and configure CCP1 it should be the same? And what if instead of OC1REF I use OC1?

By not-working I mean that the outputs of the slave timer are not synchronized.

Maybe is the way I should configure in the STM32CubeIDE in the picture?

0693W000000W2sJQAS.png

Thanks!

Daniel

CubeMX settings mean nothing. Please post the contents of the timer registers.​

Hi Berendi,

Attached are two screenshots. At the left, TRGO is configured as OC1 and at the right OC1REFC. Just noted it ends in C, maybe is the complementary?

Anyways, it is strange that it doesn't act the same.

You can see also at the left and right that CCR1 is 333. In the left one (works ok) the trigger is at this value. In the right one, I see in the oscilloscope that the trigger is like CCR1 is 0, but is not.

0693W000000W2vDQAS.png

I don't know what the Cube/CubeMX folks mean by OC1. They keep inventing their own terminology, not matching the RM, so if you want to know what that does, you have no other option than generate the code and then go and reverse engineer the stuff to get to the bottom. I am not interested in that game so I simply don't use Cube/CubeMX at all.

JW

Okay so in the first case, MMS=0b011 Compare Pulse, when compare happens, TRGO outputs a pulse lasting one timer clock.

In the latter, MMS=0b100 so it's OC1REFC (I used an older version of RM0440 for the screenshot above, missing the "c" incorrectly). The C in OC1REFC comes from the fact that it's not OC1REF directly, but it's the result of combination with OC2REF, see description of combined/asymmetric modes in the description of OC1M in TIMx_CCMR1

0693W000000W2wBQAS.png

As you don't have set any of the combined modes, in your case, the TRGO is then the same shape as the output you see on the pin, ie. "normal" PWM1 waveform.

Now why this does not do what you expect in triggering the slave, might depend on the particular setting of the slave, and in the particular sequencing of events.

JW

DKuro.1
Associate III

Thanks JW,

I understand now more about the output triggers.

I read the reference manual and try to select OC4REF and play with to OC4M register to check if I can use OC4REF as TRGo but with no success.

My project works, only that I used OC1 instead. I would like to know how to use OCxREF for future cases if its possible.

But really thanks for the help JW!!

The difference between compare pulse (MMS==0b0011) and compare tim_oc*refc (0b0100 <= MMS <= 0b0111) is that

  • Compare pulse occurs when CNT==CCR1
  • Compare tim_oc*refc occurs when the output signal of the channel goes from inactive to active level, according to the output compare mode (OC*M) bits in CCMR. All channels are set to PWM mode 1, in which the signal is active while CNT<CCR. As the timer is in the default upcounting mode, the signal goes active when CNT==0, and inactive when CNT==CCR.

So I think that setting the channel to PWM mode 2 would solve your problem if the red remark at the bottom means that the slave is indeed triggered, but at CNT==0 instead of CNT==CCR

Once again, read out and post both the master and slave timers registers, for the non-working case.

JW