LEX_Threaded_Programming

Dependencies:   Heater_V2 MODSERIAL Nanopb FastPWM ADS8568_ADC

Revision:
32:c825071486eb
Parent:
31:09d2f3e4ed99
Child:
35:aa35c6325dac
--- a/main.cpp	Mon Nov 18 13:49:01 2019 +0000
+++ b/main.cpp	Mon Nov 18 17:50:49 2019 +0000
@@ -54,8 +54,8 @@
 DigitalOut valve_0(PA_5);
 DigitalOut valve_1(PA_6);
 
-float pressure_in;
-float pressure_out;
+float pressure_in = 0.1;   // 0.1 - 0.9 corresponds to 0 - 15psi
+float pressure_out = 0.1;
 
 //Heater Control
 FastPWM drive_1(PC_9);
@@ -203,6 +203,19 @@
 {
     while(1){
         flags.wait_any(0x2,osWaitForever,true);
+        
+        //Read and control pressure
+        pressure_in  = pressure_in  * PRESSURE_SMOOTH_FACTOR + (1 - PRESSURE_SMOOTH_FACTOR) * pressure_1.read();
+        pressure_out = pressure_out * PRESSURE_SMOOTH_FACTOR + (1 - PRESSURE_SMOOTH_FACTOR) * pressure_0.read();
+        if (pressure_in < exp_config.fluidics.pressure_sensor_setpoint_adc - exp_config.fluidics.pressure_sensor_hysteresis_adc) {
+            led_1 = 1;
+            pump = 1;
+        }
+        else if (pressure_in > exp_config.fluidics.pressure_sensor_setpoint_adc) {
+            led_1 = 0;
+            pump = 0;
+        }
+
         //Output time, R_avg, R_ref, R_var, error, error_integrated, duty cycle, input pressure, output pressure
         pc.printf("%10d,%10d,%10.6f,%10.6f,%10.6f,%10.6f,%10.6f,%10.6f,%10.6f,%10.6f\n", 
             heater_ID, timer.read_ms(), heater->Get_R_avg(), heater->Get_R_ref(), heater->Get_R_var(), heater->Get_error(), heater->Get_error_integrated(), heater->Get_D(), pressure_in, pressure_out);
@@ -267,11 +280,11 @@
     float drive_cal_a, drive_cal_b;
     
     // turn off pump and valves and LED drive
-    pump = 0;
-    valve_0 = 0;
-    valve_1 = 0;
-    camTrigger = 0;
-    ledDrive = 0;
+ //   pump = 0;
+ //   valve_0 = 0;
+ //   valve_1 = 0;
+ //   camTrigger = 0;
+ //   ledDrive = 0;
         
     pc.baud(115200);
     adc.init();
@@ -332,7 +345,7 @@
     while (pc.getcNb()!='p' && !user_0);
     pc.printf("# Pressure control start signal received\n");
     //pressure_thread.start(& pressure_control);
-    pressure_tick.attach_us(& pressure_control, exp_config.fluidics.pressure_control_loop_interval_ms * 1000); 
+    //pressure_tick.attach_us(& pressure_control, exp_config.fluidics.pressure_control_loop_interval_ms * 1000); 
 
     //Start logging
     logging_thread.start(& log_state);
@@ -348,7 +361,7 @@
     heat_tick.attach_us(& temp_trigger,exp_config.thermal.thermal_control_loop_interval_ms * 1000);  
 
     pc.printf("# Starting routine on drive board: %d\n",drive_board_serial_number[i_board]);
-    pc.printf("heater id, time (ms), R_avg (Ohm), R_set (Ohm), R (Ohm), Err (Ohm), Err_int (Ohm.ms), Duty cycle, P1 (ADC), P2 (ADC)\n");
+    pc.printf("heater id, time (ms), R_avg (Ohm), R_set (Ohm), R_var (Ohm), Err (Ohm), Err_int (Ohm.ms), Duty cycle, P0 (ADC), P1 (ADC)\n");
     timer.start();
     set_point_routine(profile);