国产免费AV|泡泡玛特欧洲总部将设在伦敦|中文天堂网www新版资源在线|一本久道综合在线中文|国精产品一二三产区的使用方法|香蕉鱼在线观看|www.27eee

ELEOK

標題: 51單片機霍爾電機PID調速程序 lcd1602顯示轉速 Proteus仿真 [打印本頁]

作者: eng    時間: 2021-6-20 23:56
標題: 51單片機霍爾電機PID調速程序 lcd1602顯示轉速 Proteus仿真
仿真原理圖如下(proteus仿真工程文件和完整單片機C源碼可到本帖附件中下載)

部分單片機源碼:
  1. #include "pid.h"
  2. #include "huoer.h"

  3. extern times_A,times;
  4. float PID_M_Kp =0.1382, PID_M_Ki = 0.001, PID_M_Kd =0.01; //定義 Kp、Ki、Kd 三個參數
  5. float pid_Sv;
  6. u16 PID_m_add=0,pid_pwm;

  7. float PID_current_error; //當前差值
  8. float PID_last_error; //上次差值
  9. float PID_prev_error; //上上次差值
  10. float integrality_date=0; //積分數據

  11. void Motor(u16 std_speed)
  12. {
  13.                 float P,D;//,I;//,I,D; //定義局部變量
  14.           std_speed+=120;
  15.                 PID_prev_error=PID_last_error; //更新每次的差值
  16.                 PID_last_error=PID_current_error; //更新每次的差值
  17.                 PID_current_error=std_speed-times; //更新每次的差值
  18.          
  19.           integrality_date=integrality_date+PID_current_error;
  20.                 P=PID_M_Kp*PID_current_error; //比例 P 輸出公式
  21.          // I=PID_M_Ki*integrality_date; //積分 I 輸出公式
  22.     D=PID_M_Kd*(PID_current_error-PID_last_error); //微分 D 輸出公式
  23.       
  24.                 PID_m_add=P+D;//+I;//+I+D+PID_m_add; //電機的 PID 增量值輸
  25.       
  26.                 output_pwm(PID_m_add);
  27. }

  28. void output_pwm(u16 output)
  29. {
  30.         if(output>200)output=200; //限制電機的最大速度
  31.    if(output<1)output=1;
  32.            pid_pwm = output;
  33. }

  34. /*/////////////////
  35. 60   360
  36. 420  0

  37. //////////代碼太多放不下,請到附件下載后瀏覽////////
復制代碼
完整單片機源碼和proteus仿真文件: lcd1602霍爾編碼電機.zip (85.26 KB, 售價: 5 E幣)





歡迎光臨 ELEOK (http://m.afoofa.cn/) Powered by Discuz! X5.0