typedef struct PID
{
double SetPoint; // Desired Value
double Proportion; // Proportional Const
double Integral; // Integral Const
double Derivative; // Derivative Const
double LastError; // Error[-1]
double PrevError; // Error[-2]
double SumError; // Sums of Errors
} PID;
/*=========================================================================*\
Perform One PID Iteration
\*=========================================================================*/
double PIDCalc ( PID *pp, double NextPoint )
{ double dError, Error;
pp->SumError += (Error = pp->SetPoint - NextPoint);
dError = pp->LastError - pp->PrevError;
pp->PrevError = pp->LastError;
pp->LastError = Error;
return ( pp->Proportion * Error
+ pp->Integral * pp->SumError
+ pp->Derivative * dError
);
}
/*=========================================================================*\
Initialize PID Structure
\*=========================================================================*/
void PIDInit ( PID *pp )
{ memset ( pp,0,sizeof(PID) );
}
/***************************************************************************\
Main Program
\***************************************************************************/
double sensor ( void ) // Dummy Sensor Function
{ return 100.0;
}
void actuator ( double rDelta ) // Dummy Actuator Function
{}
void main ( void )
{ PID sPID; // PID Control Structure
double rOut; // PID Response (Output)
double rIn; // PID Feedback (Input)
PIDInit ( &sPID ); // Initialize Structure
sPID.Proportion = 0.5; // Set PID Coefficients
sPID.Integral = 0.5;
sPID.Derivative = 0.0;
sPID.SetPoint = 100.0; // Set PID Setpoint
for (;;) // Mock Up of PID Processing
{ rIn = sensor (); // Read Input
rOut = PIDCalc ( &sPID,rIn ); // Perform PID Interation
actuator ( rOut ); // Effect Needed Changes
}
}
Previous article:PID Control C51 Program (3)
Next article:PID Control C51 Program (5)
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- What is the rigidity setting of Panasonic servo drive?
- How to change the inertia ratio of Panasonic servo drive
- What is the inertia ratio of the servo motor?
- Is it better for the motor to have a large or small moment of inertia?
- What is the difference between low inertia and high inertia of servo motors?
- Playing with Zynq Serial 2——GPIO peripherals of Zynq PS
- Ask the big guy, about the problem of DS1302
- Why is DS heavily doped in the MOS tube structure?
- The free evaluation Perf-V development board has been successfully ported and run on the Wujian100 platform
- [Goodbye 2021, Hello 2022] Keep a low profile, face reality, and keep moving forward for your dreams
- How to display black text on white background in FPGA?
- EEWORLD University Hall----Application of IoT sensing technology
- [micropython] STM32 branch improves support for wiznet5k
- MSP430 MCU Development Record (18)
- TI C6000 DSP Basics: GPIO