This file contains defines, typedefs and prototypes for the PID controller.
Definition in file pid.h.
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Data Structures | |
| struct | pidData |
| PID Status. More... | |
Defines | |
| #define | FALSE 0 |
| FALSE constant. | |
| #define | MAX_I_TERM (MAX_LONG - (2 * (int32_t)MAX_INT)) |
| #define | MAX_INT 32767 |
| Maximum value of integers. | |
| #define | MAX_LONG 2147483647L |
| Maximum value of long integers. | |
| #define | SCALING_FACTOR 256 |
| Scaling division factor for PID controller. | |
| #define | TRUE (!FALSE) |
| TRUE constant. | |
Typedefs | |
| typedef pidData | pidData_t |
| PID Status. | |
Functions | |
| int16_t | PID_Controller (int16_t setPoint, int16_t processValue, pidData_t *pid_st) |
| PID control algorithm. | |
| void | PID_Init (int16_t p_factor, int16_t i_factor, int16_t d_factor, pidData_t *pid) |
| Initialisation of PID controller parameters. | |
| void | PID_Reset_Integrator (pidData_t *pid_st) |
| Resets the integrator. | |
|
|
FALSE constant.
Definition at line 79 of file pid.h. Referenced by ActualDirectionUpdate(), CommutationTicksUpdate(), DirectionInputChangeISR(), HallChangeISR(), main(), and MotorSynchronizedUpdate(). |
|
|
Maximum value of the I-term. This limits the maximum positive or negative value of the I-term. Changing this value leads to a different integral anti-windup limit. Do not increase this value from its default, as it is already at the limit of the underlying data types. Definition at line 75 of file pid.h. Referenced by PID_Controller(), and PID_Init(). |
|
|
Maximum value of integers.
Definition at line 63 of file pid.h. Referenced by PID_Controller(), and PID_Init(). |
|
|
Maximum value of long integers.
|
|
|
Scaling division factor for PID controller. Scaling division factor for the PID controller. The P, I and D gains will be divided by this number. Definition at line 37 of file pid.h. Referenced by PID_Controller(). |
|
|
TRUE constant.
Definition at line 82 of file pid.h. Referenced by CommutationTicksUpdate(), MotorSynchronizedUpdate(), and Timer1CaptureISR(). |
|
|
PID Status. Setpoints and data used by the PID control algorithm |
|
||||||||||||||||
|
PID control algorithm. Calculates output from setpoint, process value and PID status.
Definition at line 65 of file pid.c. References pidData::D_Factor, pidData::I_Factor, pidData::lastProcessValue, MAX_I_TERM, MAX_INT, pidData::maxError, pidData::maxSumError, pidData::P_Factor, SCALING_FACTOR, and pidData::sumError. Referenced by SpeedController(). 00066 { 00067 int16_t error, p_term, d_term; 00068 int32_t i_term; 00069 int32_t ret; 00070 int32_t temp; 00071 00072 error = setPoint - processValue; 00073 00074 // Calculate Pterm and limit error overflow 00075 if (error > pid_st->maxError) 00076 { 00077 p_term = MAX_INT; 00078 } 00079 else if (error < -pid_st->maxError) 00080 { 00081 p_term = -MAX_INT; 00082 } 00083 else 00084 { 00085 p_term = pid_st->P_Factor * error; 00086 } 00087 00088 // Calculate Iterm and limit integral runaway 00089 temp = pid_st->sumError + error; 00090 if(temp > pid_st->maxSumError) 00091 { 00092 i_term = MAX_I_TERM; 00093 pid_st->sumError = pid_st->maxSumError; 00094 } 00095 else if(temp < -pid_st->maxSumError) 00096 { 00097 i_term = -MAX_I_TERM; 00098 pid_st->sumError = -pid_st->maxSumError; 00099 } 00100 else 00101 { 00102 pid_st->sumError = temp; 00103 i_term = pid_st->I_Factor * pid_st->sumError; 00104 } 00105 00106 // Calculate Dterm 00107 d_term = pid_st->D_Factor * (pid_st->lastProcessValue - processValue); 00108 00109 pid_st->lastProcessValue = processValue; 00110 00111 ret = (p_term + i_term + d_term) / SCALING_FACTOR; 00112 if(ret > MAX_INT) 00113 { 00114 ret = MAX_INT; 00115 } 00116 else if(ret < -MAX_INT) 00117 { 00118 ret = -MAX_INT; 00119 } 00120 00121 return((int16_t)ret); 00122 }
|
|
||||||||||||||||||||
|
Initialisation of PID controller parameters. Initialise the variables used by the PID algorithm.
Definition at line 41 of file pid.c. References pidData::D_Factor, pidData::I_Factor, pidData::lastProcessValue, MAX_I_TERM, MAX_INT, pidData::maxError, pidData::maxSumError, pidData::P_Factor, and pidData::sumError. Referenced by main(). 00043 { 00044 // Start values for PID controller 00045 pid->sumError = 0; 00046 pid->lastProcessValue = 0; 00047 // Tuning constants for PID loop 00048 pid->P_Factor = p_factor; 00049 pid->I_Factor = i_factor; 00050 pid->D_Factor = d_factor; 00051 // Limits to avoid overflow 00052 pid->maxError = MAX_INT / pid->P_Factor; 00053 pid->maxSumError = MAX_I_TERM / pid->I_Factor; 00054 }
|
|
|
Resets the integrator. Calling this function will reset the integrator in the PID regulator. Definition at line 129 of file pid.c. References pidData::sumError. Referenced by CommutationTicksUpdate(). 00130 { 00131 pid_st->sumError = 0; 00132 }
|
1.4.4