6 sharps, 2 ads hooked up
Dependencies: ADS1115 BME280 CronoDot SDFileSystem mbed
Fork of Outdoor_UPAS_v1_2_Tboard by
Diff: main.cpp
- Revision:
- 8:c4a8f9b67cee
- Parent:
- 7:29b01d5812ee
- Child:
- 9:8646fd501832
--- a/main.cpp Tue Mar 01 16:59:14 2016 +0000 +++ b/main.cpp Wed Mar 02 16:49:59 2016 +0000 @@ -11,7 +11,7 @@ #include "EEPROM.h" #include "Calibration.h" //Serial pc(USBTX, USBRX); -//Serial microChannel(D0, D1); // tx, rx Appears there is a conflict in the mbed code (possibly already assigned to SERIAL_TX, SERIAL_RX, USBTX, USBRX need to reassign these values) +//Serial microChannel(USBTX, USBRX); // tx, rx Appears there is a conflict in the mbed code (possibly already assigned to SERIAL_TX, SERIAL_RX, USBTX, USBRX need to reassign these values) // However still an issue with the BLE not reading the EEPROM with the old pin assignments Jake had. Serial microChannel(D8, D2); // tx, rx //Timer t; @@ -34,9 +34,10 @@ //DigitalOut GPS_EN(p4,0); //pin 4 is used to enable and disable the GPS, in order to recive serial communications Calibration calibrations(1); //Default serial/calibration if there are no values for the selected option -Timeout stop; //This is the stop call back object +Timeout stop; //This is the stop callback object //Timeout logg; -Ticker logg; //This is the logging call back object +Ticker logg; //This is the logging callback object +Ticker flowCtl; //This is the control loop callback object uint16_t serial_num = 1; // Default serial/calibration number int RunReady =0; @@ -277,7 +278,54 @@ RGB_LED.set_led(1,0,0); } - + +void flowControl() +{ + RGB_LED.set_led(0,1,0); + omronReading = ads.readADC_SingleEnded(0, 0xC583); // read channel 0 PGA = 2 : Full Scale Range = 2.048V + omronVolt = (omronReading*4.096)/(32768*2); + + if(omronVolt<=calibrations.omronVMin) { + massflow = calibrations.omronMFMin; + } else if(omronVolt>=calibrations.omronVMax) { + massflow = calibrations.omronMFMax; + } else { + massflow = calibrations.MF4*pow(omronVolt,(float)4)+calibrations.MF3*pow(omronVolt,(float)3)+calibrations.MF2*pow(omronVolt,(float)2)+calibrations.MF1*omronVolt+calibrations.MF0; + } + + atmoRho = ((press-((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)))*100)/(287.0531*(temp+273.15))+((6.1078*pow((float)10,(float)((7.5*temp)/(237.3+temp))))*(rh/100)*100)/(461.4964*(temp+273.15)); + volflow = massflow/atmoRho; + sampledVol = sampledVol + ((((float)logInerval)/60.0)*volflow); + deltaVflow = volflow-volflowSet; + massflowSet = volflowSet*atmoRho; + deltaMflow = massflow-massflowSet; + if(abs(deltaMflow)>.025) { + digital_pot_change = (int)(gainFlow*deltaMflow); + + + if(abs(digital_pot_change)>=50) { + digital_pot_set = (int)(digital_pot_set+(int)((10.0*deltaMflow))); + //RGB_LED.set_led(1,0,0); + } else { + digital_pot_set = (digital_pot_set+ digital_pot_change); + // RGB_LED.set_led(1,1,0); + } + + if(digital_pot_set>=digitalpotMax) { + digital_pot_set = digitalpotMax; + //RGB_LED.set_led(1,0,0); + } else if(digital_pot_set<=digitalpotMin) { + digital_pot_set = digitalpotMin; + //RGB_LED.set_led(1,0,0); + } + + + DigPot.writeRegister(digital_pot_set); + + } else { + //RGB_LED.set_led(0,1,0); + } +} int main(){ //wait(10); @@ -403,6 +451,7 @@ //log_data(); stop.attach(&check_stop, 31); // check if we should shut down every 9 seconds, starting 60s after the start. logg.attach(&log_data, logInerval); + flowCtl.attach(&flowControl, 1); //** end of initalization **// @@ -414,8 +463,7 @@ // Do other things... } - //logg.attach(&log_data, 30); // uses callbacks or block Interrupts for anything that uses i2c - // while(!RTC_UPAS.compare(startAndEndTime[6], startAndEndTime[7], startAndEndTime[8], startAndEndTime[9], startAndEndTime[10], startAndEndTime[11])){ + }