|
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
1.jpg (172.82 KB, 下載次數(shù): 66)
下載附件
2021-6-19 21:56 上傳
3.jpg (31.34 KB, 下載次數(shù): 54)
下載附件
2021-6-19 21:56 上傳
4.jpg (24.7 KB, 下載次數(shù): 89)
下載附件
2021-6-19 21:56 上傳
代碼太多放不下,請(qǐng)到附件下載后瀏覽,謝謝!!!
單片機(jī)源程序如下:
- #include "pid.h"
- #include "huoer.h"
- extern times_A,times;
- float PID_M_Kp =0.1382, PID_M_Ki = 0.001, PID_M_Kd =0.01; //定義 Kp、Ki、Kd 三個(gè)參數(shù)
- float pid_Sv;
- u16 PID_m_add=0,pid_pwm;
- float PID_current_error; //當(dāng)前差值
- float PID_last_error; //上次差值
- float PID_prev_error; //上上次差值
- float integrality_date=0; //積分?jǐn)?shù)據(jù)
- void Motor(u16 std_speed)
- {
- float P,D;//,I;//,I,D; //定義局部變量
- std_speed+=120;
- PID_prev_error=PID_last_error; //更新每次的差值
- PID_last_error=PID_current_error; //更新每次的差值
- PID_current_error=std_speed-times; //更新每次的差值
-
- integrality_date=integrality_date+PID_current_error;
- P=PID_M_Kp*PID_current_error; //比例 P 輸出公式
- // I=PID_M_Ki*integrality_date; //積分 I 輸出公式
- D=PID_M_Kd*(PID_current_error-PID_last_error); //微分 D 輸出公式
-
- PID_m_add=P+D;//+I;//+I+D+PID_m_add; //電機(jī)的 PID 增量值輸
-
- output_pwm(PID_m_add);
- }
- void output_pwm(u16 output)
- {
- if(output>200)output=200; //限制電機(jī)的最大速度
- if(output<1)output=1;
- pid_pwm = output;
- }
- /*/////////////////
- 60 360
- 420 0
-
- /////////////////*/
復(fù)制代碼
51hei.png (13.19 KB, 下載次數(shù): 60)
下載附件
2021-6-20 03:34 上傳
所有資料51hei提供下載:
1602霍爾編碼電機(jī).zip
(85.26 KB, 下載次數(shù): 213)
2021-6-19 21:53 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|