采用变频器控制皮带给料机,通过调节电机转速灵活调节给料机的给料速度,改善了给料机构的性能;采用基于模糊控制的在线调整定量控制算法,旨在保证计量精度的前提下,尽量提高计量速度,并适应对多种物料多种定量的包装计量,减少物料特性变化对计量精度的影响。 1)定量包装秤整体结构设计; 2)自动定量包装秤定量控制算法设计; 3)基于模糊控制的在线调整定量控制优化算法设计; 4)自动定量包装秤模糊控制器设计; 5)自动定量包装秤控制系统硬件设计; 6)分不同物料、不同定量值进行对比实验。
制作出来的实物图:
压力传感器设备
矩阵键盘,参数设置
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() //中断处理函数,改变灯的状态
- {
- 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); // 中断设置函数,每 20ms 进入一次中断
- MsTimer2::start(); //开始计时
- 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();
- }
复制代码
所有资料51hei提供下载:
MyMainCode.rar
(2.95 KB, 下载次数: 20)
|