REV1

Dependencies:   KellerDruck_pressure PID PWM-Coil-driver Sensirion_SF04 VL6180

Fork of TestBenchSerenity-proto_F429ZI by Ian Wolf

Committer:
iwolf32
Date:
Mon Jul 31 20:55:31 2017 +0000
Revision:
5:34584c78fbac
Parent:
4:79b23d1fbcd1
REV1;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dmwahl 0:67debf2ccbc2 1 #include "main.h"
dmwahl 0:67debf2ccbc2 2
iwolf32 5:34584c78fbac 3 //Liquid Flow Sensor Adjacent to the Pump
iwolf32 5:34584c78fbac 4 void update_flow2()
dmwahl 0:67debf2ccbc2 5 {
dmwahl 0:67debf2ccbc2 6 Timer timer;
dmwahl 0:67debf2ccbc2 7 timer.start();
dmwahl 0:67debf2ccbc2 8 char error;
dmwahl 0:67debf2ccbc2 9 while (true) {
dmwahl 0:67debf2ccbc2 10 i2c1_m.lock();
dmwahl 0:67debf2ccbc2 11 timer.reset();
iwolf32 5:34584c78fbac 12 error = mainflow.Measure(FLOW);
iwolf32 5:34584c78fbac 13 //int wait = (200 - timer.read_ms());
dmwahl 0:67debf2ccbc2 14 i2c1_m.unlock();
iwolf32 5:34584c78fbac 15 //Thread::wait(wait);
dmwahl 0:67debf2ccbc2 16 }
dmwahl 0:67debf2ccbc2 17 }
dmwahl 0:67debf2ccbc2 18
iwolf32 5:34584c78fbac 19 //High Speed Pressure Sensor
iwolf32 5:34584c78fbac 20 void highspeedpressure(){
iwolf32 5:34584c78fbac 21 while(true) {
iwolf32 5:34584c78fbac 22 High_Speed_Pressure = analog_value.read(); //
iwolf32 5:34584c78fbac 23 High_Speed_Pressure = High_Speed_Pressure*100*(14.69/8.6); // Calibrate value to 1atm
iwolf32 5:34584c78fbac 24 wait_ms(1);
iwolf32 5:34584c78fbac 25 }
dmwahl 0:67debf2ccbc2 26 }
dmwahl 0:67debf2ccbc2 27 void print_process_values()
dmwahl 0:67debf2ccbc2 28 {
dmwahl 0:67debf2ccbc2 29 //Thread::wait(100); // Wait initially to allow sensors to update, prevents a zero reading from going to serial
dmwahl 0:67debf2ccbc2 30 Timer timer;
dmwahl 0:67debf2ccbc2 31 timer.start();
dmwahl 0:67debf2ccbc2 32 while (true) {
dmwahl 0:67debf2ccbc2 33 stdio_m.lock();
dmwahl 0:67debf2ccbc2 34 timer.reset();
dmwahl 0:67debf2ccbc2 35
iwolf32 5:34584c78fbac 36 pc.printf("%0.02fpsi raw: %u %.02f\r\n",
iwolf32 5:34584c78fbac 37 High_Speed_Pressure, mainflow.flow.u16, t);
iwolf32 5:34584c78fbac 38 //pc.printf("%.0f %s (raw: %i) Temp: %.1fC Vdd: %.2f\n\r", ((float)mainflow.flow.i16 / mainflow.scaleFactor.u16), mainflow.flowUnitStr, mainflow.flow.i16, (float)mainflow.temperature.i16/10, (float)mainflow.vdd.u16/1000);
iwolf32 5:34584c78fbac 39 //int wait = 1;//(1000- timer.read_ms());
dmwahl 0:67debf2ccbc2 40 stdio_m.unlock();
iwolf32 5:34584c78fbac 41 //Thread::wait(wait);
dmwahl 0:67debf2ccbc2 42 }
dmwahl 0:67debf2ccbc2 43 }
dmwahl 0:67debf2ccbc2 44
dmwahl 0:67debf2ccbc2 45 // main() runs in its own thread in the OS
dmwahl 0:67debf2ccbc2 46 int main()
dmwahl 0:67debf2ccbc2 47 {
iwolf32 5:34584c78fbac 48 t1.start();
iwolf32 4:79b23d1fbcd1 49 //ledBlu = 1;
dmwahl 0:67debf2ccbc2 50 pc.printf("Serenity Starting up...\n\r");
iwolf32 5:34584c78fbac 51
iwolf32 5:34584c78fbac 52 //Thread to poll high speed pressure sensor
iwolf32 5:34584c78fbac 53 HighSpeedPressure.set_priority(osPriorityNormal);
iwolf32 5:34584c78fbac 54 HighSpeedPressure.start(highspeedpressure);
iwolf32 5:34584c78fbac 55
iwolf32 4:79b23d1fbcd1 56 //Thread to poll flow sensor
iwolf32 4:79b23d1fbcd1 57 update_flow2_t.set_priority(osPriorityNormal);
iwolf32 4:79b23d1fbcd1 58 update_flow2_t.start(update_flow2);
dmwahl 0:67debf2ccbc2 59
dmwahl 0:67debf2ccbc2 60 // Thread to send process values to serial port
dmwahl 0:67debf2ccbc2 61 print_process_values_t.set_priority(osPriorityLow);
dmwahl 0:67debf2ccbc2 62 print_process_values_t.start(&print_process_values);
dmwahl 0:67debf2ccbc2 63
dmwahl 0:67debf2ccbc2 64 while (true) {
iwolf32 5:34584c78fbac 65 t= t1.read_ms();
iwolf32 5:34584c78fbac 66
dmwahl 0:67debf2ccbc2 67 }
dmwahl 0:67debf2ccbc2 68 }
dmwahl 0:67debf2ccbc2 69