Code supports writing to the SD card as well as working with the Volckens group smartphone apps for the mbed HRM1017
Dependencies: ADS1115 BLE_API BME280 Calibration CronoDot EEPROM LSM303 MCP40D17 NCP5623BMUTBG SDFileSystem SI1145 STC3100 mbed nRF51822
Fork of UPAS_BLE_and_USB by
Diff: main.cpp
- Revision:
- 55:f24d70f519cd
- Parent:
- 54:8ee11c9ecd8a
- Child:
- 56:c4d6bdd7c3fb
diff -r 8ee11c9ecd8a -r f24d70f519cd main.cpp --- a/main.cpp Sat Jun 27 18:06:21 2015 +0000 +++ b/main.cpp Mon Jun 29 14:32:04 2015 +0000 @@ -30,26 +30,25 @@ //UPAS0012 CALIBRATION TRANSFER FUNCTION COEFFICIENTS FROM 'UPAS v2 OSU-calibration primary flow data.xlsx' //mass flow sensor output signal (x) vs. mass flow (y) //y = -0.9198x4 + 4.995x3 - 9.0171x2 + 8.1039x - 2.1758 -float MF4 = -0.9507; -float MF3 = 5.1495; -float MF2 = -9.2983; -float MF1 = 8.3236; -float MF0 = -2.2377; +float MF4 = -0.6154; +float MF3 = 3.7873; +float MF2 = -7.2564; +float MF1 = 7.0202; +float MF0 = -1.9413; //Mass flow sensor polynomial deviation limits -float omronVMin = 0.435; //V -float omronVMax = 1.7997; //V -float omronMFMin = 0.013; //g/L -float omronMFMax = 2.669; //g/L +float omronVMin = 0.424; //V +float omronVMax = 1.8429; //V +float omronMFMin = 0.000; //g/L +float omronMFMax = 2.958; //g/L //DIGITAL POTENTIOSTAT dig-pot vs m_dot POLYNOMIAL TRANSFER FUNCTION COEFFICIENTS FROM 'UPAS v2 OSU-calibration primary flow data.xlsx' //y = 6.2912x4 - 56.643x3 + 195.7x2 - 329.36x + 245.2 -float DP4 = 6.0986; -float DP3 = -55.372; -float DP2 = 192.76; -float DP1 = -326.6; -float DP0 = 244.32; - +float DP4 = 5.3839; +float DP3 = -51.627; +float DP2 = 191.09; +float DP1 = -345.9; +float DP0 = 277.63; float press; float temp; @@ -76,17 +75,20 @@ float massflow; //g/min float volflow; //L/min -float volflowSet = 1 -; //L/min -int logInerval = 10; +float volflowSet = 1.0; //L/min +int logInerval = 5; float massflowSet; float deltaVflow = 0.0; float deltaMflow = 0.0; float gainFlow; float sampledVol; //L, total sampled volume -uint8_t digital_pot_setpoint; //min = 0x7F, max = 0x00 -uint8_t digital_pot_set; +int digital_pot_setpoint; //min = 0x7F, max = 0x00 +int digital_pot_set; +int digital_pot_change; +int digitalpotMax = 127; +int digitalpotMin = 2; + char filename[] = "/sd/UPAS0012LOG000000000000.txt"; SDFileSystem sd(SPIS_PSELMOSI, SPIS_PSELMISO, SPIS_PSELSCK, SPIS_PSELSS, "sd"); // I believe this matches Todd's pinout, let me know if this doesn't work. (p12, p13, p15, p14) @@ -124,19 +126,19 @@ //Digtal pot tf from file: UPAS v2 OSU-PrimaryFlowData FullSet 2015-05-29 CQ mods.xlsx digital_pot_setpoint = (int)floor(DP4*pow(massflowSet,4)+DP3*pow(massflowSet,3)+DP2*pow(massflowSet,2)+DP1*massflowSet+DP0); //min = 0x7F, max = 0x00 - if(digital_pot_setpoint>=127){ - digital_pot_setpoint = 127; + if(digital_pot_setpoint>=digitalpotMax){ + digital_pot_setpoint = digitalpotMax; } - else if(digital_pot_setpoint<=1){ - digital_pot_setpoint = 1; + else if(digital_pot_setpoint<=digitalpotMin){ + digital_pot_setpoint = digitalpotMin; } DigPot.writeRegister(digital_pot_setpoint); wait(1); blower = 1; - RTCtime = RTC.get_time(); - sprintf(filename, "/sd/UPAS0012LOG_%02d-%02d-%02d_%02d-%02d-%02d.txt",RTCtime[5],RTCtime[4],RTCtime[3],RTCtime[2],RTCtime[1],RTCtime[0]); + RTC.get_time(); + sprintf(filename, "/sd/UPAS0012LOG_%02d-%02d-%02d_%02d-%02d-%02d.txt",RTC.year,RTC.month,RTC.date,RTC.hour,RTC.minutes,RTC.seconds); FILE *fp = fopen(filename, "w"); fclose(fp); //pc.printf("%d\r\n",digital_pot_setpoint); @@ -178,11 +180,11 @@ massflowSet = volflowSet*atmoRho; deltaMflow = massflow-massflowSet; //pc.printf("%f,%f,%f,%f,%d,%u,%x\r\n",omronVolt,massflow,massflowSet,deltaMflow,digital_pot_set,digital_pot_set,digital_pot_set); - digital_pot_set = (uint8_t)(digital_pot_set+(int8_t)((gainFlow*deltaMflow))); - if(digital_pot_set>=127){ - digital_pot_set = 127; - }else if(digital_pot_set<=1){ - digital_pot_set = 1; + digital_pot_set = (int)(digital_pot_set+(int)((gainFlow*deltaMflow))); + if(digital_pot_set>=digitalpotMax){ + digital_pot_set = digitalpotMax; + }else if(digital_pot_set<=digitalpotMin){ + digital_pot_set = digitalpotMin; } wait(2); @@ -203,15 +205,15 @@ while(1) { - RTCtime = RTC.get_time(); // the way the variable RTCtime works you must save the variables in normal chars or weird things happen - Seconds = RTCtime[0];//Seconds - Minutes = RTCtime[1];//Minutes - Hour = RTCtime[2];//Hour - Date = RTCtime[3];//Date - Month = RTCtime[4];//Month - Year = RTCtime[5];//Year + RTC.get_time(); // the way the variable RTCtime works you must save the variables in normal chars or weird things happen + Seconds = RTC.seconds;//Seconds + Minutes = RTC.minutes;//Minutes + Hour = RTC.hour;//Hour + Date = RTC.date;//Date + Month = RTC.month;//Month + Year = RTC.year;//Year - secondsD = (double)RTCtime[0]; + secondsD = (double)Seconds; if(fmod(secondsD,logInerval)==0) { @@ -233,15 +235,19 @@ deltaMflow = massflow-massflowSet; if(abs(deltaMflow)>.025){ - digital_pot_set = (uint8_t)(digital_pot_set+(int8_t)(gainFlow*deltaMflow)); + digital_pot_change = (int)(gainFlow*deltaMflow); + - if(digital_pot_set>=127){ - digital_pot_set = 127; + if(abs(digital_pot_change)>=50){ RGB_LED.set_led(1,0,0); - }else if(digital_pot_set<=1){ - digital_pot_set = 1; + }else if(digital_pot_change+digital_pot_set>=digitalpotMax&abs(digital_pot_change)<50){ + digital_pot_set = digitalpotMax; + RGB_LED.set_led(1,0,0); + }else if(digital_pot_change+digital_pot_set<=digitalpotMin&abs(digital_pot_change)<50){ + digital_pot_set = digitalpotMin; RGB_LED.set_led(1,0,0); }else{ + digital_pot_set = (digital_pot_set+ digital_pot_change); RGB_LED.set_led(1,1,0);} DigPot.writeRegister(digital_pot_set);