cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H573 timer synchronization issue

AHame
Associate III

Not sure why my previous post was marked as spam:

Hello,

I'm trying to do something relatively simple but can't figure out the issue. It might also be possible that there is no issue and my expectations are wrong about timer synchronization.

 

I am using TIM1 as a master with trigger out event configured when the timer is enabled. Enabling timer1 should start TIM2 and TIM15 (both configured as slave with appropriate ITR0 triggers).

 

Just for debugging and simplicity all the timers are using the same prescaler and the same period (ARR register value is the same).

 

The timer do start when I enable timer1 as expected. But they are not synchronized. 

Below are registers dump for tim1, tim2 and tim15 just before setting TIM1.CR1  enable bit. Once I set the enable bit I get the logic analyzer capture shown.

I mean it works in the sense that enabling TIM1 triggers TIM2 and TIM15 but why aren't they synchronized?

Here is the code. I am using HAL for simplicity but I did try direct register manipulation but outcome was exactly the same. 

HAL_TIM_OC_Start_IT(&htim2,TIM_CHANNEL_3);
HAL_TIM_OC_Start_IT(&htim15,TIM_CHANNEL_2);
HAL_TIM_OC_Start_IT(&htim1,TIM_CHANNEL_1);

 


AHame_1-1721067035595.png

 

On the surface it appears to work but when I zoom in on the first rising edge :

AHame_2-1721067075684.png

 

 


 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Still looks like it could be a rise time issue. TIM1 is fastest, and overshoots, so the edge happens there first. TIM2 by comparison is much slower, no overshoot. Analog capture speed isn't quite high enough to say with certainty.

They all start going high at about the same time. Just takes longer for some channels to hit the threshold.

TDK_0-1721145462677.png

Could be a scope channel issue, but unlikely. Swap channels to eliminate that possibility.

There can be subtle timing differences between master/slave and timers not on the same bus. Changing the starting CNT value can shift things with the resolution of one timer tick.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

6 REPLIES 6
AHame
Associate III

Register Dumps

Peripheral, Register, Value, Fields
TIM1, TIM1_CR1, 0x0000, CEN: B_0x0; UDIS: B_0x0; URS: B_0x0; OPM: B_0x0; DIR: B_0x0; CMS: B_0x0; ARPE: B_0x0; CKD: B_0x0; UIFREMAP: B_0x0; DITHEN: B_0x0
TIM1, TIM1_CR2, 0x00100020, CCPC: B_0x0; CCUS: B_0x0; CCDS: B_0x0; MMS: B_0x2; TI1S: B_0x0; OIS1: B_0x0; OIS1N: B_0x0; OIS2: 0b0; OIS2N: 0b0; OIS3: 0b0; OIS3N: 0b0; OIS4: 0b0; OIS4N: 0b0; OIS5: 0b0; OIS6: 0b0; MMS2: B_0x1; MMS_1: 0b0
TIM1, TIM1_SMCR, 0x00000000, SMS: B_0x0; OCCS: B_0x0; TS: B_0x0; MSM: B_0x0; ETF: B_0x0; ETPS: B_0x0; ECE: B_0x0; ETP: B_0x0; SMS_1: 0b0; TS_1: 0b00; SMSPE: B_0x0; SMSPS: B_0x0
TIM1, TIM1_DIER, 0x00000000, UIE: B_0x0; CC1IE: B_0x0; CC2IE: B_0x0; CC3IE: B_0x0; CC4IE: B_0x0; COMIE: B_0x0; TIE: B_0x0; BIE: B_0x0; UDE: B_0x0; CC1DE: B_0x0; CC2DE: B_0x0; CC3DE: B_0x0; CC4DE: B_0x0; COMDE: B_0x0; TDE: B_0x0; IDXIE: B_0x0; DIRIE: B_0x0; IERRIE: B_0x0; TERRIE: B_0x0
TIM1, TIM1_SR, 0x00000000, UIF: B_0x0; CC1IF: B_0x0; CC2IF: 0b0; CC3IF: 0b0; CC4IF: 0b0; COMIF: B_0x0; TIF: B_0x0; BIF: B_0x0; B2IF: B_0x0; CC1OF: B_0x0; CC2OF: 0b0; CC3OF: 0b0; CC4OF: 0b0; SBIF: B_0x0; CC5IF: 0b0; CC6IF: 0b0; IDXF: B_0x0; DIRF: B_0x0; IERRF: B_0x0; TERRF: B_0x0
TIM1, TIM1_EGR, 0x0000, UG: -; CC1G: -; CC2G: -; CC3G: -; CC4G: -; COMG: -; TG: -; BG: -; B2G: -
TIM1, TIM1_CCMR1_Input, 0x00000030, CC1S: B_0x0; IC1PSC: B_0x0; IC1F: B_0x3; CC2S: B_0x0; IC2PSC: 0b00; IC2F: 0b0000
TIM1, TIM1_CCMR1_Output, 0x00000030, CC1S: B_0x0; OC1FE: B_0x0; OC1PE: B_0x0; OC1M: B_0x3; OC1CE: B_0x0; CC2S: B_0x0; OC2FE: 0b0; OC2PE: 0b0; OC2M: 0b000; OC2CE: 0b0; OC1M_1: 0b0; OC2M_1: 0b0
TIM1, TIM1_CCMR2_Input, 0x00000000, CC3S: B_0x0; IC3PSC: 0b00; IC3F: 0b0000; CC4S: B_0x0; IC4PSC: 0b00; IC4F: 0b0000
TIM1, TIM1_CCMR2_Output, 0x00000000, CC3S: B_0x0; OC3FE: 0b0; OC3PE: 0b0; OC3M: B_0x0; OC3CE: 0b0; CC4S: B_0x0; OC4FE: 0b0; OC4PE: 0b0; OC4M: 0b000; OC4CE: 0b0; OC3M_1: 0b0; OC4M_1: 0b0
TIM1, TIM1_CCER, 0x00000000, CC1E: B_0x0; CC1P: B_0x0; CC1NE: B_0x0; CC1NP: B_0x0; CC2E: 0b0; CC2P: 0b0; CC2NE: 0b0; CC2NP: 0b0; CC3E: 0b0; CC3P: 0b0; CC3NE: 0b0; CC3NP: 0b0; CC4E: 0b0; CC4P: 0b0; CC4NE: 0b0; CC4NP: 0b0; CC5E: 0b0; CC5P: 0b0; CC6E: 0b0; CC6P: 0b0
TIM1, TIM1_CNT, 0x00000000, CNT: 0b0000000000000000; UIFCPY: 0b0
TIM1, TIM1_PSC, 0x00F9, PSC: 0b0000000011111001
TIM1, TIM1_ARR, 0x00000031, ARR: 0b00000000000000110001
TIM1, TIM1_RCR, 0x0000, REP: 0b0000000000000000
TIM1, TIM1_CCR1, 0x00000000, CCR1: 0b00000000000000000000
TIM1, TIM1_CCR2, 0x00000000, CCR2: 0b00000000000000000000
TIM1, TIM1_CCR3, 0x00000000, CCR3: 0b00000000000000000000
TIM1, TIM1_CCR4, 0x00000000, CCR4: 0b00000000000000000000
TIM1, TIM1_BDTR, 0x02002000, DTG: 0b00000000; LOCK: B_0x0; OSSI: B_0x0; OSSR: B_0x0; BKE: B_0x0; BKP: B_0x1; AOE: B_0x0; MOE: B_0x0; BKF: B_0x0; BK2F: B_0x0; BK2E: B_0x0; BK2P: B_0x1; BKDSRM: B_0x0; BK2DSRM: 0b0; BKBID: B_0x0; BK2BID: 0b0
TIM1, TIM1_CCR5, 0x00000000, CCR5: 0b00000000000000000000; GC5C1: B_0x0; GC5C2: B_0x0; GC5C3: B_0x0
TIM1, TIM1_CCR6, 0x00000000, CCR6: 0b00000000000000000000
TIM1, TIM1_CCMR3, 0x00000000, OC5FE: 0b0; OC5PE: 0b0; OC5M: 0b000; OC5CE: 0b0; OC6FE: 0b0; OC6PE: 0b0; OC6M: 0b000; OC6CE: 0b0; OC5M_1: 0b0; OC6M_1: 0b0
TIM1, TIM1_DTR2, 0x00000000, DTGF: 0b00000000; DTAE: B_0x0; DTPE: B_0x0
TIM1, TIM1_ECR, 0x00000000, IE: B_0x0; IDIR: B_0x0; IBLK: B_0x0; FIDX: B_0x0; IPOS: B_0x0; PW: 0b00000000; PWPRSC: 0b000
TIM1, TIM1_TISEL, 0x00000000, TI1SEL: B_0x0; TI2SEL: B_0x0; TI3SEL: B_0x0; TI4SEL: B_0x0
TIM1, TIM1_AF1, 0x00000001, BKINE: B_0x1; BKCMP1E: B_0x0; BKCMP2E: B_0x0; BKCMP3E: B_0x0; BKCMP4E: B_0x0; BKCMP5E: B_0x0; BKCMP6E: B_0x0; BKCMP7E: B_0x0; BKCMP8E: B_0x0; BKINP: B_0x0; BKCMP1P: B_0x0; BKCMP2P: B_0x0; BKCMP3P: B_0x0; BKCMP4P: B_0x0; ETRSEL: B_0x0
TIM1, TIM1_AF2, 0x00000001, BK2INE: B_0x1; BK2CMP1E: B_0x0; BK2CMP2E: B_0x0; BK2CMP3E: B_0x0; BK2CMP4E: B_0x0; BK2CMP5E: B_0x0; BK2CMP6E: B_0x0; BK2CMP7E: B_0x0; BK2CMP8E: B_0x0; BK2INP: B_0x0; BK2CMP1P: B_0x0; BK2CMP2P: B_0x0; BK2CMP3P: B_0x0; BK2CMP4P: B_0x0; OCRSEL: B_0x0
TIM1, TIM1_DCR, 0x00000000, DBA: B_0x0; DBL: B_0x0; DBSS: 0b0000
TIM1, TIM1_DMAR, 0x00000000, DMAB: 0b00000000000000000000000000000000
TIM15, TIM15_CR1, 0x0000, CEN: B_0x0; UDIS: B_0x0; URS: B_0x0; OPM: B_0x0; ARPE: B_0x0; CKD: B_0x0; UIFREMAP: B_0x0; DITHEN: B_0x0
TIM15, TIM15_CR2, 0x0020, CCPC: B_0x0; CCUS: B_0x0; CCDS: B_0x0; MMS: B_0x2; TI1S: B_0x0; OIS1: B_0x0; OIS1N: B_0x0; OIS2: B_0x0
TIM15, TIM15_SMCR, 0x00000006, SMS1: B_0x6; TS1: B_0x0; MSM: B_0x0; SMS2: B_0x0; TS2: B_0x0
TIM15, TIM15_DIER, 0x0004, UIE: B_0x0; CC1IE: B_0x0; CC2IE: B_0x1; COMIE: B_0x0; TIE: B_0x0; BIE: B_0x0; UDE: B_0x0; CC1DE: B_0x0; COMDE: B_0x0; TDE: B_0x0
TIM15, TIM15_SR, 0x0047, UIF: B_0x1; CC1IF: B_0x1; CC2IF: 0b1; COMIF: B_0x0; TIF: B_0x1; BIF: B_0x0; CC1OF: B_0x0; CC2OF: 0b0
TIM15, TIM15_EGR, 0x0000, UG: -; CC1G: -; CC2G: -; COMG: B_0x0; TG: -; BG: -
TIM15, TIM15_CCMR1_Input, 0x00003000, CC1S: B_0x0; IC1PSC: B_0x0; IC1F: B_0x0; CC2S: B_0x0; IC2PSC: 0b00; IC2F: 0b0011
TIM15, TIM15_CCMR1_Output, 0x00003000, CC1S: B_0x0; OC1FE: B_0x0; OC1PE: B_0x0; OC1M1: B_0x0; OC1CE: B_0x0; CC2S: B_0x0; OC2FE: 0b0; OC2PE: 0b0; OC2M1: 0b011; OC2CE: 0b0; OC1M2: B_0x0; OC2M2: 0b0
TIM15, TIM15_CCER, 0x0010, CC1E: B_0x0; CC1P: B_0x0; CC1NE: B_0x0; CC1NP: B_0x0; CC2E: 0b1; CC2P: 0b0; CC2NP: 0b0
TIM15, TIM15_CNT, 0x00000000, CNT: 0b0000000000000000; UIFCPY: 0b0
TIM15, TIM15_PSC, 0x00F9, PSC: 0b0000000011111001
TIM15, TIM15_ARR, 0x00000031, ARR: 0b00000000000000110001
TIM15, TIM15_RCR, 0x0000, REP: 0b00000000
TIM15, TIM15_CCR1, 0x00000000, CCR1: 0b00000000000000000000
TIM15, TIM15_CCR2, 0x00000000, CCR2: 0b00000000000000000000
TIM15, TIM15_BDTR, 0x0000A000, DTG: 0b00000000; LOCK: B_0x0; OSSI: B_0x0; OSSR: B_0x0; BKE: B_0x0; BKP: B_0x1; AOE: B_0x0; MOE: B_0x1; BKF: B_0x0; BKDSRM: B_0x0; BKBID: B_0x0
TIM15, TIM15_DTR2, 0x00000000, DTGF: 0b00000000; DTAE: B_0x0; DTPE: B_0x0
TIM15, TIM15_TISEL, 0x00000000, TI1SEL: B_0x0; TI2SEL: B_0x0
TIM15, TIM15_AF1, 0x00000001, BKINE: B_0x1; BKCMP1E: B_0x0; BKCMP2E: B_0x0; BKCMP3E: B_0x0; BKCMP4E: B_0x0; BKCMP5E: B_0x0; BKCMP6E: B_0x0; BKCMP7E: B_0x0; BKCMP8E: B_0x0; BKINP: B_0x0; BKCMP1P: B_0x0; BKCMP2P: B_0x0; BKCMP3P: B_0x0; BKCMP4P: B_0x0
TIM15, TIM15_AF2, 0x00000000, OCRSEL: B_0x0
TIM15, TIM15_DCR, 0x00000000, DBA: B_0x0; DBL: B_0x0; DBSS: 0b0000
TIM15, TIM15_DMAR, 0x00000000, DMAB: 0b00000000000000000000000000000000
TIM2, TIM2_CR1, 0x0000, CEN: B_0x0; UDIS: B_0x0; URS: B_0x0; OPM: B_0x0; DIR: B_0x0; CMS: B_0x0; ARPE: B_0x0; CKD: B_0x0; UIFREMAP: B_0x0; DITHEN: B_0x0
TIM2, TIM2_CR2, 0x00000020, CCDS: B_0x0; MMS1: B_0x2; TI1S: B_0x0; MMS2: B_0x0
TIM2, TIM2_SMCR, 0x00000006, SMS1: B_0x6; OCCS: B_0x0; TS1: B_0x0; MSM: B_0x0; ETF: B_0x0; ETPS: B_0x0; ECE: B_0x0; ETP: B_0x0; SMS2: B_0x0; TS2: B_0x0; SMSPE: B_0x0; SMSPS: B_0x0
TIM2, TIM2_DIER, 0x00000008, UIE: B_0x0; CC1IE: B_0x0; CC2IE: B_0x0; CC3IE: B_0x1; CC4IE: B_0x0; TIE: B_0x0; UDE: B_0x0; CC1DE: B_0x0; CC2DE: B_0x0; CC3DE: B_0x0; CC4DE: B_0x0; TDE: B_0x0; IDXIE: B_0x0; DIRIE: B_0x0; IERRIE: B_0x0; TERRIE: B_0x0
TIM2, TIM2_SR, 0x00000000, UIF: B_0x0; CC1IF: B_0x0; CC2IF: 0b0; CC3IF: 0b0; CC4IF: 0b0; TIF: B_0x0; CC1OF: B_0x0; CC2OF: 0b0; CC3OF: 0b0; CC4OF: 0b0; IDXF: B_0x0; DIRF: B_0x0; IERRF: B_0x0; TERRF: B_0x0
TIM2, TIM2_EGR, 0x0000, UG: -; CC1G: -; CC2G: -; CC3G: -; CC4G: -; TG: -
TIM2, TIM2_CCMR1_Input, 0x00000000, CC1S: B_0x0; IC1PSC: B_0x0; IC1F: B_0x0; CC2S: B_0x0; IC2PSC: 0b00; IC2F: 0b0000
TIM2, TIM2_CCMR1_Output, 0x00000000, CC1S: B_0x0; OC1FE: B_0x0; OC1PE: B_0x0; OC1M1: B_0x0; OC1CE: B_0x0; CC2S: B_0x0; OC2FE: 0b0; OC2PE: 0b0; OC2M1: 0b000; OC2CE: 0b0; OC1M2: B_0x0; OC2M2: 0b0
TIM2, TIM2_CCMR2_Input, 0x00000030, CC3S: B_0x0; IC3PSC: 0b00; IC3F: 0b0011; CC4S: B_0x0; IC4PSC: 0b00; IC4F: 0b0000
TIM2, TIM2_CCMR2_Output, 0x00000030, CC3S: B_0x0; OC3FE: 0b0; OC3PE: 0b0; OC3M1: 0b011; OC3CE: 0b0; CC4S: B_0x0; OC4FE: 0b0; OC4PE: 0b0; OC4M1: 0b000; OC4CE: 0b0; OC3M2: 0b0; OC4M2: 0b0
TIM2, TIM2_CCER, 0x0100, CC1E: B_0x0; CC1P: B_0x0; CC1NP: 0b0; CC2E: 0b0; CC2P: 0b0; CC2NP: 0b0; CC3E: 0b1; CC3P: 0b0; CC3NP: 0b0; CC4E: 0b0; CC4P: 0b0; CC4NP: 0b0
TIM2, TIM2_CNT, 0x00000000, CNT: 0b00000000000000000000000000000000
TIM2, TIM2_PSC, 0x00F9, PSC: 0b0000000011111001
TIM2, TIM2_ARR, 0x00000031, ARR: 0b00000000000000000000000000110001
TIM2, TIM2_CCR1, 0x00000000, CCR1: 0b00000000000000000000000000000000
TIM2, TIM2_CCR2, 0x00000000, CCR2: 0b00000000000000000000000000000000
TIM2, TIM2_CCR3, 0x00000000, CCR3: 0b00000000000000000000000000000000
TIM2, TIM2_CCR4, 0x00000000, CCR4: 0b00000000000000000000000000000000
TIM2, TIM2_ECR, 0x00000000, IE: B_0x0; IDIR: B_0x0; IBLK: B_0x0; FIDX: B_0x0; IPOS: B_0x0; PW: 0b00000000; PWPRSC: 0b000
TIM2, TIM2_TISEL, 0x00000000, TI1SEL: B_0x0; TI2SEL: B_0x0; TI3SEL: B_0x0; TI4SEL: B_0x0
TIM2, TIM2_AF1, 0x00000000, ETRSEL: B_0x0
TIM2, TIM2_AF2, 0x00000000, OCRSEL: B_0x0
TIM2, TIM2_DCR, 0x00000000, DBA: B_0x0; DBL: B_0x0; DBSS: 0b0000
TIM2, TIM2_DMAR, 0x00000000, DMAB: 0b00000000000000000000000000000000

AHame
Associate III

Register dump is marked as spam when copied directly.... here it is in a file hopefully this bypass the spam filter :


TDK
Guru

Analog capture would be insightful. Difference capacitance on lines may be affecting the rise times.

Do falling edges follow the same pattern? Does the second rising edge follow the same pattern? Are all timer output pins set to very high frequency?

There can be small delays between when a master timer starts and the slaves start. This can be overcome by setting CNT values of the master a few counts behind the slaves. There are some other synchronization settings as well. Curiously, your slave timer channel goes high before the master timer channel does, so I don't think that's the culprit here.

 

If you feel a post has answered your question, please click "Accept as Solution".
AHame
Associate III

@TDK Thanks for the great suggestion of doing an analog capture. I somehow got too deep in the digital troubleshooting and forgot to look for potential analog problems.

Here is the analog capture. As you can see it has the same kind of behavior. I did make sure that the alternate functions pins for output compare where set to very high frequency. Didn't make any difference probably because those three pins I use for Timer output compare are not connected to anything except the high input impedance of the logic analyzer.

AHame_0-1721136043231.png


That however gave me an idea and looking at the chip pinout I realized that TIM5 output compare channel 2 is also accessible on the same pin I used for TIM15. This allowed me to do another test but with Tim2 and Tim5 configured as slave this time with exactly the same probing setup.

Interestingly Tim2 and Tim5 are way more in sync as you can see below. Is it possible that since Tim2 and Tim15 are not on the same APB bus that is why I get this weird synchronization issue?Tim15 is also a timer with dead time and break support so maybe there is something to it?

AHame_1-1721136993766.png


That being said I'm still puzzled as you are as to why Tim15 output compare channel is going up before the timer 1 output compare channel. 

I really need to use TIM15 or TIM12 because other timers are not available as an input trigger for the DMA operations I need. That made me look at using TIM12 and indeed it is also way more in synch. So everything leads to it being a problem with TIM15 but I am not sure why.

 

AHame_2-1721137799100.png

AHame_3-1721137942817.png

 

TDK
Guru

Still looks like it could be a rise time issue. TIM1 is fastest, and overshoots, so the edge happens there first. TIM2 by comparison is much slower, no overshoot. Analog capture speed isn't quite high enough to say with certainty.

They all start going high at about the same time. Just takes longer for some channels to hit the threshold.

TDK_0-1721145462677.png

Could be a scope channel issue, but unlikely. Swap channels to eliminate that possibility.

There can be subtle timing differences between master/slave and timers not on the same bus. Changing the starting CNT value can shift things with the resolution of one timer tick.

If you feel a post has answered your question, please click "Accept as Solution".
AHame
Associate III

I see what you mean on my latest experiments but on the example with TIM1, TIM2 and TIM15 which was my original question even in analog mode you can see that TIM15 seem to really start before TIM1 which is still odd

AHame_4-1721146106155.png


I'll try with a scope later today and report back to see if the logic analyzer slower sampling rate could be the issue