⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pid.lst

📁 mcu51程序串口输入控制2相4线步进电机的程序
💻 LST
字号:
C51 COMPILER V7.04   PID                                                                   05/17/2006 17:00:59 PAGE 1   


C51 COMPILER V7.04, COMPILATION OF MODULE PID
OBJECT MODULE PLACED IN pid.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE pid.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          
   2            
*** ERROR C100 IN LINE 2 OF PID.C: unprintable character 0xA1 skipped
*** ERROR C100 IN LINE 2 OF PID.C: unprintable character 0xA1 skipped
*** ERROR C100 IN LINE 2 OF PID.C: unprintable character 0xA1 skipped
*** ERROR C100 IN LINE 2 OF PID.C: unprintable character 0xA1 skipped
   3            #include <stdio.h>
*** ERROR C100 IN LINE 3 OF PID.C: unprintable character 0xA1 skipped
*** ERROR C100 IN LINE 3 OF PID.C: unprintable character 0xA1 skipped
*** ERROR C100 IN LINE 3 OF PID.C: unprintable character 0xA1 skipped
*** ERROR C100 IN LINE 3 OF PID.C: unprintable character 0xA1 skipped
*** ERROR C141 IN LINE 3 OF PID.C: syntax error near '#'
*** ERROR C129 IN LINE 3 OF PID.C: missing ';' before '<'
   4            #include<math.h>
   5            
   6            struct _pid {
   7             int pv; /*integer that contains the process value*/
   8             int sp; /*integer that contains the set point*/
   9             float integral;
  10             float pgain;
  11             float igain;
  12             float dgain;
  13             int deadband;
  14             int last_error;
  15            };
  16            
  17            struct _pid warm,*pid;
  18            int process_point, set_point,dead_band; 
  19            float p_gain, i_gain, d_gain, integral_val,new_integ;; 
  20            
  21            
  22            
  23            /*------------------------------------------------------------------------ 
  24            pid_init 
  25            
  26            DESCRIPTION This function initializes the pointers in the _pid structure 
  27            to the process variable and the setpoint. *pv and *sp are 
  28            integer pointers. 
  29            ------------------------------------------------------------------------*/ 
  30            void pid_init(struct _pid *warm, int process_point, int set_point)
  31            { 
  32             struct _pid *pid; 
  33             
  34             pid = warm; 
  35             pid->pv = process_point; 
  36             pid->sp = set_point; 
  37            } 
  38            
  39            
  40            /*------------------------------------------------------------------------ 
  41            pid_tune 
  42            
  43            DESCRIPTION Sets the proportional gain (p_gain), integral gain (i_gain), 
  44            derivitive gain (d_gain), and the dead band (dead_band) of 
  45            a pid control structure _pid. 
C51 COMPILER V7.04   PID                                                                   05/17/2006 17:00:59 PAGE 2   

  46            ------------------------------------------------------------------------*/ 
  47            
  48            void pid_tune(struct _pid *pid, float p_gain, float i_gain, float d_gain, int dead_band) 
  49            { 
  50             pid->pgain = p_gain; 
  51             pid->igain = i_gain; 
  52             pid->dgain = d_gain; 
  53             pid->deadband = dead_band; 
  54             pid->integral= integral_val; 
  55             pid->last_error=0; 
  56            } 
  57            
  58            /*------------------------------------------------------------------------ 
  59            pid_setinteg 
  60            
  61            DESCRIPTION Set a new value for the integral term of the pid equation. 
  62            This is useful for setting the initial output of the 
  63            pid controller at start up. 
  64            ------------------------------------------------------------------------*/ 
  65            void pid_setinteg(struct _pid *pid,float new_integ)
  66            { 
  67             pid->integral = new_integ; 
  68             pid->last_error = 0; 
  69            } 
  70            
  71            /*------------------------------------------------------------------------ 
  72            pid_bumpless 
  73            
  74            DESCRIPTION Bumpless transfer algorithim. When suddenly changing 
  75            setpoints, or when restarting the PID equation after an 
  76            extended pause, the derivative of the equation can cause 
  77            a bump in the controller output. This function will help 
  78            smooth out that bump. The process value in *pv should 
  79            be the updated just before this function is used. 
  80            ------------------------------------------------------------------------*/ 
  81            void pid_bumpless(struct _pid *pid) 
  82            { 
  83            
  84             pid->last_error = (pid->sp)-(pid->pv); 
  85             
  86            } 
  87            
  88            /*------------------------------------------------------------------------ 
  89            pid_calc 
  90            
  91            DESCRIPTION Performs PID calculations for the _pid structure *a. This function uses the positional for
             -m of the pid equation, and incorporates an integral windup prevention algorithim. Rectangular integration is used, so th
             -is function must be repeated on a consistent time basis for accurate control. 
  92            
  93            RETURN VALUE The new output value for the pid loop. 
  94            
  95            USAGE #include "control.h"*/ 
  96            
  97            
  98            float pid_calc(struct _pid *pid)
  99            { 
 100             int err;
 101             float pterm, dterm, result, ferror; 
 102             
 103             err = (pid->sp) - (pid->pv); 
 104             if (abs(err) > pid->deadband) 
 105             { 
C51 COMPILER V7.04   PID                                                                   05/17/2006 17:00:59 PAGE 3   

 106             ferror = (float) err; /*do integer to float conversion only once*/ 
 107             pterm = pid->pgain * ferror; 
 108             if (pterm > 100 || pterm < -100)
 109             {
 110             pid->integral = 0.0; 
 111             }
 112             else 
 113             { 
 114             pid->integral += pid->igain * ferror; 
 115             if (pid->integral > 100.0) 
 116             {
 117             pid->integral = 100.0; 
 118             }
 119             else if (pid->integral < 0.0) pid->integral = 0.0; 
 120             } 
 121             dterm = ((float)(err - pid->last_error)) * pid->dgain; 
 122             result = pterm + pid->integral + dterm; 
 123             } 
 124             else result = pid->integral; 
 125             pid->last_error = err; 
 126             return (result); 
 127            }
 128            
 129            
 130            void main(void)
 131            {
 132             float display_value;
 133             int count=0;
 134            
 135             pid = &warm;
 136            
 137            // printf("Enter the values of Process point, Set point, P gain, I gain, D gain \n");
 138            // scanf("%d%d%f%f%f", &process_point, &set_point, &p_gain, &i_gain, &d_gain);
 139            
 140            
 141            
 142             process_point = 30;
 143             set_point = 40;
 144             p_gain = (float)(5.2);
 145             i_gain = (float)(0.77);
 146             d_gain = (float)(0.18);
 147            
 148            
 149            
 150             dead_band = 2;
 151             integral_val =(float)(0.01);
 152            
 153            
 154             printf("The values of Process point, Set point, P gain, I gain, D gain \n");
 155             printf(" %6d %6d %4f %4f %4f\n", process_point, set_point, p_gain, i_gain, d_gain);
 156            
 157             printf("Enter the values of Process point\n");
 158            
 159             while(count<=20)
 160             {
 161            
 162            
 163            
 164             scanf("%d",&process_point);
 165            
 166             pid_init(&warm, process_point, set_point);
 167             pid_tune(&warm, p_gain,i_gain,d_gain,dead_band);
C51 COMPILER V7.04   PID                                                                   05/17/2006 17:00:59 PAGE 4   

 168             pid_setinteg(&warm,0.0); //pid_setinteg(&warm,30.0);
 169            
 170             //Get input value for process point
 171             pid_bumpless(&warm);
 172            
 173             // how to display output
 174             display_value = pid_calc(&warm); 
 175             printf("%f\n", display_value); 
 176             //printf("\n%f%f%f%f",warm.pv,warm.sp,warm.igain,warm.dgain); 
 177             count++; 
 178             
 179             } 
 180            
 181            }
 182          

C51 COMPILATION COMPLETE.  0 WARNING(S),  10 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -