2014-04-29 02:05 PM
Greetings,
I have a project running with the STM32F205RCT6 and currently have PWM running according to the following configurations: TIM1 -- Channel 1 - GPIOA-8 TIM1 -- Channel 2 - GPIOA-9 TIM1 -- Channel 3 - GPIOA-10 TIM3 -- Channel 1 - GPIOA - 6 TIM3 -- Channel 2 - GPIOA - 7 My application requires 2 additional PWM channels in conjunction with the ones above and I am not able to get the following to work: TIM4 -- Channel 1 - GPIOB - 14 TIM4 -- Channel 2 - GPIOB - 8 The timer appears to be running but the output pin does not appear to be properly mapped to the timer output. Here's the code I'm using to setup TIM4:static void TIM_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
uint16_t preloadValue = 0;
/* TIM4 clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
/* GPIOB clock enable */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
/* GPIOB Configuration: TIM4 CH1 (PB14) CH2 (PB8) */
GPIO_StructInit(&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Connect TIM4 pins to AF */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_TIM4);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_TIM4);
/* Compute the prescaler value */
preloadValue = (uint16_t) ((SystemCoreClock /2) / 32000) - 1;
/* Time base configuration */
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Period = preloadValue;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_ARRPreloadConfig(TIM4, ENABLE);
/* PWM1 Mode configuration: Channel1 */
TIM_OCStructInit(&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 100; // Constant plugged in just for testing
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM4, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
/* PWM1 Mode configuration: Channel2 */
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 100; // Constant plugged in just for testing
TIM_OC2Init(TIM4, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Enable);
/* TIM4 enable counter */
TIM_Cmd(TIM4, ENABLE);
}
I have tried using other timers (with the exception of TIM8) to no avail.
I appreciate any insight.
Thanks in advance,
Michael A. Dupont
#pwm #tim4 #stm32f2xx
2014-04-29 02:14 PM
My application requires 2 additional PWM channels in conjunction with the ones above and I am not able to get the following to work:
TIM4 -- Channel 1 - GPIOB - 14
TIM4 -- Channel 2 - GPIOB - 8
Unfortunately you are inventing connectivity, PB8 is TIM4_CH3, PB14 has no association with TIM4. Refer to the part's Data Manual
2014-04-29 02:19 PM
Thanks, Clive1.
Yeah, I figured it was something like that. I'm coming from a different processor universe and having to get used to the conventions. Best regards, Michael A. Dupont2014-04-29 02:33 PM
Clive1, quick status and thanks,
All is working. Thanks for your quick response. M.Dupont