AnsweredAssumed Answered

Syncing PWM/Timer's on STM32f205rb

Question asked by bandholm.mikkel.001 on Aug 30, 2012
Latest reply on Aug 30, 2012 by Clive One
Hi Please help me with synching 4 timers
I need 4 PWM from 4 different timers to sync it's output so that i get this result:

 ________________                ________________               
_|                    |____________|                    |___________     TIM9_CH1
 ________________                ________________               
_|                    |____________|                    |___________     TIM1_CH1
 ________________                ________________               
_|                    |____________|                    |___________     TIM8_CH1
 ________________                ________________               
_|                    |____________|                    |___________     TIM10_CH1


I have tried to look in the examples but can not find on suitable, i need the PWM to run at 70kHz.




My setup is as follows




     RCC_AHB1PeriphClockCmd(     RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC                                   , ENABLE);
     RCC_APB2PeriphClockCmd(     RCC_APB2Periph_TIM1  | RCC_APB2Periph_TIM9  | RCC_APB2Periph_TIM8 | RCC_APB2Periph_TIM10     , ENABLE);




     /* ==============================  TIMER 1(PWM) ==============================  */


     /*PWM GPIO Configuration */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_8;
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
     GPIO_Init(GPIOA, &GPIO_InitStructure);


     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
     GPIO_Init(GPIOB, &GPIO_InitStructure);


     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
     GPIO_Init(GPIOC, &GPIO_InitStructure);


     /* Time base configuration */
     TIM_TimeBaseStructure.TIM_Period = 1710;
     TIM_TimeBaseStructure.TIM_Prescaler = 0;
     TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
     TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
     TIM_TimeBaseInit(PWMTIMER1, &TIM_TimeBaseStructure);
     TIM_TimeBaseInit(PWMTIMER2, &TIM_TimeBaseStructure);
     TIM_TimeBaseInit(PWMTIMER3, &TIM_TimeBaseStructure);
     TIM_TimeBaseInit(PWMTIMER4, &TIM_TimeBaseStructure);
     //TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_;
     //TIM_TimeBaseInit(TIM11, &TIM_TimeBaseStructure);


     /* PWM1 Mode configuration: Channel 1 */
     TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
     TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
     TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
     TIM_OCInitStructure.TIM_Pulse = 0;
     TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;




     TIM_OC1Init(PWMTIMER1, &TIM_OCInitStructure);
     TIM_OC1PreloadConfig(PWMTIMER1, TIM_OCPreload_Enable);


     /* PWM1 Mode configuration: Channel 2 */
     TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
     TIM_OCInitStructure.TIM_Pulse = 0;
     TIM_OC1Init(PWMTIMER2, &TIM_OCInitStructure);
     TIM_OC1PreloadConfig(PWMTIMER2, TIM_OCPreload_Enable);


     /* PWM1 Mode configuration: Channel 3 */
     TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
     TIM_OCInitStructure.TIM_Pulse = 0;
     TIM_OC1Init(PWMTIMER3, &TIM_OCInitStructure);
     TIM_OC1PreloadConfig(PWMTIMER3, TIM_OCPreload_Enable);
     
     
     //     /* PWM1 Mode configuration: Channel 4*/
     TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
     TIM_OCInitStructure.TIM_Pulse = 0;
     TIM_OC1Init(PWMTIMER4, &TIM_OCInitStructure);
     TIM_OC1PreloadConfig(PWMTIMER4, TIM_OCPreload_Enable);


     GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM9);
     GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_TIM1);
     GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_TIM10);
     GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_TIM8);


     /* Enable Auto Reload Register Preload */
     TIM_ARRPreloadConfig(PWMTIMER1, ENABLE);
     TIM_CtrlPWMOutputs(PWMTIMER1, ENABLE);


     /* Enable Auto Reload Register Preload */
     TIM_ARRPreloadConfig(PWMTIMER2, ENABLE);
     TIM_CtrlPWMOutputs(PWMTIMER2, ENABLE);


     /* Enable Auto Reload Register Preload */
     TIM_ARRPreloadConfig(PWMTIMER3, ENABLE);
     TIM_CtrlPWMOutputs(PWMTIMER3, ENABLE);


     /* Enable Auto Reload Register Preload */
     TIM_ARRPreloadConfig(PWMTIMER4, ENABLE);
     TIM_CtrlPWMOutputs(PWMTIMER4, ENABLE);


         
     TIM_Cmd(PWMTIMER1, ENABLE);               
     TIM_Cmd(PWMTIMER2, ENABLE);               
     TIM_Cmd(PWMTIMER3, ENABLE);               
     TIM_Cmd(PWMTIMER4, ENABLE);               
     
     

Outcomes