CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PID integral term

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Zek_De



Joined: 13 Aug 2016
Posts: 100

View user's profile Send private message

PID integral term
PostPosted: Fri Feb 10, 2017 10:58 am     Reply with quote

Hello friends,
I couldn't understand how to do integral term limits. These are my codes, and 20.000 max pwm to max power. Where is my mistake?
Code:

int16_t Constrain(float test, int16_t a, int16_t b)
{
   if(test < a) return a;
   else if(test > b) return b;
   else return (int16_t)lroundf(test);
}
//##########################################
uint16_t PIDX(uint16_t value, float target, float current)
{
   error = (target - current);
   integral = (float)Constrain((integral + error*deltaT), -19000, 19000);
   derivative = (error - previousError) / deltaT;
   previousError = error;
   return (Constrain(value + Kp*error + Ki*integral + Kd*derivative, 0, 19999));
}
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Feb 10, 2017 11:18 am     Reply with quote

to my old eyes, it's using floating point numbers...
or...it could be lack of casting or other math related confusion,like braces.

When doing math like this, you should print out(display) ALL of the interim terms and use KNOWN input values, compare what the PIC says vs what YOU have done the math on.

I didn't use them 20 years ago with 16F877s and realtime helicopters...
..no need for them and they take a HUGE amount of time to compute.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Fri Feb 10, 2017 11:52 am     Reply with quote

Yes. The idea of 'PID', and 'floating point', don't really go together on a PIC, unless you are controlling something really slow. I've successfully done some quite fast PID's using 24bit integers, with the last byte treated as the fractional part. 1.0000, then is stored as 256....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group