So this is what I have...
Code:
#include "pid.h"
#include "ifi_aliases.h"
#include "ifi_default.h"
#include "ifi_utilities.h"
#include "user_routines.h"
#include "printf_lib.h"
int PID_Main (int current, int target, int static_i, int i_max, int i_min,
int static_p, int p_gain, int i_gain, int d_gain){
int pout, perr, iout, ierr, derr, dout;
// calculate errors \\
perr = target - current;
ierr = static_i + perr;
derr = static_p - perr;
// limit ierr \\
if (ierr => i_max)
{
ierr = i_max;
}
else if(ierr =< i_min)
{
ierr = i_min;
}
// calulate outputs from each part \\
pout = p_gain * perr;
iout = i_gain * ierr;
dout = d_gain * derr;
// calculate output \\
return pout + iout + dout;
}
1. I don't know how to retrieve the static variables after the function has processed them.
2. I would also like to create a structure to hold all the info passed to this function so if anyone has any advice on doing that I would appreciate it.
This function may not work properly I had written a single channel PID, but it was early this year and I can't find it. If you see any problems please tell me.
Matt, I was referring to your white paper.
Thanks,
EHaskins