#ifndef __PID__ #define __PID__ /*PID = Uk + KP*[E(k)-E(k-1)]+KI*E(k)+KD*[E(k)-2E(k-1)+E(k-2)]; (Incremental PID formula) Function entry: RK (set value), CK (actual value), KP, KI, KD Function export: U(K)*/ typedef struct PIDValue { int8 KP; int8 KI; int8 KD; int8 F; int8 BITMOV; int EK[3]; int UK; int RK; int CK; int UK_REAL; }pid_str; //PIDValueStr PID; void pid_exe(pid_str *PID); #endif //pid.c /*PID = PID->UK_REAL + PID->KP*[E(k)-E(k-1)]+PID->KI*E(k)+PID->KD*[E(k)-2E(k-1)+E(k-2)]; (Incremental PID formula) Function entry: PID->RK (set value), PID->CK (actual value), PID->KP, PID->KI, PID->KD Function export: U(K)*/ #include "defines.h" #include "pid.h" #define MAXOUT 0xff //#define MAXGAP 100 void pid_exe(pid_str*PID) { PID->EK[2]=PID->EK[1]; PID->EK[1]=PID->EK[0]; PID->EK[0]=PID->RK-PID->CK; PID->UK_REAL=PID->UK_REAL +PID->KP*(PID->EK[0]-PID->EK[1])//differentiate once and integrate to get the original number +(float)PID->KI*PID->EK[0]/PID->F//direct integration +(float)PID->KD*(PID->EK[0]-2*PID->EK[1]+PID->EK[2])*PID->F; //Integration after second-order differential is first-order differential if((PID->UK_REAL>>PID->BITMOV)>=MAXOUT) { PID->UK=MAXOUT; }else if(PID->UK_REAL>>PID->BITMOV<=-MAXOUT) { PID->UK=-MAXOUT; }else { PID->UK=PID->UK_REAL>>PID->BITMOV; } }
The code I wrote here uses an incremental PID (i.e. UK_REAL + PID->KP*[E(k)-E(k-1)]+PID->KI*E(k)+PID->KD*[E(k)-2E(k-1)+E(k-2)]; this sentence corresponds to the value of the PID control amount added to the previous PID control amount, which is equivalent to taking a derivative). The final output result is the cumulative output of each operation.
Attached is an excerpt of the difference between positional pid and incremental pid.
(1) The output of the position PID control is related to the entire past state, and the accumulated value of the error is used; while the output of the incremental PID is only related to the error between the current beat and the previous two beats, so the accumulated error of the position PID control is relatively larger; (2) The incremental PID control output is the control quantity increment and has no integral effect. Therefore, this method is suitable for objects whose actuators have integral components, such as stepper motors, while the position PID is suitable for objects whose actuators do not have integral components, such as electro-hydraulic servo valves. (3) Since the incremental PID output is the increment of the control quantity, if the computer fails, the impact of the false operation is small, and the actuator itself has a memory function and can remain in place, which will not seriously affect the operation of the system. The output of the position type directly corresponds to the output of the object, so it has a greater impact on the system.
Previous article:Serial port interrupt mode in 51 single chip microcomputer
Next article:51 MCU UART serial communication mode 1 implementation
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- A must-read summary of drone principles (Part 3) Introduction to the appearance of drones
- [Fudan Micro FM33LG0 Series Development Board Review] PGL Function and Brief Analysis
- Application design of MCU in blood analyzer
- CST Chinese Tutorial
- Recommended fuel gauges for drone battery packs
- [Mil MYB-YT507 development board trial experience] Install pyecharts module
- MediaTek launches the largest recruitment in history, with annual salary of more than 345,000 for graduates with master's degree
- BlueNRG-Series RTC with Sleep Reference Design
- Multi-channel data acquisition system based on CS5321 and CS5322
- In a Class D amplifier, the output waveforms of the three stages are modulator, Class D amplifier, and low-pass filter.