📄 pid_wf1.lst
字号:
C51 COMPILER V6.10 PID_WF1 04/19/2001 12:09:40 PAGE 1
C51 COMPILER V6.10, COMPILATION OF MODULE PID_WF1
OBJECT MODULE PLACED IN .\PID_wf1.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\PID_wf1.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*------------------------------------------------------------------*-
2
3 PID_wf1.C (v1.00)
4
5 ------------------------------------------------------------------
6
7 Simple PID control implementation, with anti-windup protection.
8
9 See Chapter 35 for details.
10
11
12 COPYRIGHT
13 ---------
14
15 This code is from the book:
16
17 PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont
18 [Pearson Education, 2001; ISBN: 0-201-33138-1].
19
20 This code is copyright (c) 2001 by Michael J. Pont.
21
22 See book for copyright details and other information.
23
24 -*------------------------------------------------------------------*/
25
26 #include "PID_wf1.h"
27
28 // ------ Private constants ----------------------------------------
29
30 #define PID_KP (0.2f) // Proportional gain
31 #define PID_KI (0.10f) // Integral gain
32 #define PID_KD (0.10f) // Differential gain
33
34 #define PID_WINDUP_PROTECTION (1) // Set to TRUE (1) or FALSE (0)
35
36 #define PID_MAX (1.0f) // Maximum PID controller output
37 #define PID_MIN (0.0f) // Minimum PID controller output
38
39 // ------ Private variable definitions------------------------------
40
41 static float Sum_G; // Integrator component
42 static float Old_error_G; // Previous error value
43
44 /*------------------------------------------------------------------*-
45
46 PID_Control()
47
48 Simple floating-point version.
49
50 See text for details.
51
52 -*------------------------------------------------------------------*/
53 float PID_Control(float Error, float Control_old)
54 {
55 1 // Proportional term
C51 COMPILER V6.10 PID_WF1 04/19/2001 12:09:40 PAGE 2
56 1 float Control_new = Control_old + (PID_KP * Error);
57 1
58 1 // Integral term
59 1 Sum_G += Error;
60 1 Control_new += PID_KI * Sum_G;
61 1
62 1 // Differential term
63 1 Control_new += (PID_KD * SAMPLE_RATE * (Error - Old_error_G));
64 1
65 1 // Optional windup protection - see text
66 1 if (PID_WINDUP_PROTECTION)
67 1 {
68 2 if ((Control_new > PID_MAX) || (Control_new < PID_MIN))
69 2 {
70 3 Sum_G -= Error; // Don't increase Sum...
71 3 }
72 2 }
73 1
74 1 // Control_new cannot exceed PID_MAX or fall below PID_MIN
75 1 if (Control_new > PID_MAX)
76 1 {
77 2 Control_new = PID_MAX;
78 2 }
79 1 else
80 1 {
81 2 if (Control_new < PID_MIN)
82 2 {
83 3 Control_new = PID_MIN;
84 3 }
85 2 }
86 1
87 1 // Store error value
88 1 Old_error_G = Error;
89 1
90 1 return Control_new;
91 1 }
92
93 /*------------------------------------------------------------------*-
94 ---- END OF FILE -------------------------------------------------
95 -*------------------------------------------------------------------*/
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 342 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 8 12
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -