Go Down

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



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?


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:


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.



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?





I'm assuming this bug was never fixed since I just got the error 5 years later?

For those curious,  constrain your pwm output to +-255 or this error will occur. 

Would be nice if the pwmc.c source did this for you and not crash the entire stack.

Go Up