Rev0
Dependencies: PID QEI-Intruptinmode-set SB1602E mbed
Fork of PreHeater-Rev2 by
プリヒータ基板のファームウェアです。 Rev2基板用ですので、温度センサーなどが変更になっています。
This is Pre Heater device firmware. This firmware is Rev2 PCB design.
Diff: main.cpp
- Revision:
- 1:1440321bc326
- Parent:
- 0:b2cea429ec0b
- Child:
- 2:6315824f8a29
--- a/main.cpp Fri Jul 24 18:08:18 2015 +0000 +++ b/main.cpp Tue Jul 28 18:59:40 2015 +0000 @@ -32,17 +32,17 @@ //GPIO initilaize AnalogIn THAI(dp4); PwmOut out(dp18); -DigitalOut ledR(dp17),ledG(dp25),ledB(dp27); +DigitalOut ledR(dp17),ledG(dp25),ledB(dp26); InterruptIn RunPB(dp10); Serial pc(dp16, dp15); // tx, rx /* PID constant initialize Kc, Ti, Td, interval */ -#define P 0.1 //propotional band -#define I 1.5 //Integral -#define D 1.0 //Devide +#define P 1.5 //propotional band +#define I 50.0 //Integral +#define D 0.5 //Devide #define RATE 0.1 //update time sec -#define InitialSP 30.0 // Boot Setpoint initial temeprature +//#define InitialSP 45.0 // Boot Setpoint initial temeprature PID TIC(P, I, D, RATE); /*LCD I2C pin initialize */ @@ -50,13 +50,16 @@ SB1602E lcd(dp5, dp27, init_massage); // SDA, SCL /*QEI initialize */ #define ROTATE_PER_REVOLUTIONS 24 -QEI wheel(dp13, dp11, NC, ROTATE_PER_REVOLUTIONS, QEI::X2_ENCODING); +QEI wheel(dp11, dp13, NC, PullUp, ROTATE_PER_REVOLUTIONS, QEI::X2_ENCODING); //Initial -float temp_sv_input = InitialSP, waittime,OV_LL,ticout,qei,Bias; +float temp_sv_input, waittime,OV_LL,ticout,qei,Bias; bool Run(false); double temp_pv,temp_cal; int rtostime; +int encPulseCnt = 0; +int encPulses = 0; +int end_getPulses_old = 0; /*PB control*/ void runmode() @@ -69,14 +72,28 @@ while(1) { /*input for change to 0 to 100% range by 30C to 120C */ /*Temperature setpoint low high range */ -#define RangeSPL 30.0 //Celcius low side temperature - temp_sv_input = wheel.getPulses() / 20.0 + RangeSPL; - if (temp_sv_input <= RangeSPL) { - temp_sv_input = RangeSPL; -#define RangeSPH 100.0 //Celcius high side temperature - } else if (temp_sv_input >= RangeSPH) { - temp_sv_input = RangeSPH; +#define RangeSPL 45.0 //Celcius low side temperature +#define EncoderDiv 25.0 +#define RangeSPH 100.0 //Celcius high side temperature + + encPulses = wheel.getPulses(); + if(end_getPulses_old != encPulses) + { + encPulseCnt = encPulseCnt + (encPulses - end_getPulses_old); + + if( encPulseCnt < 0 ) + { + encPulseCnt = 0; + } + if( encPulseCnt > ( (RangeSPH-RangeSPL) * EncoderDiv) ) + { + encPulseCnt = (RangeSPH-RangeSPL) * EncoderDiv; + } } + end_getPulses_old = encPulses; + + + temp_sv_input = encPulseCnt / EncoderDiv + RangeSPL; /*six order polynomial calculation value Thermister pull up resiter 560R @@ -84,15 +101,29 @@ Thermister Resistance 10K ohm at 25C This NTC is NCP18XH103F03RB muRata */ - temp_cal = THAI.read() * 3.3; - temp_pv =-0.7964*pow(temp_cal,6.0) - 2.5431*pow(temp_cal,5.0) +63.605*pow(temp_cal,4.0) - 274.1*pow(temp_cal,3.0) + 522.57*pow(temp_cal,2.0) - 539.26*temp_cal + 405.76; + //temp_cal = THAI.read() * 3.3; + //temp_pv =-0.7964*pow(temp_cal,6.0) - 2.5431*pow(temp_cal,5.0) +63.605*pow(temp_cal,4.0) - 274.1*pow(temp_cal,3.0) + 522.57*pow(temp_cal,2.0) - 539.26*temp_cal + 405.76; + + /*LM26LVCISDX-115 Factory Preset Temperature Switch and Temperature Sensor Gain3 115C trip sensor calculation value.*/ + temp_cal = THAI.read() * 3300; + temp_pv = -0.00000000007*pow(temp_cal,3.0)-0.000002*pow(temp_cal,2.0)-0.091*temp_cal+201.5; /*LCD Display section */ /*LCD Display section */ - lcd.printf(0, "SP %.1f", temp_sv_input); - lcd.printf(0, "PV %.1f\n", temp_pv); - lcd.printf(1, "OUT %.2f", out.read() * 100); - lcd.printf(1, "PB %s\n", Run); + lcd.printf(0,0, "SP %.1f", temp_sv_input); + lcd.printf(0,1, "PV %.1f\n", temp_pv); + //lcd.printf(1, "OUT %.2f", out.read() * 100); + //lcd.printf(1, "PB %s\n", Run); + printf("\033[1;1H"); + printf("OUT %.6f", out.read() * 100); + printf("\033[1;20H"); + printf("PB %s\n", Run); + printf("\033[2;1H"); + printf("PV %.6f\n", temp_pv); + printf("\033[2;20H"); + printf("SP %.6f", temp_sv_input); + printf("\033[3;1H"); + printf("PV %.6f\n", THAI.read()); /*Tenperature indicater */ /* 1.5C high temperature */ if (Run == true) { @@ -116,7 +147,7 @@ ledG = 1; ledB = 1; } - Thread::wait(rtostime * 2); + Thread::wait(rtostime * 1); } }