Skip to main content
brandonchan2001
Visitor II
April 7, 2011
Question

Changing duty cycle for TIM8

  • April 7, 2011
  • 1 reply
  • 698 views
Posted on April 08, 2011 at 00:20

Changing duty cycle for TIM8

    This topic has been closed for replies.

    1 reply

    mehmet.karakaya
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 14:30

    void PWMinit(void){

      /* Time Base configuration */

      TIM_TimeBaseStructure.TIM_Prescaler = 0;

      TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

      TIM_TimeBaseStructure.TIM_Period = 7200;

      TIM_TimeBaseStructure.TIM_ClockDivision = 0;

      TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

      TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);

      /* Channel 1, 2,3 and 4 Configuration in PWM mode */

      TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;

      TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

      TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;

      TIM_OCInitStructure.TIM_Pulse = 200;

      TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

      TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;

      TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;

      TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;

      TIM_OC1Init(TIM8, &TIM_OCInitStructure);

      TIM_OC2Init(TIM8, &TIM_OCInitStructure);

      TIM_OC3Init(TIM8, &TIM_OCInitStructure);

      

      TIM_CCPreloadControl(TIM8, DISABLE);

      /* TIM1 counter enable */

      TIM_Cmd(TIM8, ENABLE);

      /* Main Output Enable */

      TIM_CtrlPWMOutputs(TIM8, ENABLE);

    --------------

    and in the main loop

            TIM8->CCR1= 500;

    ------------------

    this code is working with my application

    I looked at the supplied example code that uses the TIM3 timer and was able to change the TIM->CCR1 register inside a while loop in order to change the PWM duty cycle while the MCU is running. However, when I tried to do the same with TIM8, the duty cycle seems to stay constant at the initial TIM->CCR1 value that it was initialized with (duty cycle remains constant). Are there special conditions for TIM8 that I should be aware of when dealing with TIM8 specifically?

    Any help would be greatly appreciated thanks!