Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r2496e9225fa1b2c627d625def02515a0f0dd5793 -ra3b108c205e9bcd4d1a45033d73c5714c7247123 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 2496e9225fa1b2c627d625def02515a0f0dd5793) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision a3b108c205e9bcd4d1a45033d73c5714c7247123) @@ -17,11 +17,14 @@ #include "TemperatureSensors.h" #include "FPGA.h" +#include "SystemCommMessages.h" // TODO: For testing only REMOVE #include "Timers.h" // TODO: For testing only REMOVE +//TODO change the incoming water for ranges + // Private variables #define PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN 16U ///< Primary heater external temperature sensors gain @@ -55,11 +58,11 @@ #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 READ_AND_ERROR_PREV_FPGA_COUNT_INDEX 0U -#define READ_AND_ERROR_INTERNAL_READ_COUNT_INDEX 1U -#define READ_AND_ERROR_INTERNAL_ERROR_COUNT_INDEX 2U -#define READ_AND_ERROR_PREV_FPGA_ERROR_INDEX 3U -#define NUM_OF_READ_AND_ERROR_ARRAY_COLUMNS 4U +#define READ_AND_ERROR_PREV_FPGA_COUNT_INDEX 0U ///< Read and error previous FPGA count index +#define READ_AND_ERROR_INTERNAL_READ_COUNT_INDEX 1U ///< Read and error internal read count index +#define READ_AND_ERROR_INTERNAL_ERROR_COUNT_INDEX 2U ///< Read and error internal error count index +#define READ_AND_ERROR_PREV_FPGA_ERROR_INDEX 3U ///< Read and error previous FPGA error index +#define NUM_OF_READ_AND_ERROR_ARRAY_COLUMNS 4U ///< Number of read and error array columns #define MAX_ALLOWED_TEMP_DELTA_BETWEEN_SENSORS 2U ///< Maximum allowed temperature delta between sensors @@ -68,9 +71,8 @@ #define MAX_ALLOWED_UNCHANGED_ADC_READS 4U ///< Maximum number of times that the read of a sensor cannot change -#define EXTERNAL_TEMP_SENSORS_ERROR_VALUE 0x80 -#define HEATERS_INTERNAL_TEMP_SENSOR_FAULT 0x01 -#define MASK_OFF_U32_MSB 0x00FFFFFF +#define EXTERNAL_TEMP_SENSORS_ERROR_VALUE 0x80 ///< External temperature sensors error value +#define HEATERS_INTERNAL_TEMP_SENSOR_FAULT 0x01 ///< Heaters internal temperature sensor fault /// Temperature sensor self test states typedef enum tempSensors_Self_Test_States @@ -91,19 +93,6 @@ } TEMPSENSORS_EXEC_STATES_T; /// FPGA error and read counts -typedef struct -{ - U08 RTDErrorCount; ///< RTD error count (include all 4 conductivity and temperature sensors) - U08 RTDReadCount; ///< RTD read count (include all 4 conductivity and temperature sensors) - U08 TRoErrorCount; ///< THDo (outlet redundant temperature sensor) error count - U08 TRoReadCount; ///< THDo (outlet redundant temperature sensor) read count - U08 TDiErrorCount; ///< TDi (inlet dialysate) temperature sensor error count - U08 TDiReadCount; ///< TDi (inlet dialysate) temperature sensor read count - U08 primaryHeaterFlags; ///< Primary heater internal temperature sensor error flags - U08 primaryHeaterReadCount; ///< Primary heater internal temperature sensor read count - U08 trimmerHeaterFlags; ///< Trimmer heater internal temperature sensor error flags - U08 trimmerHeaterReadCount; ///< Trimmer heater internal temperature sensor read count -} FPGA_READ_AND_ERROR_COUNTS_T; // TODO REmove static SELF_TEST_STATUS_T tempSensorsSelfTestResult; ///< Self test result of the TemperatureSensors module static TEMPSENSORS_SELF_TEST_STATES_T tempSensorsSelfTestState; ///< TemperatureSensor self test state @@ -117,7 +106,8 @@ [ NUM_OF_TEMP_SENSORS_CONSTANTS_ARRAY_COLUMNS ]; static F32 avgADCReads [ NUM_OF_TEMPERATURE_SENSORS ]; //TODO remove ///< Temperature sensors averaged ADC values static F32 temperatureValues [ NUM_OF_TEMPERATURE_SENSORS ]; -static U32 readAndErrorCounts [ NUM_OF_TEMPERATURE_SENSORS ] [ NUM_OF_READ_AND_ERROR_ARRAY_COLUMNS ]; +static U32 readAndErrorCounts [ NUM_OF_TEMPERATURE_SENSORS ] + [ NUM_OF_READ_AND_ERROR_ARRAY_COLUMNS ]; // Private functions prototypes @@ -360,17 +350,9 @@ { U32 error; U32 heatersTemperature; - BOOL isADCValid = FALSE; + BOOL isADCValid = TRUE; F32 temperature; - - // TODO For testing only. REMOVE - /*temperature = getADC2TempConversion ( adc, - tempSensorsConstants [ TEMPSENSORS_CONDUCTIVITY_SENSOR_2_TEMP_SENSOR ] [ ADC_READ_GAIN_INDEX ], - tempSensorsConstants [ TEMPSENSORS_CONDUCTIVITY_SENSOR_2_TEMP_SENSOR ] [ ADC_READ_REF_RESISTANCE_INDEX ], - tempSensorsConstants [ TEMPSENSORS_CONDUCTIVITY_SENSOR_2_TEMP_SENSOR ] [ ADC_READ_0_DEG_RESISTANCE_INDEX ] );*/ - // TODO for testing only. REMOVE - /* * check if the index is not the heaters * Mask the values accordingly @@ -383,7 +365,8 @@ */ if ( sensorIndex != TEMPSENSORS_PRIMARY_HEATER_INTERNAL_TEMP_SENSOR || sensorIndex != TEMPSENSORS_TRIMMER_HEATER_INTERNAL_TEMP_SESNOR ) { - error = adc & MASK_OFF_U32_MSB; + error = 0; + adc = adc & MASK_OFF_U32_MSB; /* * what if the fpga channel error is not zero? * what if the fpga channel error is zero but the individual is not? @@ -395,14 +378,15 @@ { // TODO: alarm? } - isADCValid = FALSE; + //isADCValid = FALSE; } if ( error == EXTERNAL_TEMP_SENSORS_ERROR_VALUE ) { //tODO: FILL UP - isADCValid = FALSE; + //isADCValid = FALSE; } } + // It is a heaters temperature sensor else { // Fault state is the 17th bit @@ -414,9 +398,9 @@ // Fault alarm? or have a threshold? // If the fault is 1, should we check the individuals? } - + // TODO fix these heatersTemperature = adc & 0xFF05; - heatersTemperature = (heatersTemperature & 0x7FFF) >> 2; + heatersTemperature = (heatersTemperature & 0x7FFF) >> 2; //TODO use #define for 2 } U32 previousReadCount = readAndErrorCounts [ sensorIndex ] [ READ_AND_ERROR_PREV_FPGA_COUNT_INDEX ]; @@ -432,7 +416,7 @@ readAndErrorCounts [ sensorIndex ] [ READ_AND_ERROR_PREV_FPGA_COUNT_INDEX ] = fpgaCount; readAndErrorCounts [ sensorIndex ] [ READ_AND_ERROR_INTERNAL_ERROR_COUNT_INDEX ] = internalErrorCount++; } - isADCValid = FALSE; + //isADCValid = FALSE; } else if ( fpgaCount > previousReadCount ) { @@ -481,7 +465,6 @@ { temperature = avgADCReads * HEATERS_INTERNAL_ADC_TO_TEMP_CONVERSION_COEFF; } - temperatureValues [ sensorIndex ] = temperature; } } @@ -597,35 +580,14 @@ // 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( TEMPSENSORS_INLET_PRIMARY_HEATER_TEMP_SENSOR, getFPGATPiTemp() ); - //processADCRead( TEMPSENSORS_OUTLET_PRIMARY_HEATER_TEMP_SENSOR, getFPGATPoTemp() ); - //processADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_1_TEMP_SENSOR, getFPGACD1Temp() ); - //processADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_2_TEMP_SENSOR, getFPGACD2Temp() ); - //processADCRead( TEMPSENSORS_OUTLET_REDUNDANCY_TEMP_SENSOR, getFPGATHDoTemp() ); - //processADCRead( TEMPSENSORS_INLET_DIALYSATE_TEMP_SENSOR, getFPGATDiTemp() ); + processADCRead( TEMPSENSORS_INLET_PRIMARY_HEATER_TEMP_SENSOR, getFPGATPiTemp(), getFPGARTDErrorCount(), getFPGARTDReadCount() ); + processADCRead( TEMPSENSORS_OUTLET_PRIMARY_HEATER_TEMP_SENSOR, getFPGATPoTemp(), getFPGARTDErrorCount(), getFPGARTDReadCount() ); + processADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_1_TEMP_SENSOR, getFPGACD1Temp(), 0, 0 ); + processADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_2_TEMP_SENSOR, getFPGACD2Temp(), 0, 0 ); + processADCRead( TEMPSENSORS_OUTLET_REDUNDANCY_TEMP_SENSOR, getFPGATHDoTemp(), 0, 0 ); + processADCRead( TEMPSENSORS_INLET_DIALYSATE_TEMP_SENSOR, getFPGATDiTemp(), 0, 0 ); //processADCRead( TEMPSENSORS_PRIMARY_HEATER_INTERNAL_TEMP_SENSOR, getFPGAPrimaryHeaterTemp() ); //processADCRead( TEMPSENSORS_TRIMMER_HEATER_INTERNAL_TEMP_SESNOR, getFPGATrimmerHeaterTemp() ); - // TODO REMOVE THIS CODE. FOR TESTING ONLY - - - /*U08 dara; - U32 test [20] = {16327313, 16330313, 16333313, 16336313, 16339313, 16342313, 16345313, 16348313, 16351313, 16354313, - 16357313, 16360313, 16363313, 16366313, 16369313, 16372313, 16375313, 16378313, 16381313, 16384313}; - - U32 test2 [20] = {16348313, 16358313, 16368313, 16378313, 16388313, 16398313, 16408313, 16418313, 16428313, 16438313, - 16448313, 16458313, 16468313, 16478313, 16488313, 16498313, 16508313, 16518313, 16528313, 16538313}; - - for ( dara = 0; dara<20; dara++) - { - processADCRead(0, test[dara]); - } - dara = 0; - for ( dara = 0; dara<20; dara++) - { - processADCRead(0, test2[dara]); - }*/ - // TODO REMOVE THE ABOVE CODE - return state; }