This is a typical PID processing program found on the Internet. When using a single-chip microcomputer as a control CPU, please simplify it a little. The specific PID parameters must be determined by the specific object through experiments. Due to the processing speed and RAM resource limitations of the single-chip microcomputer, floating-point operations are generally not used. Instead, all parameters are integers, and the calculation is divided by a 2-N-th power data (equivalent to shift) at the end, and similar fixed-point operations are performed, which can greatly improve the calculation speed. According to the different requirements of control accuracy, when the accuracy requirement is very high, pay attention to retaining the "remainder" caused by the shift and make good remainder compensation. This program is just the basic framework of the commonly used PID algorithm, and does not include the input and output processing part.
=================================================================================================*/
#i nclude
#i nclude
/*====================================================================== ==========
PID Function
The PID (proportional, integral, differential) function is used in mainly
control applications. PIDCalc performs one iteration of the PID
algorithm.
While the PID function works, main is just a dummy program showing
a typical usage.
=================================================================================================*/
typedef struct PID {
double SetPoint; // Set target Desired Value
double Proportion; // Proportional Cons t
double Integral; // Integral constant Integral Const
double Derivative; // Derivative constant Derivative Const
double LastError; // Error[-1]
double PrevError; // Error[-2]
double SumError; // Sums of Errors
} PID;
/*============================================================================================================
PID calculation part
=============================================================== )
{
double
dError,
Error;
Error = pp->SetPoint - NextPoint; // Deviation
pp->SumError += Error; // Integral
dError = pp->LastError - pp->PrevError; // Current differential
pp->PrevError = pp->LastError;
pp->LastError = Error;
return (pp->Proportion * Error // Proportional term
+ pp->Integral * pp->SumError // Integral term
+ pp->Derivative * dError // Derivative term
);
}
/*=
...
===================================================================================================*/
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
}
}
Expanded critical proportion method to determine PID coefficients??
Use proportional control to form a closed-loop system, and gradually increase the proportional coefficient from small to large, so that the closed-loop system is in a critical oscillation state (stable boundary). The critical oscillation state waveform is shown in Figure 2. The oscillation period in this state is Tc = 0.0396 s.
According to the empirical formula to determine the range, the characteristics of the Zhoushan DC transmission system composed of a single-bridge converter determine that the system is only controlled when the pulse triggers the valve to commutate, that is, once every 3.3 ms, that is, Ts = 3.3 ms, that is, Ts = 0.083 Tc. According to the empirical formula provided in Table 1, the above situation is close to Ts = 0.09 Tc, and the approximate range of the PID coefficient is Kp = 1 800, Ki = 370, and Kd = 4 000.
Table 1 The range of PID controller parameters of the extended critical proportion method
Ts Kp Ti Td
0.014Tc 0.63Kpc 0.49Tc 0.14Tc
0.043Tc 0.47Kpc 0.47Tc 0.16Tc 0.090Tc 0.34Kpc
0.43Tc 0.20Tc 0.160Tc
0.27Kpc 0.40Tc 0.22Tc
Previous article:PID Control C51 Program (1)
Next article:PID Control C51 Program (3)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Xunwei IMX6 development board Android application-buzzer test
- Lithium-ion battery
- How to expand the BIM code space of CC2640 SDK sample code
- Sound Level Meter MASTECH MS6700 Disassembly Pictures and Information
- Design of Multi-channel Data Acquisition System Based on CPLD
- EEWORLD University Hall----Underactuated Robotics MIT 2019 spring 6.382
- It's so tiring to work under a fool!
- Could you please tell me what glue is used to stick piezoelectric ceramic sheets to ultrasonic sensors?
- EEWORLD University Hall----C2000 series new products bring convenience to servo and motor drive systems
- [GD32E231 DIY Contest] 01. GD32E231-start and creative content introduction