text1.lst
来自「C8051F350控制器」· LST 代码 · 共 121 行
LST
121 行
C51 COMPILER V7.20 TEXT1 04/13/2007 16:22:58 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE TEXT1
OBJECT MODULE PLACED IN .\Text1.obj
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE H:\Text1.c BROWSE DEBUG OBJECTEXTEND PRINT(.\Text1.lst) OBJECT(.\Text1.obj)
line level source
1 /*====================================================================================================
2 这是从网上找来的一个比较典型的PID处理程序,在使用单片机作为控制cpu时,请稍作简化,具体的PID
3 参数必须由具体对象通过实验确定。由于单片机的处理速度和ram资源的限制,一般不采用浮点数运算,
4 而将所有参数全部用整数,运算到最后再除以一个2的N次方数据(相当于移位),作类似定点数运算,可
5 大大提高运算速度,根据控制精度的不同要求,当精度要求很高时,注意保留移位引起的“余数”,做好余
6 数补偿。这个程序只是一般常用pid算法的基本架构,没有包含输入输出处理部分。
7 =====================================================================================================*/
8 #include <string.h>
9 #include <stdio.h>
10 /*====================================================================================================
11 PID Function
12
13 The PID (比例、积分、微分) function is used in mainly
14 control applications. PIDCalc performs one iteration of the PID
15 algorithm.
16
17 While the PID function works, main is just a dummy program showing
18 a typical usage.
19 =====================================================================================================*/
20
21 typedef struct PID {
22
23 double SetPoint; // 设定目标 Desired Value
24
25 double Proportion; // 比例常数 Proportional Const
26 double Integral; // 积分常数 Integral Const
27 double Derivative; // 微分常数 Derivative Const
28
29 double LastError; // Error[-1]
30 double PrevError; // Error[-2]
31 double SumError; // Sums of Errors
32
33 } PID;
34
35 /*====================================================================================================
36 PID计算部分
37 =====================================================================================================*/
38
39 double PIDCalc( PID *pp, double NextPoint )
40 {
41 1 double dError,
42 1 Error;
43 1
44 1 Error = pp->SetPoint - NextPoint; // 偏差
45 1 pp->SumError += Error; // 积分
46 1 dError = pp->LastError - pp->PrevError; // 当前微分
47 1 pp->PrevError = pp->LastError;
48 1 pp->LastError = Error;
49 1 return (pp->Proportion * Error // 比例项
50 1 + pp->Integral * pp->SumError // 积分项
51 1 + pp->Derivative * dError // 微分项
52 1 );
53 1 }
54
55 /*====================================================================================================
C51 COMPILER V7.20 TEXT1 04/13/2007 16:22:58 PAGE 2
56 Initialize PID Structure
57 =====================================================================================================*/
58
59 void PIDInit (PID *pp)
60 {
61 1 memset ( pp,0,sizeof(PID));
62 1 }
63
64 /*====================================================================================================
65 Main Program
66 =====================================================================================================*/
67
68 double sensor (void) // Dummy Sensor Function
69 {
70 1 return 100.0;
71 1 }
72
73 void actuator(double rDelta) // Dummy Actuator Function
74 {}
*** WARNING C280 IN LINE 73 OF H:\TEXT1.C: 'rDelta': unreferenced local variable
75
76 void main(void)
77 {
78 1 PID sPID; // PID Control Structure
79 1 double rOut; // PID Response (Output)
80 1 double rIn; // PID Feedback (Input)
81 1
82 1 PIDInit ( &sPID ); // Initialize Structure
83 1 sPID.Proportion = 0.5; // Set PID Coefficients
84 1 sPID.Integral = 0.5;
85 1 sPID.Derivative = 0.0;
86 1 sPID.SetPoint = 100.0; // Set PID Setpoint
87 1
88 1 for (;;) { // Mock Up of PID Processing
89 2
90 2 rIn = sensor (); // Read Input
91 2 rOut = PIDCalc ( &sPID,rIn ); // Perform PID Interation
92 2 actuator ( rOut ); // Effect Needed Changes
93 2 }
94 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 364 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 55
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?