PID Control C51 Program (2)

Publisher:云自南国来Latest update time:2016-11-17 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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


Reference address:PID Control C51 Program (2)

Previous article:PID Control C51 Program (1)
Next article:PID Control C51 Program (3)

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号