Pages: [1]   Go Down
Author Topic: Help with error message got on serial after arduino crash  (Read 972 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged


0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Forum Administrator
Milano, Italy
Offline Offline
Sr. Member
*****
Karma: 23
Posts: 292
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@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?

Logged

C.

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok Cmaglie, I'll open there.

Regards,

Joao
Logged


Pages: [1]   Go Up
Jump to: