Change PWM duty cycle

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Stephane
Posts: 13
Joined: Tue Aug 26, 2014 3:41 pm
Has thanked: 2 times
Been thanked: 2 times

Change PWM duty cycle

Post by Stephane »

Hello,

I have a small module that uses two channels on the PWM5.
I would like to be able to modify the duty cycle of one of these two channels.

My problem is that when i modify the duty cycle of one channel, the second channel is resetted.

To modify the duty cycle, i use the function pwmEnableChannel.
I think it is the culprit that disable the second PWM.

Is there another function under Chibios to change the duty cycle without interfering with another channel ?
Or do i have to play with the TIM5_CCRx registers ?

Thank you in advance.

Stephane
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Change PWM duty cycle

Post by Giovanni »

Hi,

pwmEnableChannel() only touches the CCR register, this should not happen but it happens because a stupid bug in this code...

I imagine you are using an STM32F3, correct?

Code: Select all

void pwm_lld_enable_channel(PWMDriver *pwmp,
                            pwmchannel_t channel,
                            pwmcnt_t width) {

  /* Changing channel duty cycle on the fly.*/
#if STM32_TIM_MAX_CHANNELS <= 4
  pwmp->tim->CCR[channel] = width;
#else
  if (channel <= 4)
    pwmp->tim->CCR[channel] = width;
  else
    pwmp->tim->CCXR[channel - 4] = width;
#endif
}


Opened a ticket: https://sourceforge.net/p/chibios/bugs/722/
Will be fixed in 16.1.4 (next weekend).

Giovanni
Stephane
Posts: 13
Joined: Tue Aug 26, 2014 3:41 pm
Has thanked: 2 times
Been thanked: 2 times

Re: Change PWM duty cycle

Post by Stephane »

Hi,

You are very impressive: very fast answer and correct guess.

(Sorry, i forgotten to specify that i am using a STM32F373)

Thanks a lot for your help !

Stéphane
Stephane
Posts: 13
Joined: Tue Aug 26, 2014 3:41 pm
Has thanked: 2 times
Been thanked: 2 times

Re: Change PWM duty cycle

Post by Stephane »

Hello again,

I have to confess that i found a misplaced pwmStart() on my code...

On my case, with Chibios 3.0.0, the pwmEnableChannel() routine seems to work correctly.

With best regards,

Stéphane
Post Reply