Page 1 of 1

Change PWM duty cycle

Posted: Wed Mar 02, 2016 11:33 am
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

Re: Change PWM duty cycle

Posted: Wed Mar 02, 2016 11:46 am
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

Re: Change PWM duty cycle

Posted: Wed Mar 02, 2016 1:27 pm
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

Re: Change PWM duty cycle

Posted: Thu Mar 03, 2016 4:29 pm
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