PWM dutycycle is not working as expected

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
Aravinth
Posts: 4
Joined: Mon Jan 06, 2020 8:15 pm

PWM dutycycle is not working as expected

Post by Aravinth »

Hi, I've been playing around with my nucleo f446ze board for quite some time.. I came across a weird problem, while setting my dutycycle to 75% the on-board led behaves as if its set at 25% dutycycle (its dimmer)
And when I set my dutycycle to 25% the led behaves like its set at 75% dutycycle ( its brighter)

PWM duty cycle 25% - LED brightness 75%
PWM duty cycle 75% - LED brightness 25%

I've listed my config below.. Can you please explain whats is wrong or is it supposed to work like this.

Code: Select all

static PWMConfig pwmcfg = {
  100000,                                   
  1000,                                   
  pwmpcb,
  {
   {PWM_OUTPUT_ACTIVE_HIGH, pwmc1cb},
   {PWM_OUTPUT_DISABLED, NULL},
   {PWM_OUTPUT_DISABLED, NULL},
   {PWM_OUTPUT_DISABLED, NULL}
  },
 
   pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 2500));
 


Thanks in Advance :)
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PWM dutycycle is not working as expected

Post by Giovanni »

Perhaps the output should be active low, how is connected the LED?

Giovanni
Aravinth
Posts: 4
Joined: Mon Jan 06, 2020 8:15 pm

Re: PWM dutycycle is not working as expected

Post by Aravinth »

User LD2: a blue user LED is connected to PB7.
These user LEDs are on when the I/O is HIGH value, and are off when the I/O is LOW.

I've even tried with {PWM_OUTPUT_ACTIVE_LOW, pwmc1cb} still the same response.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PWM dutycycle is not working as expected

Post by Giovanni »

Is the pin programmed with the right alternate mode? also enable assertions, those can catch invalid settings in the driver (you need to specify frequencies that can be physically obtained using the timer divider).

Anyway, you need to look at that pin using an oscilloscope so we can understand the problem.

Giovanni
Aravinth
Posts: 4
Joined: Mon Jan 06, 2020 8:15 pm

Re: PWM dutycycle is not working as expected

Post by Aravinth »

Thanks...
I will let you know if I test the pins with oscilloscope.
Aravinth
Posts: 4
Joined: Mon Jan 06, 2020 8:15 pm

Re: PWM dutycycle is not working as expected

Post by Aravinth »

Hello..Thanks , My issues has been resolved. Previously I didnt set correct alternate function
I've been using callback to switch gpio pin.. Didnt knew back then :P
Now I have hooked up an external LED on one of the gpio pins and used with alternate function, Works great.

Credits to Rocco Marco Guglielmi also helped me figure out this issue. LINK: https://www.playembedded.org/blog/stm32 ... omment-371
Post Reply