AnsweredAssumed Answered

How to Update Timer period ???

Question asked by Kallberg.Mikael on Jul 23, 2011
Latest reply on Jul 24, 2011 by Kallberg.Mikael
I have tried to update Timer 2 with new period value without any good resualt.

I use two channels on Timer 2 as PWM outputs,
The PWM works fine, But when i tries to update the period value in timer 2 the PWM signals disappears.

sometimes i manage to update the timer with a period value that is larger then the one before. but never a smaller value.

please i really would like some help with this one. i have tried this for to long now.

My update code so far.

    /* Time Base configuration */
    TIM_TimeBaseStructure.TIM_Period = 1000;
    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
    TIM_ClearFlag(TIM2, TIM_FLAG_CC3);

    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
    TIM_OCInitStructure.TIM_Pulse =  500;
    TIM_OC3Init(TIM2, &TIM_OCInitStructure);





And the Timer initilize code

    // Timer clock
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_AFIO, ENABLE);
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

    /* Time Base configuration */
    TIM_TimeBaseStructure.TIM_Period = 2000;
    TIM_TimeBaseStructure.TIM_Prescaler = 0;
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
   
    TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
 
    /* PWM1 Mode configuration: Channel1 */
    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure.TIM_Pulse = 1000;
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

    TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
    TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
 
    // Motor A channel
    TIM_OC2Init(TIM2, &TIM_OCInitStructure);
    TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);
    // Motor B channel
    TIM_OC3Init(TIM2, &TIM_OCInitStructure);
    TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);

    TIM_ARRPreloadConfig(TIM2, ENABLE);
 
    /* TIM1 enable counter */
    TIM_Cmd(TIM2, ENABLE);

    /* TIM1 Main Output Enable */
    TIM_CtrlPWMOutputs(TIM2, ENABLE);

Outcomes