[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Problem with signed 32bit ints?

From: Mike Panetta
Subject: [avr-gcc-list] Problem with signed 32bit ints?
Date: 28 Jan 2003 12:17:50 -0500

I think I am having a problem with signed 32bit ints on the avr.  Here
is the function I am having problems with: 

DoPid(MotorInfo * motor) 
int32_t error; 
int32_t drive; 
int16_t Tp; //<--  I cant change these to int32_t 
int16_t Ti; //              "  " 
int16_t Td; //              "  " 

error = motor->setpoint - motor->position; 
Tp = motor->Kp*error; 
Td = motor->Kd*(error - motor->PrevErr); 
        Ti = motor->Ki*motor->Ierror; 
drive = (Tp+Td+Ti)/(int32_t)motor->Ko; 

motor->PrevErr = error; 

if (drive >= motor->maxDrive) 
drive = motor->maxDrive; 
else if (drive <= -(motor->maxDrive)) 
drive = -(motor->maxDrive); 
motor->Ierror += error;  
motor->drive = drive; 
return drive; 


If I change any of Tp, Ti, or Td to 32 bit ints the function fails to
work when the value of any of the variables is negative.  The Kp, Ki,
Kd, and Ko values in the struct MotorInfo are all signed 8 bit values. 
Does anyone have any clue as to what I am doing wrong?  Or is it really
a bug in the compiler?  Are there any known issues with mixing 32bit and
16bit or less values in a comparison or divide operation?  


PS:  I am not on the list, so please CC me any response.

avr-gcc-list at http://avr1.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]