內含PID控制、AD轉換、12864顯示、電機測速、控制邏輯程序
仿真原理圖如下(proteus仿真工程文件和C源碼可到本帖附件中下載)
1.png (79.6 KB)
下載附件
2021-4-21 15:39 上傳
3.png (13.82 KB)
下載附件
2021-4-21 15:40 上傳
部分源程序:完整源碼下載附件后查看
- #include <reg52.h>
- #include <intrins.h>
- #include <LCD12864.h>
- #include <ADC.h>
- #include <WORDMODEL.h>
- #include <MOTOR.h>
- #define uint unsigned int
- #define uchar unsigned char
- #include <string.h>
- uchar SOC = 0, V = 0, VOLT = 0;
- //SOC
- void display0()
- {
- SOC = vol*100/255;
- temp0 = SOC / 100;
- temp1 = (SOC % 100) / 10;
- temp2 = SOC % 10;
- show_ch1(1, 0, 4 * 6, ch1 + (12 * (temp0 + 4)));
- show_ch1(1, 0, 5 * 6, ch1 + (12 * (temp1 + 4)));
- show_ch1(1, 0, 6 * 6, ch1 + (12 * (temp2 + 4)));
- }
- //車速
- void display1()
- {
- V = vol * 192 / 255;
- temp0 = V / 100;
- temp1 = (V % 100) / 10;
- temp2 = V % 10;
- show_ch1(2, 0, 3 * 6, ch1 + (12 * (temp0 + 4)));
- show_ch1(2, 0, 4 * 6, ch1 + (12 * (temp1 + 4)));
- show_ch1(2, 0, 5 * 6, ch1 + (12 * (temp2 + 4)));
- }
- //電池電壓
- void display2()
- {
- VOLT = vol * 400 / 255;
- temp0 = VOLT / 100;
- temp1 = (VOLT % 100) / 10;
- temp2 = VOLT % 10;
- show_ch1(2, 2, 0 * 6, ch1 + (12 * (temp0 + 4)));
- show_ch1(2, 2, 1 * 6, ch1 + (12 * (temp1 + 4)));
- show_ch1(2, 2, 2 * 6, ch1 + (12 * (temp2 + 4)));
- }
- //目標制動力矩
- void display3()
- {
- targetM = vol * 200 / 255;
- D= vol * 100 / 255;
- temp0 = targetM / 100;
- temp1 = (targetM % 100) / 10;
- temp2 = targetM % 10;
- show_ch1(2, 4, 3 * 6, ch1 + (12 * (temp0 + 4)));
- show_ch1(2, 4, 4 * 6, ch1 + (12 * (temp1 + 4)));
- show_ch1(2, 4, 5 * 6, ch1 + (12 * (temp2 + 4)));
- }
- //實際制動力矩
- void display4()
- {
- // val=100;
- factM=num1/5 ;
- // val = vol * 192 / 255;
- temp0 = factM / 100;
- temp1 = (factM % 100) / 10;
- temp2 = factM % 10;
- show_ch1(2, 6, 3 * 6, ch1 + (12 * (temp0 + 4)));
- show_ch1(2, 6, 4 * 6, ch1 + (12 * (temp1 + 4)));
- show_ch1(2, 6, 5 * 6, ch1 + (12 * (temp2 + 4)));
- }
- void main()
- {
- InitLCD();
- TimeInit();
- ClearScreen(0);
- Set_line(0);
- //SOC顯示
- show_ch1(1,0,0*6,ch1+12*1);
- show_ch1(1,0,1*6,ch1+12*2);
- show_ch1(1,0,2*6,ch1+12*3);
- show_ch1(1, 0, 3 * 6, ch1 + 12 * 0);
- show_ch1(1, 0, 7 * 6, ch1 + 12 * 14);
- //車速顯示
- show_ch2(1, 0, 52, ch2 + 24 * 6);
- show_ch2(2, 0, 0 * 12, ch2 + 24 * 7);
- show_ch1(2, 0, 1 * 12, ch1 + 12 * 0);
- show_ch1(2, 0, 6*6, ch1 + 12 * 15);
- show_ch1(2, 0, 6 * 7, ch1 + 12 * 16);
- show_ch1(2, 0, 6 * 8, ch1 + 12 * 17);
- show_ch1(2, 0, 6 * 9, ch1 + 12 * 18);
- //電池電壓顯示
- show_ch2(1, 2, 0 * 14, ch2 + 24 * 12);
- show_ch2(1, 2, 1 * 14, ch2 + 24 * 13);
- show_ch2(1, 2, 2 * 14, ch2 + 24 * 14);
- show_ch2(1, 2, 3 * 14, ch2 + 24 * 15);
- show_ch1(1, 2, 4 * 14, ch1 + 12 * 0);
- show_ch1(2, 2, 6 * 3, ch1 + 12 * 21);
- //目標制動力矩顯示
- show_ch2(1, 4, 0, ch2 + 24 * 0);
- show_ch2(1, 4, 13, ch2 + 24 * 1);
- show_ch2(1, 4, 26, ch2 + 24 * 2);
- show_ch2(1, 4, 39, ch2 + 24 * 3);
- show_ch2(1, 4, 52, ch2 + 24 * 4);
- show_ch2(2, 4, 0 * 12, ch2 + 24 * 5);
- show_ch1(2, 4, 1 * 12, ch1 + 12 * 0);
- show_ch1(2, 4, 6 * 6, ch1 + 12 * 19);
- show_ch1(2, 4, 7 * 6, ch1 + 12 * 20);
- //實際制動力矩顯示
- show_ch2(1, 6, 0 , ch2 + 24 * 16);
- show_ch2(1, 6, 13, ch2 + 24 * 17);
- show_ch2(1, 6, 26, ch2 + 24 * 2);
- show_ch2(1, 6, 39, ch2 + 24 * 3);
- show_ch2(1, 6, 52, ch2 + 24 * 4);
- show_ch2(2, 6, 0 * 12, ch2 + 24 * 5);
- show_ch1(2, 6, 1 * 12, ch1 + 12 * 0);
- show_ch1(2, 6, 6 * 6, ch1 + 12 * 19);
- show_ch1(2, 6, 7 * 6, ch1 + 12 * 20);
-
- while(1)
- {
- ADDA=0;
- ADDB=0;
- ADDC=0;
- adc();
- display0();
-
- ADDA=1;
- adc();
- display1();
-
- ADDA=0;
- ADDB=1;
- adc();
- display2();
-
- ADDA=1;
- adc();
- display3();
- if (SOC>95)
- {
- targetM = 0;
- }
- if (V <20)
- {
- targetM = 0;
- }
- if (VOLT > 390)
- {
- targetM = 0;
- }
- if (targetM > 150)
- {
- targetM = 0;
- }
- else if(targetM > 100)
- {
- targetM = targetM*0.5;
- }
-
- if (time1 > 100)
- {
- time1 = 0;
- num1 = Inpluse*103/27 ;
- Inpluse = 0;
- PIDControl();
- PWM =D;
- }
- display4();
-
- }
- }
- //-------------------------------
- //定時器0
- //-------------------------------
- void Timer0(void) interrupt 1
- {
-
- // TH0 = 0XFF; //重裝初值
- // TL0 = 0X9c; //標準值
- // TL0 = 0Xb8; //包含誤差
- TH0=0XFF;
- TL0=0X37;
- time++;
- if (time >= 100) //PWM周期為100*0.1ms
- time = 0;
- if (time < PWM)
- IN01 = 1;
- else
- IN01 = 0;
- time1++; //轉速測量周期
- }
- 完整代碼見附件
復制代碼
2.png (18.72 KB)
下載附件
2021-4-21 15:39 上傳
完整仿真文件和C源碼程序:
51單片機程序和電路仿真.zip
(120.2 KB, 售價: 10 E幣)
2021-4-21 15:42 上傳
點擊文件名下載附件
售價: 10 E幣 [記錄]
[ 購買]
【必讀】版權免責聲明
1、本主題所有言論和內容純屬會員個人意見,與本論壇立場無關。2、本站對所發內容真實性、客觀性、可用性不做任何保證也不負任何責任,網友之間僅出于學習目的進行交流。3、對提供的數字內容不擁有任何權利,其版權歸原著者擁有。請勿將該數字內容進行商業交易、轉載等行為,該內容只為學習所提供,使用后發生的一切問題與本站無關。 4、本網站不保證本站提供的下載資源的準確性、安全性和完整性;同時本網站也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的損失或傷害。 5、本網站所有軟件和資料均為網友推薦收集整理而來,僅供學習用途使用,請務必下載后兩小時內刪除,禁止商用。6、如有侵犯你版權的,請及時聯系我們(電子郵箱1370723259@qq.com)指出,本站將立即改正。
|