AnsweredAssumed Answered

STM32F4 Two Complementary PWM Outputs does not have the same frequency

Question asked by pham.minh on Jan 21, 2015
Latest reply on Jan 22, 2015 by pham.minh
Have anyone ever had trouble when updating frequency can cause the two complementary pwm outputs not have the same frequency?

I'm using STM32F407VGT6 Discovery, controlling the PWM frequency.

01.static void TIM1_Configuration(void)
02.{
03.    /* Time Base configuration */
04.    TIM_TimeBaseStructure.TIM_Prescaler          = 0;
05.    TIM_TimeBaseStructure.TIM_CounterMode        = TIM_CounterMode_CenterAligned1;
06.    TIM_TimeBaseStructure.TIM_Period             = Timer_Period;
07.    TIM_TimeBaseStructure.TIM_RepetitionCounter  = 0; // update event is generated at each counter overflow
08.    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
09.    TIM1->EGR = TIM_PSCReloadMode_Update;
10.    TIM1->CR1 |= TIM_CR1_URS;
11.    TIM1->CR1 &= (uint16_t)~TIM_OPMode_Single;
12. 
13.    /* Channel 1, 3 Configuration in PWM mode */
14.    TIM_OCInitStructure.TIM_OCMode       = TIM_OCMode_PWM2;
15.    TIM_OCInitStructure.TIM_OutputState  = TIM_OutputState_Enable; //Co the dung 2 lenh nay de ngat xung
16.    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
17.    TIM_OCInitStructure.TIM_Pulse        = Channel_Pulse;
18.    TIM_OCInitStructure.TIM_OCPolarity   = TIM_OCPolarity_High;  //Khong lien quan den trang thai sau khi ngat xung
19.    TIM_OCInitStructure.TIM_OCNPolarity  = TIM_OCNPolarity_High; //Khong lien quan den trang thai sau khi ngat xung
20.    TIM_OCInitStructure.TIM_OCIdleState  = TIM_OCIdleState_Reset;
21.    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
22.    TIM_OC1PreloadConfig(TIM1, TIM_CCMR1_OC1PE);
23.    TIM_OC1Init(TIM1, &TIM_OCInitStructure);
24.    TIM1->CR1 |= TIM_CR1_ARPE; // Set the ARR Preload Bit
25. 
26.    /* Automatic Output enable, Break, dead time and lock configuration*/
27.    TIM_BDTRInitStructure.TIM_OSSRState  = TIM_OSSRState_Disable;
28.    TIM_BDTRInitStructure.TIM_OSSIState  = TIM_OSSIState_Disable;
29.    TIM_BDTRInitStructure.TIM_LOCKLevel  = TIM_LOCKLevel_OFF;
30.    TIM_BDTRInitStructure.TIM_DeadTime   = 0;
31.    TIM_BDTRInitStructure.TIM_Break      = TIM_Break_Disable;
32.    TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;
33.    TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
34. 
35.    /* TIM1 counter enable */
36.    TIM_Cmd(TIM1, ENABLE);//1Tcy
37. 
38.    /* Main Output Enable */
39.    TIM_CtrlPWMOutputs(TIM1, ENABLE);
40.}
41. 
42.void TIM1_PWM_Freq_Update(void)
43.{
44.    TIM1->CR1 |= TIM_CR1_UDIS;
45. 
46.    TIM1->ARR    = Timer_Period;
47. 
48.    TIM1->CR1 &= (uint16_t)~TIM_CR1_UDIS;
49.}



fsthfdg.gif

Outcomes