<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > PID算法調(diào)節(jié)C51程序(3)

          PID算法調(diào)節(jié)C51程序(3)

          作者: 時(shí)間:2016-11-23 來(lái)源:網(wǎng)絡(luò) 收藏
          #include
            #include
            
            struct _pid {
             int pv;
             int sp;
             float integral;
             float pgain;
             float igain;
             float dgain;
             int deadband;
             int last_error;
            };
            
            struct _pid warm,*pid;
            int process_point, set_point,dead_band;
            float p_gain, i_gain, d_gain, integral_val,new_integ;;
            
            
            
            
            void pid_init(struct _pid *warm, int process_point, int set_point)
            {
             struct _pid *pid;
            
             pid = warm;
             pid->pv = process_point;
             pid->sp = set_point;
            }
            
            
            
            
            void pid_tune(struct _pid *pid, float p_gain, float i_gain, float d_gain, int dead_band)
            {
             pid->pgain = p_gain;
             pid->igain = i_gain;
             pid->dgain = d_gain;
             pid->deadband = dead_band;
             pid->integral= integral_val;
             pid->last_error=0;
            }
            
            
            void pid_setinteg(struct _pid *pid,float new_integ)
            {
             pid->integral = new_integ;
             pid->last_error = 0;
            }
            
            
            void pid_bumpless(struct _pid *pid)
            {
            
             pid->last_error = (pid->sp)-(pid->pv);
            
            }
            
            
            
            
            float pid_calc(struct _pid *pid)
            {
             int err;
             float pterm, dterm, result, ferror;
            
             err = (pid->sp) - (pid->pv);
             if (abs(err) > pid->deadband)
             {
             ferror = (float) err;
             pterm = pid->pgain * ferror;
             if (pterm > 100 || pterm < -100)
             {
             pid->integral = 0.0;
             }
             else
             {
             pid->integral += pid->igain * ferror;
             if (pid->integral > 100.0)
             {
             pid->integral = 100.0;
             }
             else if (pid->integral < 0.0) pid->integral = 0.0;
             }
             dterm = ((float)(err - pid->last_error)) * pid->dgain;
             result = pterm + pid->integral + dterm;
             }
             else result = pid->integral;
             pid->last_error = err;
             return (result);
            }
            
            
            void main(void)
            {
             float display_value;
             int count=0;
            
             pid = &warm;
            
            // printf("Enter the values of Process point, Set point, P gain, I gain, D gain ");
            // scanf("%d%d%f%f%f", &process_point, &set_point, &p_gain, &i_gain, &d_gain);
            
            
            
             process_point = 30;
             set_point = 40;
             p_gain = (float)(5.2);
             i_gain = (float)(0.77);
             d_gain = (float)(0.18);
            
            
            
             dead_band = 2;
             integral_val =(float)(0.01);
            
            
             printf("The values of Process point, Set point, P gain, I gain, D gain ");
             printf(" %6d %6d %4f %4f %4f", process_point, set_point, p_gain, i_gain, d_gain);
            
             printf("Enter the values of Process point");
            
             while(count<=20)
             {
            
            
            
             scanf("%d",&process_point);
            
             pid_init(&warm, process_point, set_point);
             pid_tune(&warm, p_gain,i_gain,d_gain,dead_band);
             pid_setinteg(&warm,0.0); //pid_setinteg(&warm,30.0);
            
             //Get input value for process point
             pid_bumpless(&warm);
            
             // how to display output
             display_value = pid_calc(&warm);
             printf("%f", display_value);
             //printf("%f%f%f%f",warm.pv,warm.sp,warm.igain,warm.dgain);
             count++;
            
             }
            
            }


          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();