采用變頻器控制皮帶給料機(jī),通過調(diào)節(jié)電機(jī)轉(zhuǎn)速靈活調(diào)節(jié)給料機(jī)的給料速度,改善了給料機(jī)構(gòu)的性能;采用基于模糊控制的在線調(diào)整定量控制算法,旨在保證計(jì)量精度的前提下,盡量提高計(jì)量速度,并適應(yīng)對(duì)多種物料多種定量的包裝計(jì)量,減少物料特性變化對(duì)計(jì)量精度的影響。 1)定量包裝秤整體結(jié)構(gòu)設(shè)計(jì); 2)自動(dòng)定量包裝秤定量控制算法設(shè)計(jì); 3)基于模糊控制的在線調(diào)整定量控制優(yōu)化算法設(shè)計(jì); 4)自動(dòng)定量包裝秤模糊控制器設(shè)計(jì); 5)自動(dòng)定量包裝秤控制系統(tǒng)硬件設(shè)計(jì); 6)分不同物料、不同定量值進(jìn)行對(duì)比實(shí)驗(yàn)。
制作出來的實(shí)物圖:
接線示意圖1.jpg (4.19 MB, 下載次數(shù): 63)
下載附件
壓力傳感器設(shè)備
2018-5-10 23:44 上傳
接線示意圖 2.jpg (3.53 MB, 下載次數(shù): 57)
下載附件
矩陣鍵盤,參數(shù)設(shè)置
2018-5-10 23:43 上傳
arduino源程序如下:
- #include "HX711.h"
- #include <MsTimer2.h>
- #include<Keypad.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- int Motor = 10;
- int LED = 11;
- unsigned char Pwm_Motor = 0;
- const byte ROWS = 4;
- const byte COLS = 4;
- char hexaKeys[ROWS][COLS] = {
- {'1','2','3','A'},
- {'4','5','6','B'},
- {'7','8','9','C'},
- {'*','0','#','D'}
- };
- char key = NO_KEY;
- byte rowPins[ROWS] = {9, 8, 7, 6};
- byte colPins[COLS] = {5, 4, 3, 2};
- HX711 HX711_CH0(A0, A1, 400);
- LiquidCrystal_I2C lcd(0x27,20,4);
- long Weight[5] = {0,0,0,0,0};
- long gWeight = 0;
- unsigned char gWeight_ge = 0;
- unsigned char gWeight_shi = 0;
- unsigned char gWeight_bai = 0;
- unsigned char gWeight_qian = 0;
- long gSetWeight = 0;
- long gSetWeight_Out = 0;
- unsigned char gSetWeight_Flag = 0;
- unsigned char gSetWeight_Start = 0;
- unsigned char gSetWeight_ge = 0;
- unsigned char gSetWeight_shi = 0;
- unsigned char gSetWeight_bai = 0;
- unsigned char gSetWeight_qian = 0;
- unsigned char gIndex = 0;
- static unsigned char Tmr20msFlag = 0;
- static unsigned char gMainLoop100msCnt = 1;
- static unsigned char gMainLoop500msCnt = 2;
- static unsigned char gMainLoop1000msCnt = 3;
- static unsigned char gSchedularType = 0;
- Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
- void flash() //中斷處理函數(shù),改變燈的狀態(tài)
- {
- Tmr20msFlag = 1;
- //Serial.println("20ms");
- }
- void Task_20ms(void)
- {
- Weight[gIndex] = HX711_CH0.Get_Weight();
- if(Weight[gIndex] < 0 )Weight[gIndex] = 0;
-
- gIndex++;
- if( gIndex >= 5 ) gIndex = 0;
- //Serial.println("20ms");
- }
- void Task_100ms(void)
- {
- long lWeight = 0;
- gWeight = (Weight[0] + Weight[1] + Weight[2] + Weight[3] + Weight[4]) / 5;
- if(gSetWeight_Start == 1 )
- {
- if( gSetWeight_Out > gWeight )
- {
- lWeight = gSetWeight_Out - gWeight;
- if(lWeight > 1000 ) Pwm_Motor = 250;
- else if( lWeight > 600 ) Pwm_Motor = lWeight / 5;
- else if( lWeight > 299 ) Pwm_Motor = lWeight / 6;
- else Pwm_Motor = 40;
- analogWrite(Motor,Pwm_Motor);
- }
- else
- {
- gSetWeight_Start = 0;
- Pwm_Motor = 0;
- analogWrite(Motor,Pwm_Motor);
- }
- }
- lcd.setCursor(0, 1);
- lcd.print("GetValue: ");
- if( gWeight > 5000)
- {
- lcd.print("ERR ");
- }
- else
- {
- gWeight_ge = gWeight % 10;
- gWeight_shi = ( gWeight / 10 ) % 10;
- gWeight_bai = ( gWeight / 100 ) % 10;
- gWeight_qian = gWeight / 1000;
- lcd.print(gWeight_qian,DEC);
- lcd.print(gWeight_bai,DEC);
- lcd.print(gWeight_shi,DEC);
- lcd.print(gWeight_ge,DEC);
- }
- }
- void Task_500ms(void)
- {
- analogWrite(Motor,Pwm_Motor);
- //Serial.println("500ms
- }
- void Task_1000ms(void)
- {
- //Serial.println("1000ms");
- }
- void Task_IDLE(void)
- {
- char NewValue = 0;
- char NewValueFlag = 0;
- char SetValueFlag = 0;
- key = customKeypad.getKey();
- if (key != NO_KEY)
- {
- switch( key )
- {
- case '1': NewValue = 1; NewValueFlag = 1; break;
- case '2': NewValue = 2; NewValueFlag = 1; break;
- case '3': NewValue = 3; NewValueFlag = 1; break;
- case '4': NewValue = 4; NewValueFlag = 1; break;
- case '5': NewValue = 5; NewValueFlag = 1; break;
- case '6': NewValue = 6; NewValueFlag = 1; break;
- case '7': NewValue = 7; NewValueFlag = 1; break;
- case '8': NewValue = 8; NewValueFlag = 1; break;
- case '9': NewValue = 9; NewValueFlag = 1; break;
- case '0': NewValue = 0; NewValueFlag = 1; break;
- case 'A': break;
- case 'B': break;
- case 'C': break;
- case 'D': break;
- case '#': if(gSetWeight_Flag == 1){ gSetWeight_Start = 1; gSetWeight_Flag = 0; } break;
- case '*': SetValueFlag = 1; break;
- }
- if( 1 == NewValueFlag )
- {
- gSetWeight = gSetWeight * 10 + NewValue;
- if(gSetWeight > 9999) gSetWeight = gSetWeight % 10000;
-
- gSetWeight_ge = gSetWeight % 10;
- gSetWeight_shi = ( gSetWeight / 10 ) % 10;
- gSetWeight_bai = ( gSetWeight / 100 ) % 10;
- gSetWeight_qian = gSetWeight / 1000;
- lcd.setCursor(0, 0);
- lcd.print("SetValue: ");
- lcd.print(gSetWeight_qian,DEC);
- lcd.print(gSetWeight_bai,DEC);
- lcd.print(gSetWeight_shi,DEC);
- lcd.print(gSetWeight_ge,DEC);
- }
- if( 1 == SetValueFlag )
- {
- if(gSetWeight > 5000)
- {
- lcd.setCursor(0, 0);
- lcd.print("SetValue: ERR ");
- gSetWeight = 0;
- }
- else
- {
- lcd.setCursor(0, 0);
- lcd.print("SetValue: ");
- delay(500);
- lcd.setCursor(0, 0);
- lcd.print("SetValue:");
- gSetWeight_ge = gSetWeight % 10;
- gSetWeight_shi = ( gSetWeight / 10 ) % 10;
- gSetWeight_bai = ( gSetWeight / 100 ) % 10;
- gSetWeight_qian = gSetWeight / 1000;
- lcd.setCursor(0, 0);
- lcd.print("SetValue: ");
- lcd.print(gSetWeight_qian,DEC);
- lcd.print(gSetWeight_bai,DEC);
- lcd.print(gSetWeight_shi,DEC);
- lcd.print(gSetWeight_ge,DEC);
- delay(500);
- lcd.setCursor(0, 0);
- lcd.print("SetValue: ");
- delay(500);
- lcd.setCursor(0, 0);
- lcd.print("SetValue:");
- gSetWeight_ge = gSetWeight % 10;
- gSetWeight_shi = ( gSetWeight / 10 ) % 10;
- gSetWeight_bai = ( gSetWeight / 100 ) % 10;
- gSetWeight_qian = gSetWeight / 1000;
- lcd.setCursor(0, 0);
- lcd.print("SetValue: ");
- lcd.print(gSetWeight_qian,DEC);
- lcd.print(gSetWeight_bai,DEC);
- lcd.print(gSetWeight_shi,DEC);
- lcd.print(gSetWeight_ge,DEC);
- gSetWeight_Out = gSetWeight;
- gSetWeight_Flag = 1;
- }
- }
- }
- //Serial.println("IDLE");
- }
- void setup()
- {
- pinMode(Motor, OUTPUT);
- analogWrite(Motor,0);
- pinMode(LED, OUTPUT);
- digitalWrite(LED, HIGH);
-
- Serial.begin(115200);
- //Serial.print("Welcome to use!\n");
- HX711_CH0.begin();
- delay(1500);
-
- lcd.init();
- lcd.backlight();
- lcd.print("SetValue: XXXX g");
- lcd.setCursor(0, 1);
- lcd.print("GetValue: XXXX g");
-
- delay(1500);
- HX711_CH0.begin();
- digitalWrite(LED, HIGH);
- //Serial.print("Begin to use!\n");
- MsTimer2::set(20, flash); // 中斷設(shè)置函數(shù),每 20ms 進(jìn)入一次中斷
- MsTimer2::start(); //開始計(jì)時(shí)
- Weight[0] = Weight[1] = Weight[2] = Weight[3] = Weight[4] = 0;
-
- digitalWrite(LED, LOW);
- }
- void loop()
- {
- if(1 == Tmr20msFlag)
- {
- Tmr20msFlag = 0; Task_20ms();
-
- if(gMainLoop100msCnt <= 0) { gMainLoop100msCnt = 4; Task_100ms(); }
- else { gMainLoop100msCnt--; }
-
- if(gMainLoop500msCnt <= 0) { gMainLoop500msCnt = 24; Task_500ms(); }
- else { gMainLoop500msCnt--; }
-
- if(gMainLoop1000msCnt <= 0) { gMainLoop1000msCnt = 49; Task_1000ms();}
- else { gMainLoop1000msCnt--; }
- }
- Task_IDLE();
- }
復(fù)制代碼
0.jpg (27.02 KB, 下載次數(shù): 55)
下載附件
2018-5-11 01:29 上傳
所有資料51hei提供下載:
MyMainCode.rar
(2.95 KB, 下載次數(shù): 20)
2018-5-10 23:44 上傳
點(diǎn)擊文件名下載附件
設(shè)計(jì)實(shí)現(xiàn)代碼 下載積分: 黑幣 -5
|