Page 1 of 1

PWM dutycycle is not working as expected

Posted: Mon Jan 06, 2020 8:35 pm
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 :)

Re: PWM dutycycle is not working as expected

Posted: Mon Jan 06, 2020 8:37 pm
by Giovanni
Perhaps the output should be active low, how is connected the LED?

Giovanni

Re: PWM dutycycle is not working as expected

Posted: Tue Jan 07, 2020 7:48 am
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.

Re: PWM dutycycle is not working as expected

Posted: Tue Jan 07, 2020 8:26 am
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

Re: PWM dutycycle is not working as expected

Posted: Tue Jan 07, 2020 9:53 am
by Aravinth
Thanks...
I will let you know if I test the pins with oscilloscope.

Re: PWM dutycycle is not working as expected

Posted: Wed Jan 08, 2020 10:45 pm
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