Professional Documents
Culture Documents
h"
struct pidParameters
{
float Kp;
float Ki;
float Kd;
void setup(void) // Funtion definition for setup of the ADC AND Power PWM Module.
{
int main(void)
pidParams.Kp = 0.4;
pidParams.Ki = 0;
pidParams.Kd = 0;
while(1)
{
}
}
// Interrupt Service Routine will read ADC and Update the Duty Cycle Register
// The ISR is Invoked at a 20KHz rate. This 50usecs between updates of the Duty
Cycle Register.
{
if (pidParams.integral > -32000)
pidParams.integral += pidParams.error;
}
pidParams.derivitive = pidParams.error -
pidParams.previous_error;
// Perform boundary checks on the output of the PID algorithm. If the output limits
are exceeded then, then set output to the limit
// and set flag.
pidParams.previous_error = pidParams.error;
}
}