PWM behaviour for 0% and 100% Topic is solved

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
sdalu
Posts: 35
Joined: Wed Dec 30, 2015 5:31 pm
Has thanked: 1 time
Been thanked: 2 times

PWM behaviour for 0% and 100%

Post by sdalu »

I'm wondering what should be the PWM driver behaviour for 0% and 100% duty cycle.
If enabled, should we have a channel notification for every cycle, or no notification at all?

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

Re: PWM behaviour for 0% and 100%

Post by Giovanni »

It should give a channel notification because the channel is active.

Giovanni
Angel
Posts: 5
Joined: Sun Jun 12, 2016 10:35 pm
Has thanked: 2 times

Re: PWM behaviour for 0% and 100%

Post by Angel »

Hello, I got the PWM channel working on three channels in a 103RB, but when I use this:

pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 7500));

for percentage values of 12% (value set at 1200) or below this value, the duty cycle rises up to 60% an continue increasing as I set lower percentage values. in this way, the duty cycle does not get zero or even get close of it with a 0 percentage value.

I tried to get more information by comparing the program with the sample programs, but actually those does not cover such low percentage values.
also I cheked that the higher the PWM frequency, the bigger is this behavior,

I appreciate you could give me a solution or opinion about it.
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PWM behaviour for 0% and 100%

Post by Giovanni »

Hi,

You should post your PWM settings.

Giovanni
Angel
Posts: 5
Joined: Sun Jun 12, 2016 10:35 pm
Has thanked: 2 times

Re: PWM behaviour for 0% and 100%

Post by Angel »

thank you for answering, here they are:

static PWMConfig pwmcfg = {
200000,
10,
pwmpcb,
{
{PWM_OUTPUT_ACTIVE_HIGH, pwmc1cb},
{PWM_OUTPUT_ACTIVE_HIGH, pwmc1cb1},
{PWM_OUTPUT_ACTIVE_HIGH, pwmc1cb2},
{PWM_OUTPUT_DISABLED, NULL}
},
0,
0,
};

I tried to solve it by modifying the first two parameters (20000, 1)but then the PWM did not work at all
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PWM behaviour for 0% and 100%

Post by Giovanni »

That "10" means that your PWM has only 10 discrete duty cycle settings because the counter goes from 0 to 9 then it is reset.

You need to define the input clock and the period value accordingly to your requirements.

Giovanni
Angel
Posts: 5
Joined: Sun Jun 12, 2016 10:35 pm
Has thanked: 2 times

Re: PWM behaviour for 0% and 100%

Post by Angel »

I tried some usefull frequency combinations for my application, in some I got this effect reduced, but none of them achieved a zero duty cycle; anyway, I think I will cut off this last sampling segment by software and set the zero value in the output

thank you very much, the best
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PWM behaviour for 0% and 100%

Post by Giovanni »

Try setting the duty cycle at 0 without using the macro, do you get a continuous level? 0% and 100% should have no fronts.

Giovanni
Angel
Posts: 5
Joined: Sun Jun 12, 2016 10:35 pm
Has thanked: 2 times

Re: PWM behaviour for 0% and 100%

Post by Angel »

yes, I will set to zero that part in that way, thank you for your suggestion.

also yes, by using the macro in some setting configurations, the level of this effect is continuous , overall, in the low frequency configurations
Post Reply