Working on rewriting how we acquire data from LTC chip and sending all temp data over serial for python logging

Dependencies:   MODSERIAL mbed

Fork of TCTF_Control_Main by Rivian Irvine Team

Revision:
17:5098d8fbb298
Parent:
16:a7fd53ab4199
Child:
18:029a1283a878
--- a/main.cpp	Thu Jun 14 18:28:52 2018 +0000
+++ b/main.cpp	Fri Jun 15 00:50:47 2018 +0000
@@ -12,7 +12,7 @@
 #define DEBUG                0
 #define DEBUG1               0
 #define DEBUG2               0
-#define DEBUG3               1
+#define DEBUG3               0
 #define DEBUG5               0
 #define CHN_COUNT            8
 #define MIN_TEMP             10
@@ -432,8 +432,6 @@
     }
 }
 
-
-
 /* Function: get_temp
    **************************************************************
    Description: Retrieve data from thermistor
@@ -442,11 +440,11 @@
    Returns: the temperature of the fixture (front or back)
 */
 
-float get_temp(int chn, int port){
+float get_temp(float ADC_val){
     myled = 1;
-    ltc2487.setAddress(addrLUT[chn].adc);
+    //ltc2487.setAddress(addrLUT[chn].adc);
 
-    float ADC_val = ltc2487.readOutput(port); //(65536*1.334)/2.5
+    //float ADC_val = ltc2487.readOutput(port); //(65536*1.334)/2.5
 
     int i = 0;
 
@@ -464,11 +462,35 @@
     float m = a/b;
     float y = (m*(ADC_val-thermLUT[i].adc))+thermLUT[i].temp;
 
-    if(DEBUG2) pc.printf("DBG: CHAN: %i PORT: %i ADC VAL: %f TEMP: %f \r\n", chn, port, ADC_val, y);
+    if(DEBUG3) pc.printf("DBG: ADC VAL: %f TEMP: %f \r\n", ADC_val, y);
 
     return y;
 }
 
+void get_temp_data(){
+    //Write to all 8 channels selecting the front port to read
+    for(int chnl = 0; chnl < CHN_COUNT; chnl++){
+        ltc2487.setAddress(addrLUT[chnl].adc);
+        ltc2487.writePort(FRONT_THERM);
+    }
+    //wait until next clock cycle on LTC
+    wait(0.08);
+    for(int chnl = 0; chnl < CHN_COUNT; chnl++){
+        ltc2487.setAddress(addrLUT[chnl].adc);
+        channelTempData[chnl].currTempFront = get_temp(ltc2487.read());
+    }
+    for(int chnl = 0; chnl < CHN_COUNT; chnl++){
+        ltc2487.setAddress(addrLUT[chnl].adc);
+        ltc2487.writePort(BACK_THERM);
+    }
+    //wait until next clock cycle on LTC
+    wait(0.08);
+    for(int chnl = 0; chnl < CHN_COUNT; chnl++){
+        ltc2487.setAddress(addrLUT[chnl].adc);
+        channelTempData[chnl].currTempBack = get_temp(ltc2487.read());
+    }
+}
+
 /* Function: get_heater_current
    **************************************************************
    Description: Retrieve current into heater control MOSFET
@@ -477,7 +499,7 @@
 */
 
 float get_heater_current(int chn, int port){
-    return ltc2487.readOutput(port);
+    //return ltc2487.readOutput(port);
 }
 
 /* Function: get_valve_current
@@ -488,7 +510,7 @@
 */
 
 float get_valve_current(int chn, int port){
-    return ltc2487.readOutput(port);
+    //return ltc2487.readOutput(port);
 }
 
 /* Function: turn_valve_on
@@ -591,20 +613,19 @@
 */
 
 void test_ltc2487(int chn){
-    get_temp(chn, FRONT_THERM);
-    wait(0.1);
-    get_temp(chn, BACK_THERM);
-    wait(0.1);
-    get_temp(chn, VALVE_FET_AMP);
-    wait(0.1);
+    //get_temp(FRONT_THERM);
+    //wait(0.1);
+    //get_temp(BACK_THERM);
+    //wait(0.1);
+    //get_temp(VALVE_FET_AMP);
+    //wait(0.1);
     //if(DEBUG1) pc.printf("TEMPERATURE READING: %f \r\n", get_temp(chn));
 }
 
 //***************************************************************
 // Build packet with temperature readings to send to GUI
 //***************************************************************
-void sendTempReadings()
-{
+void sendTempReadings(){
     RESPONSE_TEMP_CMD response;
     unsigned char *ptr = (unsigned char *)&response;
     int i;
@@ -766,7 +787,7 @@
     UIDL = (uint32_t)SIM->UIDL;
 
     while(1) {
-
+        //test_mcp23008(0);
         if(DEBUG3) {
             pc.printf("DBG: <%f>[UID: %04X%08X%08X] PSTARTED\n", t.read(), UIDMH, UIDML, UIDL);
         }
@@ -783,13 +804,18 @@
         if(time_min >= 60){
            time_min = 0;
         }
+        
+        //GET TEMPERATURE DATA
+        get_temp_data();
 
         //SEND TEMPERATURE DATA FOR LOGGING
         sendTempReadings();
+        
+        time_sec = t.read();
+        pc.printf("\r TIME: %f s\r\n", time_sec);
 
         //CONTROL LOOP: LOOPS THROUGH EVERY CHANNEL AND CONTROLS THE FIXTURE IN RESPONSE
         for(int chnl = 0; chnl < CHN_COUNT; chnl++){
-            float currentTempFront = get_temp(chnl, FRONT_THERM);
 
             //check if we received data/need to update TCTF data
             if(dataReceived){
@@ -802,13 +828,13 @@
                 pc.rxBufferFlush();
             }
 
-            float currentTempBack = get_temp(chnl, BACK_THERM);
+            //update channel temperature data
+            float currentTempFront = channelTempData[chnl].currTempFront;
+            float currentTempBack = channelTempData[chnl].currTempBack;
+            
+            //float currentTempBack = get_temp(chnl, BACK_THERM);
             float currentTemp = currentTempBack;
 
-            //update channel temperature data
-            channelTempData[chnl].currTempFront = currentTempFront;
-            channelTempData[chnl].currTempBack = currentTempBack;
-
             //Error check on fixture
             error_check(chnl, currentTempFront, currentTempBack, time_min);
 
@@ -834,7 +860,7 @@
                             //read timer
                             time_sec = t_cool.read();
                             while((currentTemp > ((chnlStatus[chnl].setTemp)+HYST_HIGH)) && (time_sec < MAX_CHILL_TIME)){
-                                currentTemp = get_temp(chnl, BACK_THERM);
+                                //currentTemp = get_temp(chnl, BACK_THERM);
                                 time_sec = t_cool.read();
                                 if(DEBUG5) pc.printf("DBG: [%d] TIME: %f \r\n", chnl, time_sec);
                             }
@@ -882,7 +908,7 @@
                 turn_heater_off(chnl);
                 //turn on green LED status light
                 status_led(chnl, 1);
-            }
+                }
                 else{
                     status_led(chnl, STATUS_BAD);
                 }