LEX_Threaded_Programming

Dependencies:   Heater_V2 MODSERIAL Nanopb FastPWM ADS8568_ADC

Revision:
19:8154688252fd
Parent:
18:376350fb7ef9
Child:
20:ccbe2a03893d
diff -r 376350fb7ef9 -r 8154688252fd main.cpp
--- a/main.cpp	Mon Sep 23 15:42:13 2019 +0000
+++ b/main.cpp	Mon Sep 23 17:30:25 2019 +0000
@@ -52,7 +52,7 @@
 
 float pressure_in;
 float pressure_out;
-float pressure_set_low;
+float pressure_set_low;  // update to define pressure setpoints using variables from protobuf
 float pressure_set_high;
 
 //Heater Control
@@ -90,7 +90,7 @@
 //Threads
 Thread heater_control(osPriorityHigh);
 Thread logging_thread(osPriorityAboveNormal);
-Thread pressure_thread(osPriorityAboveNormal);
+Thread pressure_thread(osPriorityNormal);
 
 //Tickers
 Ticker heat_tick;
@@ -182,7 +182,7 @@
 
 void pressure_trigger()
 {
-    flags.set(0x3);
+    flags.set(0x4);
 }
 
 
@@ -205,12 +205,12 @@
         //Output time, R_ref, R, error, error_integrated
         pc.printf("%10d,%10d,%10.6f,%10.6f,%10.6f,%10.6f\n", heater_ID, timer.read_ms(), heater->Get_R(), heater->Get_R_ref(), pressure_in, pressure_out);
         wait_us(200);//Give other threads time to get selected
-    }
+   }
 }
 
 void pressure_control() {
     while(1){
-        flags.wait_any(0x3,osWaitForever,true);
+        flags.wait_any(0x4,osWaitForever,true);
         pressure_in = pressure_1.read();
         if (pressure_in < pressure_set_low) {
             led_1 = 1;
@@ -220,7 +220,6 @@
             led_1 = 0;
             pump = 0;
         }
-        wait_us(200);//Give other threads time to get selected
     }
 }
 
@@ -328,7 +327,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_trigger, 500000);
+    pressure_tick.attach_us(& pressure_trigger, 100000);  // update to protobuf variable
 
     pc.printf("# Waiting for signal to begin temperature control (type s or press button 0)\n");
     while (pc.getcNb()!='s' && !user_0);