Go Down

Topic: Help with error message got on serial after arduino crash (Read 1 time) previous topic - next topic

alvesjc

Hi.

I don't know why, my program started to crash and I'm getting this error when I activate serial monitor in IDE.

"
loopassertion "duty <= pPwm->PWM_CH_NUM[ul_channel].PWM_CPRD" failed: file "../source/pwmc.c", line 272, function: PWMC_SetDutyCycle
Exiting with status 1.
"

Can someone help me out understanding this?
www.aqualedsource.com

alvesjc

Ok, I've managed to pinpoint the issue.

I'm using pwm at 16bit resolution.

This error message was originated because negative values were being passed to the PWM OCx registers.

The problem seems to be the built in map function.

I'm passing to it unsigned long variables, but it doesn't see them that way. It seems that they are being interpreted has signed shorts because when 32767 is reached, after that the values become negative.

The function was this:

lv_mapedpwm=map(PWMout,0UL,65535UL,MinPWM,MaxPWM);

MinPWM and MaxPWM are declared has unsigned long also.

This yeld negative values in lv_mapedpwm var.

I've then used one map function for floats and worked like a charm, although values being passed has UL.

float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

the odd thing is that the compiler doesn't complain at all when I pass the UL values to the map function.

Isn't this an issue with IDE itself? I'm using 1.5.3 version at the moment.

waiting for your comments.
www.aqualedsource.com

cmaglie

@alvesjc

probably you have found a bug in the map function (that is triggered when the values are around the maximum).
may you post an issue on github with an example that fails?

C.

alvesjc

www.aqualedsource.com

Go Up