Working on rewriting how we acquire data from LTC chip and sending all temp data over serial for python logging
Fork of TCTF_Control_Main by
Diff: main.cpp
- Revision:
- 5:0f38a0bd4f86
- Parent:
- 4:168a446bd0da
- Child:
- 6:c980535393ed
--- a/main.cpp Tue Feb 13 20:30:59 2018 +0000 +++ b/main.cpp Thu Mar 01 21:13:55 2018 +0000 @@ -10,7 +10,9 @@ //DEFINITIVE VARIABLES #define DEBUG 0 #define DEBUG1 1 -#define CHN_COUNT 48 +#define DEBUG2 1 +#define DEBUG3 1 +#define CHN_COUNT 8 #define MIN_TEMP 15 #define MAX_TEMP 60 #define HYST 0.2 @@ -34,14 +36,14 @@ }; CHNL_DATA chnlStatus[] = { - {0, NULL}, - {0, NULL}, - {0, NULL}, - {0, NULL}, - {0, NULL}, - {0, NULL}, - {0, NULL}, - {0, NULL}, + {1, 40}, + {1, 40}, + {1, 40}, + {1, 40}, + {1, 40}, + {1, 40}, + {1, 40}, + {1, 40}, {0, NULL}, {0, NULL}, {0, NULL}, @@ -264,14 +266,15 @@ ************************************************************** Description: Retrieve data from thermistor Recieves: chn: the channel of the fixture to read temp. from + port: the I/O channel to read Returns: the temperature of the fixture (front or back) */ -float get_temp(int chn){ +float get_temp(int chn, int port){ myled = 1; ltc2487.setAddress(addrLUT[chn].adc); - float ADC_val = ltc2487.readOutput(chn); //(65536*1.334)/2.5; + float ADC_val = ltc2487.readOutput(port); //(65536*1.334)/2.5 int i = 0; @@ -289,7 +292,7 @@ float m = a/b; float y = (m*(ADC_val-thermLUT[i].adc))+thermLUT[i].temp; - if(DEBUG) pc.printf("ADC VAL: %f TEMP: %f \r\n", ADC_val, y); + if(DEBUG2) pc.printf("CHNL: %i PORT: %i ADC VAL: %f TEMP: %f \r\n", chn, port, ADC_val, y); //if(chn == chnlSel) pc.printf("%f \r\n", y); @@ -418,27 +421,61 @@ */ void test_ltc2487(int chn){ - get_temp(chn); + get_temp(chn, FRONT_THERM); + wait(0.1); + //get_temp(chn, BACK_THERM); + //wait(0.1); + //get_temp(chn, VALV_FET_AMP); + //wait(0.1); //if(DEBUG1) pc.printf("TEMPERATURE READING: %f \r\n", get_temp(chn)); } +void test_all_IO(){ + test_mcp23008(0); + test_mcp23008(1); + test_mcp23008(2); + test_mcp23008(3); + test_mcp23008(4); + test_mcp23008(5); + test_mcp23008(6); + test_mcp23008(7); +} + +void test_all_ADC(){ + test_ltc2487(0); + test_ltc2487(1); + test_ltc2487(2); + test_ltc2487(3); + test_ltc2487(4); + test_ltc2487(5); + test_ltc2487(6); + test_ltc2487(7); +} int main() { - pc.baud(9600); - pc.autoDetectChar('E'); - pc.attach(&rxInterrupt, MODSERIAL::RxAutoDetect); + //pc.baud(9600); + //pc.autoDetectChar('E'); + //pc.attach(&rxInterrupt, MODSERIAL::RxAutoDetect); myled = 1; - /* + + //test_mcp23008(1); - while(1){ - test_ltc2487(1); + //FRONT_THERM, BACK_THERM, HEAT_FET_AMP, VALV_FET_AMP + /*while(1){ + myled = 0; + //test_all_ADC(); + //test_ltc2487(0); + test_all_IO(); + wait(1); + myled = 1; }*/ + while(1) { - if(DEBUG) pc.printf("THE PROGRAM STARTED \r\n"); + if(DEBUG3) pc.printf("THE PROGRAM STARTED \r\n"); //check if we recieved data/need to update TCTF data if(dataRecieved){ @@ -449,24 +486,30 @@ parseRXData(); } - for(int chnl = 0; chnl <= CHN_COUNT; chnl++){ - float currentTemp = get_temp(chnl); + for(int chnl = 0; chnl < CHN_COUNT; chnl++){ + //wait(2.5); + float currentTempFront = get_temp(chnl, FRONT_THERM); + //float currentTempBack = get_temp(chnl, BACK_THERM); //CONTROL LOOP: if(chnlStatus[chnl].status == 1){ - if(currentTemp > ((chnlStatus[chnl].setTemp)+HYST)){ + if(DEBUG3) pc.printf("TEMP: %f \r\n", currentTempFront); + if(currentTempFront > ((chnlStatus[chnl].setTemp)+HYST)){ + if(DEBUG3) pc.printf("CHILLER ON \r\n"); + //Turn heater off + //turn_heater_off(chnl); //Turn chiller on turn_valve_on(chnl); - //Turn heater off - turn_heater_off(chnl); } - else if (currentTemp < ((chnlStatus[chnl].setTemp)-HYST)){ + else if (currentTempFront < ((chnlStatus[chnl].setTemp)-HYST)){ + if(DEBUG3) pc.printf("HEATER ON \r\n"); //Turn chiller off turn_valve_off(chnl); //Turn heater on turn_heater_on(chnl); } else{ + if(DEBUG3) pc.printf("ALL OFF \r\n"); //turn off chiller turn_valve_off(chnl); //turn off heater