找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2247|回复: 0
收起左侧

51单片机霍尔电机PID调速程序-Proteus仿真

[复制链接]
ID:850067 发表于 2021-6-19 21:54 | 显示全部楼层 |阅读模式
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
1.jpg
3.jpg
4.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. /////////////////*/
复制代码
51hei.png
所有资料51hei提供下载:
1602霍尔编码电机.zip (85.26 KB, 下载次数: 213)

评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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