AnsweredAssumed Answered

TIM4 CH3, CH2, CH1 now working

Question asked by gogohia.levan on Jul 29, 2013
Latest reply on Oct 5, 2013 by Clive One
help again, I work with a four-timer but it does not work the channels one, two and three. I initialize them but they do not give a PWM.
CH4 working very good!
My code:

void init_pwm( void)
{
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure2;
    TIM_OCInitTypeDef       TIM_OCInitStructure;
    GPIO_InitTypeDef         GPIO_InitStructure;


    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);


    GPIO_InitStructure. GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
    GPIO_InitStructure. GPIO_Mode = GPIO_Mode_AF ;
    GPIO_InitStructure. GPIO_Speed = GPIO_Speed_50MHz ;
    GPIO_InitStructure. GPIO_OType = GPIO_OType_PP ;
    GPIO_InitStructure. GPIO_PuPd = GPIO_PuPd_UP ;
    GPIO_Init(GPIOD, &GPIO_InitStructure);


    GPIO_PinAFConfig(GPIOD, GPIO_PinSource12, GPIO_AF_2);
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource13, GPIO_AF_2);
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource14, GPIO_AF_2);
    GPIO_PinAFConfig(GPIOD, GPIO_PinSource15, GPIO_AF_2);


    TIM_TimeBaseStructure2. TIM_Period = 19999;
    TIM_TimeBaseStructure2. TIM_Prescaler = 72-1;
    TIM_TimeBaseStructure2. TIM_ClockDivision = 0;
    TIM_TimeBaseStructure2. TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure2);


    TIM_OCInitStructure. TIM_OCMode = TIM_OCMode_PWM1;
    TIM_OCInitStructure. TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure. TIM_Pulse = START;
    TIM_OCInitStructure. TIM_OCPolarity = TIM_OCPolarity_High;


    TIM_OC1Init(TIM4, &TIM_OCInitStructure);
    TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Disable);


    TIM_OCInitStructure. TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure. TIM_Pulse = START;


    TIM_OC2Init(TIM4, &TIM_OCInitStructure);
    TIM_OC2PreloadConfig(TIM4, TIM_OCPreload_Disable);


    TIM_OCInitStructure. TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure. TIM_Pulse = START;


    TIM_OC3Init(TIM4, &TIM_OCInitStructure);
    TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Disable);


    TIM_OCInitStructure. TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure. TIM_Pulse = START;


    TIM_OC4Init(TIM4, &TIM_OCInitStructure);
    TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Disable);


    TIM_Cmd(TIM4, ENABLE);
}

Outcomes