AnsweredAssumed Answered

[STM32F429i]PWM problem on few timers/channels

Question asked by majeran.michal on Jun 17, 2014
Latest reply on Jun 19, 2014 by Clive One
Hello everyone. I am creating a hexapod with 18 independent servos, using 18 channels on General - Purpose timers. I have problem with few timers, simply servo is not responding to new compare value. I am using timers:
TIM2 - 4 channels working
TIM3 - 4 channels working
TIM4 - 4 channels working
TIM5 - chanel 2 and 3 not working
TIM12 - not working
Do I have some conflicts with alternative configuration ? My init for timers/pwm:

001.void initTimer()
002.{
003.    RCC_TIMCLKPresConfig(RCC_TIMPrescActivated);
004. 
005.    /* TIM2 clock enable */
006.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
007. 
008.    /* TIM3 clock enable */
009.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
010. 
011.    /* TIM4 clock enable */
012.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
013. 
014.    /* TIM5 clock enable */
015.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
016. 
017.    /* TIM12 clock enable */
018.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM12, ENABLE);
019. 
020.    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
021. 
022.    /* Compute the prescaler value */
023.    uint16_t u16PrescalerValue = (uint16_t) ((SystemCoreClock) / 1000000)- 1;
024.    TIM_TimeBaseStructure.TIM_Prescaler = u16PrescalerValue; // 1MHz
025.    TIM_TimeBaseStructure.TIM_Period = 20000 - 1; // 1 MHz / 20000 = 50 Hz (20ms)
026.    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
027.    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
028. 
029.    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
030.    TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
031.    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
032.    TIM_TimeBaseInit(TIM5, &TIM_TimeBaseStructure);
033.    TIM_TimeBaseInit(TIM12, &TIM_TimeBaseStructure);
034.}
035. 
036.void initPWM()
037.{
038.    /*
039.     * Servo min(1ms)       = 1000
040.     * Servo neutral (1,5ms) = 1500
041.     * Servo max(2ms)       = 2000
042.     *
043.     */
044. 
045.    TIM_OCInitTypeDef TIM_OCInitStructure;
046. 
047.    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
048.    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
049.    TIM_OCInitStructure.TIM_Pulse = 0;
050.    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
051. 
052.    /*********************TIM2**************************/
053.    /* PWM1 Mode configuration: Channel1 (GPIOA Pin 15)*/
054.    TIM_OC1Init(TIM2, &TIM_OCInitStructure);
055.    TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable );
056. 
057.    /* PWM1 Mode configuration: Channel2 (GPIOB Pin 3)*/
058.    TIM_OC2Init(TIM2, &TIM_OCInitStructure);
059.    TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable );
060. 
061.    /* PWM1 Mode configuration: Channel3 (GPIOB Pin 10)*/
062.    TIM_OC3Init(TIM2, &TIM_OCInitStructure);
063.    TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable );
064. 
065.    /* PWM1 Mode configuration: Channel4 (GPIOB Pin 11)*/
066.    TIM_OC4Init(TIM2, &TIM_OCInitStructure);
067.    TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Enable );
068. 
069.    /*********************TIM3**************************/
070.    /* PWM1 Mode configuration: Channel1 (GPIOB Pin 4)*/
071.    TIM_OC1Init(TIM3, &TIM_OCInitStructure);
072.    TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable );
073. 
074.    /* PWM1 Mode configuration: Channel2 (GPIOB Pin 5)*/
075.    TIM_OC2Init(TIM3, &TIM_OCInitStructure);
076.    TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable );
077. 
078.    /* PWM1 Mode configuration: Channel3 (GPIOB Pin 0)*/
079.    TIM_OC3Init(TIM3, &TIM_OCInitStructure);
080.    TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable );
081. 
082.    /* PWM1 Mode configuration: Channel4 (GPIOB Pin 1)*/
083.    TIM_OC4Init(TIM3, &TIM_OCInitStructure);
084.    TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable );
085. 
086.    /*********************TIM4**************************/
087.    /* PWM1 Mode configuration: Channel1 (GPIOD Pin 12)*/
088.    TIM_OC1Init(TIM4, &TIM_OCInitStructure);
089.    TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable );
090. 
091.    /* PWM1 Mode configuration: Channel2 (GPIOD Pin 13)*/
092.    TIM_OC2Init(TIM4, &TIM_OCInitStructure);
093.    TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable );
094. 
095.    /* PWM1 Mode configuration: Channel3 (GPIOD Pin 14)*/
096.    TIM_OC3Init(TIM4, &TIM_OCInitStructure);
097.    TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable );
098. 
099.    /* PWM1 Mode configuration: Channel4 (GPIOD Pin 15)*/
100.    TIM_OC4Init(TIM4, &TIM_OCInitStructure);
101.    TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable );
102. 
103.    /*********************TIM5**************************/
104.    /* PWM1 Mode configuration: Channel1 (GPIOA Pin 0)*/
105.    TIM_OC1Init(TIM5, &TIM_OCInitStructure);
106.    TIM_OC1PreloadConfig(TIM5, TIM_OCPreload_Enable );
107. 
108.    /* PWM1 Mode configuration: Channel2 (GPIOA Pin 1)*/
109.    TIM_OC2Init(TIM5, &TIM_OCInitStructure);
110.    TIM_OC2PreloadConfig(TIM5, TIM_OCPreload_Enable );
111. 
112.    /* PWM1 Mode configuration: Channel3 (GPIOA Pin 2)*/
113.    TIM_OC3Init(TIM5, &TIM_OCInitStructure);
114.    TIM_OC3PreloadConfig(TIM5, TIM_OCPreload_Enable );
115. 
116.    /* PWM1 Mode configuration: Channel4 (GPIOA Pin 3)*/
117.    TIM_OC4Init(TIM5, &TIM_OCInitStructure);
118.    TIM_OC4PreloadConfig(TIM5, TIM_OCPreload_Enable );
119. 
120.    /*********************TIM12*************************/
121.    /* PWM1 Mode configuration: Channel1 (GPIOB Pin 14)*/
122.    TIM_OC1Init(TIM12, &TIM_OCInitStructure);
123.    TIM_OC1PreloadConfig(TIM12, TIM_OCPreload_Enable );
124. 
125.    /* PWM1 Mode configuration: Channel2 (GPIOB Pin 15)*/
126.    TIM_OC2Init(TIM12, &TIM_OCInitStructure);
127.    TIM_OC2PreloadConfig(TIM12, TIM_OCPreload_Enable );
128. 
129.    /*********************TIM9*************************/
130.    /* PWM1 Mode configuration: Channel1 (GPIOE Pin 5)*/
131.    TIM_OC1Init(TIM9, &TIM_OCInitStructure);
132.    TIM_OC1PreloadConfig(TIM9, TIM_OCPreload_Enable );
133. 
134.    /* PWM1 Mode configuration: Channel2 (GPIOE Pin 6)*/
135.    TIM_OC2Init(TIM9, &TIM_OCInitStructure);
136.    TIM_OC2PreloadConfig(TIM9, TIM_OCPreload_Enable );
137. 
138.    //enable timers
139.    TIM_Cmd(TIM2,  ENABLE);
140.    TIM_Cmd(TIM3,  ENABLE);
141.    TIM_Cmd(TIM4,  ENABLE);
142.    TIM_Cmd(TIM5,  ENABLE);
143.    TIM_Cmd(TIM9,  ENABLE);
144.    TIM_Cmd(TIM12, ENABLE);
145.}
146. 
147.void initServos()
148.{
149.    GPIO_InitTypeDef GPIO_PWM;
150. 
151.    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
152.    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
153.    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
154.    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);
155. 
156.    GPIO_PWM.GPIO_Mode = GPIO_Mode_AF;
157.    GPIO_PWM.GPIO_Speed = GPIO_Speed_100MHz;
158.    GPIO_PWM.GPIO_OType = GPIO_OType_PP;
159.    GPIO_PWM.GPIO_PuPd = GPIO_PuPd_UP;
160. 
161.    //PORT A
162.    GPIO_PWM.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_15;
163.    GPIO_Init(GPIOA, &GPIO_PWM);
164. 
165.    GPIO_PinAFConfig(GPIOA, GPIO_PinSource0, GPIO_AF_TIM5 );
166.    GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM5 );
167.    GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM5 );
168.    GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_TIM5 );
169.    GPIO_PinAFConfig(GPIOA, GPIO_PinSource15,GPIO_AF_TIM2 );
170. 
171.    //PORT B
172.    GPIO_PWM.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_14 | GPIO_Pin_15;
173.    GPIO_Init(GPIOB, &GPIO_PWM);
174. 
175.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource0, GPIO_AF_TIM3 );
176.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource1, GPIO_AF_TIM3 );
177.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_TIM2 );
178.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_TIM3 );
179.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_TIM3 );
180.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource10,GPIO_AF_TIM2 );
181.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource11,GPIO_AF_TIM2 );
182.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource14,GPIO_AF_TIM12 );
183.    GPIO_PinAFConfig(GPIOB, GPIO_PinSource15,GPIO_AF_TIM12 );
184. 
185.    //PORT D
186.    GPIO_PWM.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
187.    GPIO_Init(GPIOD, &GPIO_PWM);
188. 
189.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_TIM4 );
190.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_TIM4 );
191.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_TIM4 );
192.    GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_TIM4 );
193. 
194. 
195.}
 

 

Outcomes