/**********************************************************************//** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file TemperatureSensors.c * * @date 7-Apr-2020 * @author Dara Navaei * * @brief DG temperature sensors controller * **************************************************************************/ #include // For temperature calculation #include "TemperatureSensors.h" #include "FPGA.h" // Private variables #define PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN 16U ///< Primary heater external temperature sensors gain #define PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE 19600U ///< Primary heater external temperature sensors reference resistance #define PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE 1000U ///< Primary heater external temperature sensors zero degree resistance #define COND_SENSORS_TEMP_SENSOR_GAIN 16U ///< Conductivity sensor gain #define COND_SENSORS_TEMP_SENSOR_REF_RESISTANCE 19600U ///< Conductivity sensor reference resistance #define COND_SENSORS_TEMP_SENSOR_0_DEGREE_RESISTANCE 1000U ///< Conductivity sensor zero degree resistance #define TRIMMER_HEATER_EXT_TEMP_SENSORS_GAIN 32U ///< Trimmer heater external temperature sensors gains #define TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE 5110U ///< Trimmer heater external temperature sensors reference resistance #define TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE 100U ///< Trimmer heater external temperature sensors zero degree resistance #define TEMP_SENSORS_ADC_BITS 24U ///< External temperature sensors ADC bits #define TEMP_SENSORS_ADC_MAX_COUNT (pow(2,TEMP_SENSORS_ADC_BITS)) ///< Temperature sensors max ADC count #define TEMP_EQUATION_COEFF_A (3.9083 * pow(10,-3)) ///< ADC to temperature conversion coefficient A #define TEMP_EQUATION_COEFF_B (-5.775 * pow(10,-7)) ///< ADC to temperature conversion coefficient B #define MAX_NUM_OF_RAW_ADC_SAMPLES 20U ///< Number of ADC reads for moving average calculations #define ADC_READ_FIRST_READ_INDEX 0U ///< ADC array first ADC read index #define ADC_READ_NEXT_INDEX_INDEX 0U ///< ADC array next insertion index #define ADC_READ_RUNNING_SUM_INDEX 1U ///< ADC array running sum index #define ADC_READ_GAIN_INDEX 0U ///< ADC array gain index #define ADC_READ_REF_RESISTANCE_INDEX 1U ///< ADC array reference resistances index #define ADC_READ_0_DEG_RESISTANCE_INDEX 2U ///< ADC array zero degree resistance index #define MAX_ALLOWED_TEMP_DELTA_BETWEEN_SENSORS 2U ///< Maximum allowed temperature delta between sensors #define INPUT_PRIMARY_HEATER_TEMP_SENSOR_INDEX 0U ///< Input primary heater temperature sensor index #define OUTPUT_PRIMARY_HEATER_TEMP_SENSOR_INDEX 1U ///< Output primary heater temperature sensor index #define CONDUCTIVITY_SENSOR_1_TEMP_SENSOR_INDEX 2U ///< Conductivity sensor 1 temperature sensor index #define CONDUCTIVITY_SENSOR_2_TEMP_SENSOR_INDEX 3U ///< Conductivity sensor 2 temperature sensor index #define OUTPUT_REDUNDANCY_TEMP_SENSOR_INDEX 4U ///< Output redundancy temperature sensor index #define INPUT_DIALYSATE_TEMP_SENSOR_INDEX 5U ///< Input dialysate temperature sensor index #define PRIMARY_HEATER_INTERNAL_TEMP_SENSOR_INDEX 6U ///< Primary heater internal temperature sensor index #define TRIMMER_HEATER_INTERNAL_TEMP_SENSOR_INDEX 7U ///< Trimmer heater internal temperature sensor index /// Temperature sensor self test states typedef enum tempSensors_Self_Test_States { TEMPSENSORS_SELF_TEST_START = 0, ///< Temperature sensors self test start TEMPSENSORS_SELF_TEST_ADC_CHECK, ///< Temperature sensors self ADC check TEMPSENSORS_SELF_TEST_CONSISTENCY_CHECK, ///< Temperature sensors self test consistency check TEMPSENSORS_SELF_TEST_COMPLETE, ///< Temperature sensors self test complete NUM_OF_TEMPSENSORS_SELF_TEST_STATES ///< Total number of self test states } TEMPSENSORS_SELF_TEST_STATES_T; /// Temperature sensor exec states typedef enum tempSensors_Exec_States { TEMPSENSORS_EXEC_STATE_START = 0, ///< Temperature sensors exec start TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES, ///< Temperature sensors exec get ADC values NUM_OF_TEMPSENSORS_EXEC_STATES, ///< Total number of exec states } TEMPSENSORS_EXEC_STATES_T; static SELF_TEST_STATUS_T tempSensorsSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; ///< Self test result of the TemperatureSensors module static TEMPSENSORS_SELF_TEST_STATES_T tempSensorsSelfTestState = TEMPSENSORS_SELF_TEST_START; ///< TemperatureSensor self test state static TEMPSENSORS_EXEC_STATES_T tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; ///< TemperatureSensor exec state static U32 rawADCReads [ NUM_OF_TEMPERATURE_SENSORS ] [ MAX_NUM_OF_RAW_ADC_SAMPLES ]; ///< Number of ADC reads + the running sum static U32 runningSumAndIndex [ NUM_OF_TEMPERATURE_SENSORS ] [ 2 ]; static U32 tempSensorsConstants [ NUM_OF_TEMPERATURE_SENSORS ] [ 3 ]; static F32 avgADCReads [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors averaged ADC values // Samples array // constants array // running sum and index array static U32 sampleCount = 0; ///< Initial ADC read index until the array if filled up for the first time // Private functions prototypes static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestStart ( void ); static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestADCCheck ( void ); static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestConsistencyCheck ( void ); static TEMPSENSORS_EXEC_STATES_T handleExecStart ( void ); static TEMPSENSORS_EXEC_STATES_T handleExecGetADCValues ( void ); static F32 getADC2TempConversion ( F32 avgADC, U32 gain, U32 refResistance, U32 zeroDegResistance ); static void processADCRead ( U32 sensorIndex, U32 adc ); // Public functions /************************************************************************* * @brief initTemperatureSensors * The initTemperatureSensors function initializes the module * @details * Inputs : none * Outputs : none * @param none * @return none *************************************************************************/ void initTemperatureSensors ( void ) { U08 i; tempSensorsSelfTestResult = SELF_TEST_STATUS_IN_PROGRESS; tempSensorsSelfTestState = TEMPSENSORS_SELF_TEST_START; tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; sampleCount = 0; // Initializing the tempSensorADCReads with the reference values for ( i = 0; i < 2; i++ ) { tempSensorsConstants [ i ] [ ADC_READ_GAIN_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN; tempSensorsConstants [ i ] [ ADC_READ_REF_RESISTANCE_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; tempSensorsConstants [ i ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; } for ( i = 2; i < 4; i++ ) { tempSensorsConstants [ i ] [ ADC_READ_GAIN_INDEX ] = COND_SENSORS_TEMP_SENSOR_GAIN; tempSensorsConstants [ i ] [ ADC_READ_REF_RESISTANCE_INDEX ] = COND_SENSORS_TEMP_SENSOR_REF_RESISTANCE; tempSensorsConstants [ i ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] = COND_SENSORS_TEMP_SENSOR_0_DEGREE_RESISTANCE; } for ( i = 4; i < 6; i++ ) { tempSensorsConstants [ i ] [ ADC_READ_GAIN_INDEX ] = TRIMMER_HEATER_EXT_TEMP_SENSORS_GAIN; tempSensorsConstants [ i ] [ ADC_READ_REF_RESISTANCE_INDEX ] = TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; tempSensorsConstants [ i ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] = TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; } /*tempSensorsADCReads [ INPUT_PRIMARY_HEATER_TEMP_SENSOR_INDEX ] [ ADC_READ_GAIN_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN; tempSensorsADCReads [ INPUT_PRIMARY_HEATER_TEMP_SENSOR_INDEX ] [ ADC_READ_REF_RESISTANCE_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; tempSensorsADCReads [ INPUT_PRIMARY_HEATER_TEMP_SENSOR_INDEX ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; tempSensorsADCReads [ OUTPUT_PRIMARY_HEATER_TEMP_SENSOR_INDEX ] [ ADC_READ_GAIN_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN; tempSensorsADCReads [ OUTPUT_PRIMARY_HEATER_TEMP_SENSOR_INDEX ] [ ADC_READ_REF_RESISTANCE_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; tempSensorsADCReads [ OUTPUT_PRIMARY_HEATER_TEMP_SENSOR_INDEX ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; tempSensorsADCReads [ CONDUCTIVITY_SENSOR_1_TEMP_SENSOR_INDEX ] [ ADC_READ_GAIN_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN; tempSensorsADCReads [ CONDUCTIVITY_SENSOR_1_TEMP_SENSOR_INDEX ] [ ADC_READ_REF_RESISTANCE_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; tempSensorsADCReads [ CONDUCTIVITY_SENSOR_1_TEMP_SENSOR_INDEX ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; tempSensorsADCReads [ CONDUCTIVITY_SENSOR_2_TEMP_SENSOR_INDEX ] [ ADC_READ_GAIN_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN; tempSensorsADCReads [ CONDUCTIVITY_SENSOR_2_TEMP_SENSOR_INDEX ] [ ADC_READ_REF_RESISTANCE_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; tempSensorsADCReads [ CONDUCTIVITY_SENSOR_2_TEMP_SENSOR_INDEX ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] = PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; tempSensorsRawADCReads [ OUTPUT_REDUNDANCY_TEMP_SENSOR_INDEX ] [ ADC_READ_GAIN_INDEX ] = TRIMMER_HEATER_EXT_TEMP_SENSORS_GAIN; tempSensorsRawADCReads [ OUTPUT_REDUNDANCY_TEMP_SENSOR_INDEX ] [ ADC_READ_REF_RESISTANCE_INDEX ] = TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; tempSensorsRawADCReads [ OUTPUT_REDUNDANCY_TEMP_SENSOR_INDEX ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] = TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; tempSensorsRawADCReads [ INPUT_DIALYSATE_TEMP_SENSOR_INDEX ] [ ADC_READ_GAIN_INDEX ] = TRIMMER_HEATER_EXT_TEMP_SENSORS_GAIN; tempSensorsRawADCReads [ INPUT_DIALYSATE_TEMP_SENSOR_INDEX ] [ ADC_READ_REF_RESISTANCE_INDEX ] = TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; tempSensorsRawADCReads [ INPUT_DIALYSATE_TEMP_SENSOR_INDEX ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] = TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE; tempSensorsRawADCReads [ PRIMARY_HEATER_INTERNAL_TEMP_SENSOR_INDEX ] [ ADC_READ_GAIN_INDEX ] = 0; tempSensorsRawADCReads [ PRIMARY_HEATER_INTERNAL_TEMP_SENSOR_INDEX ] [ ADC_READ_REF_RESISTANCE_INDEX ] = 0; tempSensorsRawADCReads [ PRIMARY_HEATER_INTERNAL_TEMP_SENSOR_INDEX ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] = 0; tempSensorsRawADCReads [ TRIMMER_HEATER_INTERNAL_TEMP_SENSOR_INDEX ] [ ADC_READ_GAIN_INDEX ] = 0; tempSensorsRawADCReads [ TRIMMER_HEATER_INTERNAL_TEMP_SENSOR_INDEX ] [ ADC_READ_REF_RESISTANCE_INDEX ] = 0; tempSensorsRawADCReads [ TRIMMER_HEATER_INTERNAL_TEMP_SENSOR_INDEX ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] = 0;*/ } /************************************************************************* * @brief execTemperatureSensorsSelfTest * The execTemperatureSensorsSelfTest function runs the TemperatureSensors * POST during the self test * @details * Inputs : none * Outputs : SELF_TEST_STATUS_T * @param none * @return SELF_TEST_STATUS_T *************************************************************************/ SELF_TEST_STATUS_T execTemperatureSensorsSelfTest ( void ) { switch ( tempSensorsSelfTestState ) { case TEMPSENSORS_SELF_TEST_START: tempSensorsSelfTestState = handleSelfTestStart(); break; case TEMPSENSORS_SELF_TEST_ADC_CHECK: tempSensorsSelfTestState = handleSelfTestADCCheck(); break; case TEMPSENSORS_SELF_TEST_CONSISTENCY_CHECK: tempSensorsSelfTestState = handleSelfTestConsistencyCheck(); break; case TEMPSENSORS_SELF_TEST_COMPLETE: // Done with self test, do nothing break; default: SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_TEMPERATURE_SENSORS_INVALID_SELF_TEST_STATE, tempSensorsSelfTestState ); tempSensorsSelfTestState = TEMPSENSORS_SELF_TEST_COMPLETE; break; } return tempSensorsSelfTestResult; } /************************************************************************* * @brief execTemperatureSensors * The execTemperatureSensors function runs the TemperatureSensors main * tasks * @details * Inputs : none * Outputs : none * @param none * @return none *************************************************************************/ void execTemperatureSensors ( void ) { // read the sensors all the time switch ( tempSensorsExecState ) { case TEMPSENSORS_SELF_TEST_START: tempSensorsExecState = handleExecStart(); break; case TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES: tempSensorsExecState = handleExecGetADCValues(); break; default: SET_ALARM_WITH_2_U32_DATA ( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_TEMPERATURE_SENSORS_EXEC_INVALID_STATE, tempSensorsExecState ); tempSensorsExecState = TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; break; } } F32 getTPiTemperatureValue ( void ) { F32 adc = avgADCReads [ INPUT_PRIMARY_HEATER_TEMP_SENSOR_INDEX ]; F32 temperature = getADC2TempConversion ( adc, PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN, PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE, PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE ); return temperature; } // Private functions /************************************************************************* * @brief getADC2TempConversion * The getADC2TempConversion function calculates the temperature from * ADC read from FPGA * @details * Inputs : U32 (adc, gain, refResistance) * Outputs : F32 (temperature in deg C) * @param none * @return F32 (temperature in deg C) *************************************************************************/ static F32 getADC2TempConversion ( F32 avgADC, U32 gain, U32 refResistance, U32 zeroDegResistance ) { //R(RTD) = R(ref) * (adc – 2^N-1) / (G *2^N-1); F32 resistance = (refResistance * (avgADC - pow(2,(TEMP_SENSORS_ADC_BITS - 1)))) / (gain * pow(2,(TEMP_SENSORS_ADC_BITS - 1))); // For testing in a separate workspace, loop through and do the equation, disable Irq and Fiq and enable Irq and // get the mstimer() //T=(-A+√(A^2-4B(1-R_T/R_0 )))/2B F32 secondSqrtPart = 4 * TEMP_EQUATION_COEFF_B * (1 - (resistance / zeroDegResistance)); F32 temperature = (-TEMP_EQUATION_COEFF_A + sqrt(pow(TEMP_EQUATION_COEFF_A, 2) - secondSqrtPart)) / (2 * TEMP_EQUATION_COEFF_B); return temperature; } /************************************************************************* * @brief processADCRead * The processADCRead function receives the ADC value and the sensor * index and calculates the running sum and the moving average of the ADCs * The temperatureSensorsADCRead and tempSensorsAvgADCValues are updated * @details * Inputs : U32 (sensorIndex, adc) * Outputs : none * @param none * @return none *************************************************************************/ static void processADCRead ( U32 sensorIndex, U32 adc ) { U32 index = runningSumAndIndex [ sensorIndex ] [ ADC_READ_NEXT_INDEX_INDEX ]; U32 runningSum = runningSumAndIndex [ sensorIndex ] [ ADC_READ_RUNNING_SUM_INDEX ]; U32 indexValue = rawADCReads [ sensorIndex ] [ index ]; U32 nextIndex = INC_WRAP( index, ADC_READ_FIRST_READ_INDEX, MAX_NUM_OF_RAW_ADC_SAMPLES - 1 ); runningSum = runningSum - indexValue + adc; rawADCReads [ sensorIndex ] [ index ] = adc; runningSumAndIndex [ sensorIndex ] [ ADC_READ_NEXT_INDEX_INDEX ] = nextIndex; runningSumAndIndex [ sensorIndex ] [ ADC_READ_RUNNING_SUM_INDEX ] = runningSum; if ( sampleCount < MAX_NUM_OF_RAW_ADC_SAMPLES ) { sampleCount++; } else { sampleCount = MAX_NUM_OF_RAW_ADC_SAMPLES; } // TODO Remove this code FOR TESTING F32 test = runningSum / sampleCount; // TODO Remove this code FOR TESTING avgADCReads [ sensorIndex ] = runningSum / sampleCount; } /************************************************************************* * @brief handleSelfTestStart * The handleSelfTestStart function waits for the ADC read array to be * filled up for the first time. It then sets the state to next state * @details * Inputs : none * Outputs : state (TEMPSENSORS_SELF_TEST_STATES_T) * @param none * @return state (TEMPSENSORS_SELF_TEST_STATES_T) *************************************************************************/ static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestStart ( void ) { return TEMPSENSORS_SELF_TEST_START; } /************************************************************************* * @brief handleSelfTestADCCheck * The handleSelfTestADCCheck function checks whether the ADC reads. If the * reads are above the maximum 24bit ADC count, it will throw an alarm and * switches to the next state * @details * Inputs : none * Outputs : state (TEMPSENSORS_SELF_TEST_STATES_T) * @param none * @return state (TEMPSENSORS_SELF_TEST_STATES_T) *************************************************************************/ static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestADCCheck ( void ) { TEMPSENSORS_SELF_TEST_STATES_T state = TEMPSENSORS_SELF_TEST_CONSISTENCY_CHECK; U08 i; for ( i = 0; i < sizeof(avgADCReads); i++ ) { U32 avgADC = avgADCReads [ i ]; if ( avgADC > TEMP_SENSORS_ADC_MAX_COUNT ) { //TODO error for ADC out of range } } return state; } /************************************************************************* * @brief handleSelfTestConsistencyCheck * The handleSelfTestConsistencyCheck function checks the values of the * sensors to make sure they are within the allowed range from each other * @details * Inputs : none * Outputs : state (TEMPSENSORS_SELF_TEST_STATES_T) * @param none * @return state (TEMPSENSORS_SELF_TEST_STATES_T) *************************************************************************/ static TEMPSENSORS_SELF_TEST_STATES_T handleSelfTestConsistencyCheck ( void ) { //TODO Consider edge cases for the consistency check TEMPSENSORS_SELF_TEST_STATES_T state = TEMPSENSORS_SELF_TEST_COMPLETE; U32 largestDelta; U08 i, j, k; F32 tempBuffer [ NUM_OF_TEMPERATURE_SENSORS ]; F32 temperature; for ( k = 0; k < sizeof(tempBuffer); k++) { temperature = getADC2TempConversion ( avgADCReads [ k ], tempSensorsConstants [ k ] [ ADC_READ_GAIN_INDEX ], tempSensorsConstants [ k ] [ ADC_READ_REF_RESISTANCE_INDEX ], tempSensorsConstants [ k ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] ); tempBuffer [ k ] = temperature; } for ( i = 0; i < sizeof(tempBuffer); i++ ) { for ( j = 0; j < sizeof(tempBuffer); j++ ) { if ( i != j ) { largestDelta = MAX( largestDelta, fabs(tempBuffer [ i ] - tempBuffer [ j ]) ); } if ( largestDelta > MAX_ALLOWED_TEMP_DELTA_BETWEEN_SENSORS ) { // TODO Error } } } return state; } /************************************************************************* * @brief handleExecStart * The handleExecStart function switches the state to read * @details * Inputs : none * Outputs : state (TEMPSENSORS_EXEC_STATES_T) * @param none * @return state (TEMPSENSORS_EXEC_STATES_T) *************************************************************************/ static TEMPSENSORS_EXEC_STATES_T handleExecStart ( void ) { TEMPSENSORS_EXEC_STATES_T state = TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; // TODO FOR TESTING, REMOVE THIS CODE /*if ( tempSensorsSelfTestState == TEMPSENSORS_SELF_TEST_COMPLETE ) { U32 testADC = 16327313; //F32 temp = getADC2TempConversion ( testADC, TRIMMER_HEATER_EXT_TEMP_SENSORS_GAIN, TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE, // TRIMMER_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE); F32 temp = getADC2TempConversion ( testADC, PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN, PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE, PRIMARY_HEATER_EXT_TEMP_SENSORS_0_DEGREE_RESISTANCE); state = TEMPSENSORS_EXEC_STATE_READ_SENSORS; }*/ // TODO REMOVE THE ABOVE CODE return state; } /************************************************************************* * @brief handleExecGetADCValues * The handleExecGetADCValues function reads the ADC values from FPGA * @details * Inputs : none * Outputs : state (TEMPSENSORS_EXEC_STATES_T) * @param none * @return state (TEMPSENSORS_EXEC_STATES_T) *************************************************************************/ static TEMPSENSORS_EXEC_STATES_T handleExecGetADCValues ( void ) { TEMPSENSORS_EXEC_STATES_T state = TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; // Check the read count for a change before inserting // Need to remember the fpga counter and if it has not changed increment another counter and // zero it if it changed. if it is above a certain number throw fault // error counter from fpga same as above remember, if it is incremented: // // Look at the error counter and the specific error flag to make sure the error is a temp sensor // Add a byte array to have bits for each sensor to find out exactly what sensor failed processADCRead( INPUT_PRIMARY_HEATER_TEMP_SENSOR_INDEX, getFPGATPiTemp() ); processADCRead( OUTPUT_PRIMARY_HEATER_TEMP_SENSOR_INDEX, getFPGATPoTemp() ); // TODO Updated the get functions from FPGA processADCRead( CONDUCTIVITY_SENSOR_1_TEMP_SENSOR_INDEX, getFPGATPoTemp() ); processADCRead( CONDUCTIVITY_SENSOR_2_TEMP_SENSOR_INDEX, getFPGATPoTemp() ); processADCRead( OUTPUT_REDUNDANCY_TEMP_SENSOR_INDEX, getFPGATPoTemp() ); processADCRead( INPUT_DIALYSATE_TEMP_SENSOR_INDEX, getFPGATPoTemp() ); processADCRead( PRIMARY_HEATER_INTERNAL_TEMP_SENSOR_INDEX, getFPGATPoTemp() ); processADCRead( TRIMMER_HEATER_INTERNAL_TEMP_SENSOR_INDEX, getFPGATPoTemp() ); // TODO REMOVE THIS CODE. FOR TESTING ONLY U32 test [20] = {16327313, 16330313, 16333313, 16336313, 16339313, 16342313, 16345313, 16348313, 16351313, 16354313, 16357313, 16360313, 16363313, 16366313, 16369313, 16372313, 16375313, 16378313, 16381313, 16384313}; U08 i; for ( i = 0; i