asdf
Dependencies: KellerDruck_pressure PID PWM-Coil-driver Sensirion_SF04 VL6180
Fork of TestBenchSerenity-proto_F429ZI by
Diff: main.cpp
- Revision:
- 1:d58df8cb271d
- Parent:
- 0:67debf2ccbc2
- Child:
- 3:9ff79ea3a294
diff -r 67debf2ccbc2 -r d58df8cb271d main.cpp --- a/main.cpp Fri Jul 07 20:52:31 2017 +0000 +++ b/main.cpp Thu Jul 20 20:45:27 2017 +0000 @@ -17,10 +17,10 @@ pump.period(.001); // 1kHz PWM pump = 0; ledGrn.period(.001); - + InterruptIn pumpTach(pumpTachPin); pumpTach.rise(&pumpTachTrigger); - + pump_control_PID.setInputLimits(pumpMinPSI, pumpMaxPSI); pump_control_PID.setOutputLimits(0.0, 1.0); // Output is a PWM signal ranging from 0-1 pump_control_PID.setMode(AUTO_MODE); @@ -75,6 +75,29 @@ } } +void update_level() +{ + Timer timer; + timer.start(); + while (true) { + i2c1_m.lock(); + timer.reset(); + agentlevel = (float)level; + int wait = (1000 - timer.read_ms()); + i2c1_m.unlock(); + Thread::wait(wait); + } +} + +//float get_level() +//{ +// i2c1_m.lock(); +// float value = (float)level; +// i2c1_m.unlock(); +// return value; +//} + + void print_process_values() { //Thread::wait(100); // Wait initially to allow sensors to update, prevents a zero reading from going to serial @@ -89,8 +112,11 @@ ((float)sfm7033.flow.i16 / sfm7033.scaleFactor.u16), sfm7033.flowUnitStr, (double)pot1*18, ((double)pot2-.002)*pumpMaxPSI);*/ pc.printf("%.02fkPa %.02fpsi %.02fC %.02fF %02X %.2f%% %.0fRPM %u %.0f %s %.1f %.3f\r\n", - pumpPressure.pressureKPA, pumpPressure.pressurePSI, pumpPressure.temperatureC, pumpPressure.temperatureF, pumpPressure.status, pump.read()*100, pumpRpm, sfm7033.flow.u16, (((float)sfm7033.flow.i16 / 2) / sfm7033.scaleFactor.u16), sfm7033.flowUnitStr, (double)pot1*18, ((double)pot2)*pumpMaxPSI); + pumpPressure.pressureKPA, pumpPressure.pressurePSI, pumpPressure.temperatureC, pumpPressure.temperatureF, pumpPressure.status, pump.read()*100, pumpRpm, + sfm7033.flow.u16, (((float)sfm7033.flow.i16 / 2) / sfm7033.scaleFactor.u16), sfm7033.flowUnitStr, + (double)pot1*18, ((double)pot2)*pumpMaxPSI);//, agentlevel; int wait = (1000 - timer.read_ms()); + stdio_m.unlock(); Thread::wait(wait); } @@ -110,15 +136,37 @@ lcd.locate(0, 0); lcd.printf("%.2f slpm AA: %.1f", flow, (double)pot1*18); lcd.locate(0, 14); - lcd.printf("PV: %.0f", pumpPressure.pressurePSI); + lcd.printf("PV: %.1f", pumpPressure.pressurePSI); lcd.locate(64, 14); - lcd.printf("SV: %.0f", ((double)pot2)*pumpMaxPSI); + lcd.printf("SV: %.1f", ((double)pot2)*pumpMaxPSI); int wait = (1000 - timer.read_ms()); stdio_m.unlock(); Thread::wait(wait); } } +void update_shutoff() +{ + Timer timer; + timer.start(); + while (true) { + float threshold = 0.1; + timer.reset(); + if((double)pot1 < 0.05) { + shutoff.off(); + pc.printf("shutoff off\r\n"); + //Thread::wait(1000); + } + if((double)pot1 >= 0.1) { + shutoff.on(); + pc.printf("shutoff on\r\n"); + //Thread::wait(1000); + } + int wait = (200 - timer.read_ms()); + Thread::wait(wait); + } +} + // main() runs in its own thread in the OS int main() { @@ -129,6 +177,11 @@ pc.printf("Year: %d Month: %d Day: %d Mode: %d\r\n", pumpPressure.year, pumpPressure.month, pumpPressure.day, pumpPressure.mode); pc.printf("Status: 0x%x\r\n", pumpPressure.getStatus());*/ + + // Thread to turn shutoff valve on/off + update_shutoff_t.set_priority(osPriorityHigh); + update_shutoff_t.start(update_shutoff); + // Thread to poll pressure sensors update_pressures_t.set_priority(osPriorityNormal); update_pressures_t.start(update_pressures); @@ -137,6 +190,10 @@ update_airflow_t.set_priority(osPriorityNormal); update_airflow_t.start(update_airflow); + // Thread to poll level sensor + //update_level_t.set_priority(osPriorityIdle); + //update_level_t.start(update_level); + // Thread to update lcd update_lcd_t.set_priority(osPriorityIdle); update_lcd_t.start(update_lcd); @@ -145,10 +202,14 @@ print_process_values_t.set_priority(osPriorityLow); print_process_values_t.start(&print_process_values); - - while (true) { //pc.printf("%.02fkPa %.02fpsi %.02fC %.02fF\r\n", pumpPressure.pressureKPA, pumpPressure.pressurePSI, pumpPressure.temperatureC, pumpPressure.temperatureF); + /*shutoff.on(); + pc.printf("shutoff on\r\n"); + Thread::wait(1000); + + shutoff.off(); + pc.printf("shutoff off\r\n");*/ Thread::wait(1000); } }