找回密码
 注册

QQ登录

只需一步,快速开始

搜索

51单片机霍尔电机PID调速程序 lcd1602显示转速 Proteus仿真

[复制链接]
eng 发表于 2021-6-20 23:56:37 | 显示全部楼层 |阅读模式
仿真原理图如下(proteus仿真工程文件和完整单片机C源码可到本帖附件中下载)
1 (2).jpg
部分单片机源码:
  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币)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|ELEOK |网站地图

GMT+8, 2024-4-20 04:42

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表