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:
- 18:029a1283a878
- Parent:
- 17:5098d8fbb298
- Child:
- 19:fec49ef9944b
--- a/main.cpp Fri Jun 15 00:50:47 2018 +0000 +++ b/main.cpp Fri Jun 15 18:00:58 2018 +0000 @@ -434,10 +434,9 @@ /* Function: get_temp ************************************************************** - Description: Retrieve data from thermistor - Receives: 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) + Description: Convert A/D count to temperature value + Receives: ADC_val: the count from the A/D reading + Returns: the temp. of the A/D reading */ float get_temp(float ADC_val){ @@ -467,6 +466,13 @@ return y; } +/* Function: get_temp_DATA + ************************************************************** + Description: Read A/D data from LTC2487 and set array with front and back temp. + Receives: N/A + Returns: N/A +*/ + void get_temp_data(){ //Write to all 8 channels selecting the front port to read for(int chnl = 0; chnl < CHN_COUNT; chnl++){ @@ -479,6 +485,8 @@ ltc2487.setAddress(addrLUT[chnl].adc); channelTempData[chnl].currTempFront = get_temp(ltc2487.read()); } + //wait until next clock cycle on LTC + wait(0.08); for(int chnl = 0; chnl < CHN_COUNT; chnl++){ ltc2487.setAddress(addrLUT[chnl].adc); ltc2487.writePort(BACK_THERM); @@ -499,7 +507,11 @@ */ float get_heater_current(int chn, int port){ - //return ltc2487.readOutput(port); + ltc2487.setAddress(addrLUT[chn].adc); + ltc2487.writePort(HEAT_FET_AMP); + wait(0.08); + ltc2487.read(); + wait(0.08); } /* Function: get_valve_current @@ -510,7 +522,11 @@ */ float get_valve_current(int chn, int port){ - //return ltc2487.readOutput(port); + ltc2487.setAddress(addrLUT[chn].adc); + ltc2487.writePort(VALVE_FET_AMP); + wait(0.08); + ltc2487.read(); + wait(0.08); } /* Function: turn_valve_on @@ -612,14 +628,12 @@ Returns: N/A */ -void test_ltc2487(int chn){ - //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)); +void test_ltc2487(){ + for(int chnl = 0; chnl < CHN_COUNT; chnl++){ + float frontTemp = channelTempData[chnl].currTempFront; + float backTemp = channelTempData[chnl].currTempBack; + pc.printf("TEMPERATURE READING [%i]:: BACK: %f FRONT: %f \r\n", chnl, backTemp, frontTemp); + } } //*************************************************************** @@ -838,7 +852,7 @@ //Error check on fixture error_check(chnl, currentTempFront, currentTempBack, time_min); - pc.printf("TEMPERATURE: [%d] Temp: F: %f B: %f\r\n", chnl, currentTempFront, currentTempBack); + if(DEBUG5) pc.printf("TEMPERATURE: [%d] Temp: F: %f B: %f\r\n", chnl, currentTempFront, currentTempBack); //CONTROL LOOP: if(chnlStatus[chnl].status == 1){ @@ -849,30 +863,8 @@ if(DEBUG) pc.printf("DBG: [%d] Chiller ON \r\n", chnl); //reset heater on time chnlStatus[chnl].heater_init_time = 0; - //reset cooling timer - float time_sec = 0; - //check if the temp. diff. is small and can't wait for an entire period (~4.18) to turn valve off - if(abs(currentTemp - (chnlStatus[chnl].setTemp)) < 5){ - //start timer - t_cool.start(); - //turn chiller on - turn_valve_on(chnl); - //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); - time_sec = t_cool.read(); - if(DEBUG5) pc.printf("DBG: [%d] TIME: %f \r\n", chnl, time_sec); - } - time_sec = 0; - t_cool.stop(); - t_cool.reset(); - turn_valve_off(chnl); - } - else{ - //Turn chiller on - turn_valve_on(chnl); - } + //Turn chiller on + turn_valve_on(chnl); } else if (currentTemp < ((chnlStatus[chnl].setTemp)-HYST_LOW)){ if(DEBUG) pc.printf("DBG: [%d] Heater ON \r\n", chnl); @@ -883,7 +875,7 @@ chnlStatus[chnl].heater_init_time = time_min; } } - if(DEBUG5) pc.printf("DBG: TIME ON: %d %d %f %d %d\r\n", chnlStatus[chnl].heater_init_time, time_min, time_sec, init_heat_time, (chnlStatus[chnl].heater_init_time == NULL)); + if(DEBUG2) pc.printf("DBG: TIME ON: %d %d %f %d %d\r\n", chnlStatus[chnl].heater_init_time, time_min, time_sec, init_heat_time, (chnlStatus[chnl].heater_init_time == NULL)); //Turn heater on turn_heater_on(chnl); }