Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -r3b70632c04247a6973960e1f37ae73eb4384a6b7 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 3b70632c04247a6973960e1f37ae73eb4384a6b7) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -22,8 +22,8 @@ #include "AlarmMgmt.h" #include "DGDefs.h" +#include "FlowSensors.h" #include "Heaters.h" -#include "InternalADC.h" #include "MessageSupport.h" #include "ModeFill.h" #include "NVDataMgmt.h" @@ -37,6 +37,7 @@ #include "TaskPriority.h" #include "TemperatureSensors.h" #include "Timers.h" +#include "Voltages.h" /** * @addtogroup Heaters @@ -48,26 +49,30 @@ #define HEATERS_MAX_DUTY_CYCLE 1.00F ///< Heaters max duty cycle (100%). #define HEATERS_MIN_DUTY_CYCLE 0.00F ///< Heaters minimum duty cycle (0.00%). #define HEATERS_MIN_HEAT_DISINFECT_DUTY_CYCLE 0.6F ///< Heaters minimum duty cycle during heat disinfect. +#define HEATERS_MIN_EST_GAIN 0.2F ///< Heaters minimum estimation gain. +#define HEATERS_MAX_EST_GAIN 5.0F ///< Heaters maximum estimation gain. +#define HEATERS_NEUTRAL_EST_GAIN 1.0F ///< Heaters neutral estimation gain. #define HEATERS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Heaters data publish interval. #define MINIMUM_TARGET_TEMPERATURE 10.0F ///< Minimum allowed target temperature for the heaters. #define MAXIMUM_TARGET_TEMPERATURE 90.0F ///< Maximum allowed target temperature for the heaters. -#define HEATERS_ON_NO_FLOW_TIMEOUT_MS ( 1 * MS_PER_SECOND ) ///< Heaters on with no flow time out in milliseconds. +#define HEATERS_ON_NO_FLOW_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Heaters on with no flow time out in milliseconds. #define HEATERS_MAX_OPERATING_VOLTAGE_V 24.0F ///< Heaters max operating voltage in volts. #define HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Heaters voltage out of range time out in milliseconds. #define HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL 0.2F ///< Heaters max voltage out of range tolerance. #define TRIMMER_HEATER_MAX_POWER_W 66.5F ///< Trimmer heater maximum power in Watts. #define TRIMMER_HEATER_CONTROL_CHECK_INTERVAL_COUNT ( ( 30 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ) ///< Trimmer heater control interval count. #define DELTA_TEMPERATURE_TIME_COSNTANT_C 8.6F ///< Delta temperature calculated from time constant. -#define PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C 0.03F ///< Primary heaters duty cycle per temperature in C. +#define PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C 0.015F ///< Primary heaters duty cycle per temperature in C. #define DATA_PUBLISH_COUNTER_START_COUNT 70 ///< Data publish counter start count. #define MIN_RO_HEATER_FLOWRATE_LPM 0.2F ///< Minimum target RO heater flow rate in L/min. static const F32 WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES = 4184 / SEC_PER_MIN; ///< Water specific heat in J/KgC / 60. static const F32 PRIMARY_HEATERS_MAXIMUM_POWER_WATTS = 475 + 237.5F; ///< Primary heaters maximum power (main primary = 475W and small primary = 237.5W). +static const F32 HEATERS_VOLTAGE_TOLERANCE_V = HEATERS_MAX_OPERATING_VOLTAGE_V * HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL; ///< Heaters voltage tolerance in volts. /// Heaters data structure typedef struct @@ -76,10 +81,10 @@ HEATERS_STATE_T state; ///< Heater state. BOOL startHeaterSignal; ///< Heater start indication flag. BOOL isHeaterOn; ///< Heater on/off status flag. - F32 dutycycle; ///< Heater duty cycle. + F32 dutyCycle; ///< Heater duty cycle. F32 targetFlow; ///< Heater target flow. BOOL hasTargetTempChanged; ///< Heater target temperature change flag indicator. - F32 heaterEstGain; ///< Heater efficiency during the run. + F32 heaterEstGain; ///< Heater estimation gain during the run. BOOL hasTargetBeenReached; ///< Heater flag to indicate whether the target temperature has been reached. F32 calculatedTemperature; ///< Heater calculated temperature. DG_RESERVOIR_ID_T inactiveRsrvr; ///< Heater inactive reservoir. @@ -127,28 +132,23 @@ for ( heater = DG_PRIMARY_HEATER; heater < NUM_OF_DG_HEATERS; heater++ ) { - heatersStatus[ heater ].targetTemp = 0.0; + heatersStatus[ heater ].targetTemp = 0.0F; heatersStatus[ heater ].state = HEATER_EXEC_STATE_OFF; heatersStatus[ heater ].startHeaterSignal = FALSE; heatersStatus[ heater ].isHeaterOn = FALSE; - heatersStatus[ heater ].dutycycle = 0.0; - heatersStatus[ heater ].targetFlow = 0.0; + heatersStatus[ heater ].dutyCycle = 0.0F; + heatersStatus[ heater ].targetFlow = 0.0F; heatersStatus[ heater ].hasTargetTempChanged = FALSE; - heatersStatus[ heater ].heaterEstGain = 1.0; // Assuming 100% efficiency during initialization until it is updated + heatersStatus[ heater ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; heatersStatus[ heater ].hasTargetBeenReached = FALSE; } // Initialize the persistent alarms - initPersistentAlarm( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, - HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); - - initPersistentAlarm( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, - HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); - - initPersistentAlarm( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, - HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); - - initPersistentAlarm( ALARM_ID_DG_FLOW_TOO_LOW_WHILE_HEATER_ON, HEATERS_ON_NO_FLOW_TIMEOUT_MS, HEATERS_ON_NO_FLOW_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS, HEATERS_VOLTAGE_OUT_OF_RANGE_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_RO_FLOW_TOO_LOW_WHILE_PRIMARY_HEATER_IS_ON, HEATERS_ON_NO_FLOW_TIMEOUT_MS, HEATERS_ON_NO_FLOW_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DIALYSATE_FLOW_TOO_LOW_WHILE_TRIMMER_HEATER_IS_ON, HEATERS_ON_NO_FLOW_TIMEOUT_MS, HEATERS_ON_NO_FLOW_TIMEOUT_MS ); } /*********************************************************************//** @@ -212,7 +212,7 @@ if( heater < NUM_OF_DG_HEATERS ) { - if ( TRUE == heatersStatus[ heater ].hasTargetTempChanged ) + if ( HEATER_EXEC_STATE_OFF == heatersStatus[ heater ].state ) { status = TRUE; heatersStatus[ heater ].startHeaterSignal = TRUE; @@ -317,17 +317,32 @@ // Check if the heater is on and if it is, check the flow sensor's status if ( TRUE == heatersStatus[ heater ].isHeaterOn ) { - // TODO add the function that gets the flow of the new flow sensor for DG. For now it is assumed that trimmer heater flow sensor - // is not 0 so the heater can run if needed - F32 measFlow = ( DG_PRIMARY_HEATER == heater ? getMeasuredROFlowRateLPM() : 50.0 ); - F32 minFlow = ( DG_PRIMARY_HEATER == heater ? MIN_RO_HEATER_FLOWRATE_LPM : MIN_RO_HEATER_FLOWRATE_LPM ); - BOOL isFlowLow = ( measFlow < minFlow ? TRUE : FALSE ); + ALARM_ID_T alarm; + F32 measFlow; + F32 minFlow; + BOOL isFlowLow; - checkPersistentAlarm( ALARM_ID_DG_FLOW_TOO_LOW_WHILE_HEATER_ON, isFlowLow, measFlow, minFlow ); + if ( DG_PRIMARY_HEATER == heater ) + { + alarm = ALARM_ID_RO_FLOW_TOO_LOW_WHILE_PRIMARY_HEATER_IS_ON; + measFlow = getMeasuredFlowRateLPM( RO_FLOW_SENSOR ); + minFlow = MIN_RO_FLOWRATE_LPM; + } + else + { + alarm = ALARM_ID_DIALYSATE_FLOW_TOO_LOW_WHILE_TRIMMER_HEATER_IS_ON; + measFlow = getMeasuredFlowRateLPM( DIALYSATE_FLOW_SENSOR ); + minFlow = MIN_DIALYSATE_FLOWRATE_LPM; + } + + isFlowLow = ( measFlow < minFlow ? TRUE : FALSE ); + + checkPersistentAlarm( alarm, isFlowLow, measFlow, minFlow ); } else { - checkPersistentAlarm( ALARM_ID_DG_FLOW_TOO_LOW_WHILE_HEATER_ON, FALSE, 0.0, 0.0 ); + checkPersistentAlarm( ALARM_ID_RO_FLOW_TOO_LOW_WHILE_PRIMARY_HEATER_IS_ON, FALSE, 0.0, 0.0 ); + checkPersistentAlarm( ALARM_ID_DIALYSATE_FLOW_TOO_LOW_WHILE_TRIMMER_HEATER_IS_ON, FALSE, 0.0, 0.0 ); } } @@ -344,20 +359,61 @@ /*********************************************************************//** * @brief - * The resetHeatersEfficiency function resets the heaters efficiency upon + * The resetHeatersEstimationGain function resets the heaters estimation gain upon * the start of a treatment. * @details Inputs: none * @details Outputs: heaterStatus * @return none *************************************************************************/ -void resetHeatersEfficiency( void ) +void resetHeatersEstimationGain( void ) { - heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain = 1.0; - heatersStatus[ DG_TRIMMER_HEATER ].heaterEstGain = 1.0; + heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; + heatersStatus[ DG_TRIMMER_HEATER ].heaterEstGain = HEATERS_NEUTRAL_EST_GAIN; } /*********************************************************************//** * @brief + * The calculateHeaterEstimationGain function calculates the heater estimation + * gain. + * @details Inputs: none + * @details Outputs: heatersStatus + * @return none + *************************************************************************/ +void calculateHeaterEstimationGain( DG_HEATERS_T heater ) +{ +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_HEATERS_EFFICIENCY ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + F32 heaterEstGain = heatersStatus[ heater ].heaterEstGain; + F32 heaterDutyCycle = heatersStatus[ heater ].dutyCycle; + F32 lastFillTemperature = getAvgFillTemperature(); + F32 primaryTargetTemperature = heatersStatus[ heater ].targetTemp; + BOOL isTempUnderTarget = ( lastFillTemperature < primaryTargetTemperature ? TRUE : FALSE ); + + if ( TRUE == isTempUnderTarget ) + { + if ( heaterDutyCycle < HEATERS_MAX_DUTY_CYCLE ) + { + heaterEstGain += ( primaryTargetTemperature - lastFillTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; + } + } + else + { + if ( heaterDutyCycle > HEATERS_MIN_DUTY_CYCLE ) + { + heaterEstGain -= ( lastFillTemperature - primaryTargetTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; + } + } + + heaterEstGain = MAX( heaterEstGain, HEATERS_MIN_EST_GAIN ); + heaterEstGain = MIN( heaterEstGain, HEATERS_MAX_EST_GAIN ); + heatersStatus[ heater ].heaterEstGain = heaterEstGain; + } +} + +/*********************************************************************//** + * @brief * The handleHeaterStateOff function handles the heater not running state. * @details Inputs: heaterStatus * @details Outputs: heaterStatus @@ -408,10 +464,9 @@ else if ( ( DG_MODE_GENE == opMode ) || ( DG_MODE_DRAI == opMode ) ) { targetTemperature += DELTA_TEMPERATURE_TIME_COSNTANT_C; - // Use target flow rate during Idle and drain - targetFlow = getTargetROPumpFlowRateLPM(); - dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, FALSE ); - state = HEATER_EXEC_STATE_PRIMARY_CONTROL_TO_TARGET; + targetFlow = getTargetROPumpFlowRateLPM(); + dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, FALSE ); + state = HEATER_EXEC_STATE_PRIMARY_CONTROL_TO_TARGET; } else if ( ( DG_MODE_HEAT == opMode ) || ( DG_MODE_CHEM == opMode ) ) { @@ -421,6 +476,11 @@ dutyCycle = calculatePrimaryHeaterDutyCycle( targetTemperature, inletTemperature, targetFlow, FALSE ); state = HEATER_EXEC_STATE_CONTROL_TO_DISINFECT_TARGET; } + else + { + // No other modes are using the heaters + // TODO software fault + } // Update the calculated target temperature heatersStatus[ DG_PRIMARY_HEATER ].calculatedTemperature = targetTemperature; @@ -472,7 +532,7 @@ state = HEATER_EXEC_STATE_PRIMARY_RAMP_TO_TARGET; } - // If the heat disifect sensor indicates that the temperature is below target temperature but the target temperature had been reached + // If the heat disinfect sensor indicates that the temperature is below target temperature but the target temperature had been reached // before turn on the heaters with 100% power if ( ( heatDisinfectSensorTemp <= heatersStatus[ heater ].targetTemp ) && ( TRUE == heatersStatus[ heater ].hasTargetBeenReached ) ) { @@ -513,7 +573,7 @@ if ( ( DG_MODE_FILL == opMode ) || ( DG_MODE_GENE == opMode ) || ( DG_MODE_DRAI == opMode ) ) { - currentTemperature = getTrimmerHeaterTargetTemperature(); + currentTemperature = getReservoirCurrentTemperature(); dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, currentTemperature, targetFlowLPM, TRUE ); state = HEATER_EXEC_STATE_TRIMMER_CONTROL_TO_TARGET; } @@ -529,10 +589,15 @@ } // Update the calculated target temperature + // Reset the duty cycle since the reservoir has been switched heatersStatus[ heater ].calculatedTemperature = currentTemperature; heatersStatus[ heater ].inactiveRsrvr = getInactiveReservoir(); heatersStatus[ heater ].targetFlow = targetFlowLPM; + heatersStatus[ heater ].dutyCycle = 0.0F; trimmerHeaterControlCounter = 0; + + // Cap the minimum duty cycle. So if it is calculated to negative, set it to 0 + dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); setHeaterDutyCycle( heater, dutyCycle ); return state; @@ -549,6 +614,7 @@ static HEATERS_STATE_T handleHeaterStateTrimmerControlToTarget( void ) { HEATERS_STATE_T state = HEATER_EXEC_STATE_TRIMMER_CONTROL_TO_TARGET; + F32 tempDutyCycle = 0.0; // If the inactive reservoir has changed from the last run transition to ramp state to recalculate the // duty cycle for the next delivery @@ -560,14 +626,17 @@ { // When the trimmer heater is on, its duty cycle is adjusted at the control interval. For this control check, // dialysate inlet temperature sensor is used rather than the theoretical calculations. - F32 outletRedundantTemperature = getTemperatureValue( TEMPSENSORS_INLET_DIALYSATE ); // TODO Change to TRo in DVT + F32 outletRedundantTemperature = getTemperatureValue( TEMPSENSORS_OUTLET_REDUNDANT ); F32 targetTemperature = heatersStatus[ DG_TRIMMER_HEATER ].targetTemp; F32 targetFlowLPM = heatersStatus[ DG_TRIMMER_HEATER ].targetFlow; F32 dutyCycle = calculateTrimmerHeaterDutyCycle( targetTemperature, outletRedundantTemperature, targetFlowLPM, TRUE ); - trimmerHeaterControlCounter = 0; - setHeaterDutyCycle( DG_TRIMMER_HEATER, dutyCycle ); + tempDutyCycle = heatersStatus[ DG_TRIMMER_HEATER ].dutyCycle + dutyCycle; + tempDutyCycle = MIN( tempDutyCycle, HEATERS_MAX_DUTY_CYCLE ); + tempDutyCycle = MAX( tempDutyCycle, HEATERS_MIN_DUTY_CYCLE ); + + setHeaterDutyCycle( DG_TRIMMER_HEATER, tempDutyCycle ); } return state; @@ -587,7 +656,7 @@ // Check if the requested duty cycle is different from what the heater's duty cycle is. // If the same duty cycle is requested, then it is not needed to send it again. This is to make sure // the same duty cycle is not sent to the hardware all the time. - if ( fabs( heatersStatus[ heater ].dutycycle - pwm ) > NEARLY_ZERO ) + if ( fabs( heatersStatus[ heater ].dutyCycle - pwm ) > NEARLY_ZERO ) { if ( DG_PRIMARY_HEATER == heater ) { @@ -600,7 +669,7 @@ } // Updated the heater's information - heatersStatus[ heater ].dutycycle = pwm; + heatersStatus[ heater ].dutyCycle = pwm; } } @@ -617,48 +686,13 @@ *************************************************************************/ static F32 calculatePrimaryHeaterDutyCycle( F32 targetTemperature, F32 currentTemperature, F32 flow, BOOL checkEfficiency ) { - // Get the primary heater's efficiency and the last fill temperature from the ModeFill - F32 heaterEfficiency = heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain; - -#ifndef _RELEASE_ - if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_HEATERS_EFFICIENCY ) != SW_CONFIG_ENABLE_VALUE ) -#endif - { - if ( TRUE == checkEfficiency ) - { - F32 lastFillTemperature = getLastFillTemperature(); - F32 primaryTargetTemperature = heatersStatus[ DG_PRIMARY_HEATER ].targetTemp; - - // If the last fill temperature > target temperature, it means the primary heater overshot the duty cycle - // so with its efficiency is toned down for the next fill cycle - // If the heater under-shoots the duty cycle, the efficiency increases the duty cycle for the next fill cycle - if ( lastFillTemperature - primaryTargetTemperature < 0.0F ) - { - heaterEfficiency -= ( lastFillTemperature - primaryTargetTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; - } - else - { - heaterEfficiency += ( primaryTargetTemperature - lastFillTemperature ) * PRIMARY_HEATER_DUTY_CYCLE_PER_TEMPERATURE_C; - } - - // If the efficiency is less than 0, set it to 0 but if the efficiency is greater than 100, it is not enforced - // to be 100 since the duty cycle range check will cap the duty cycle to 100 anyways. - heaterEfficiency = MAX( heaterEfficiency, 0.0 ); - - // Update the heaters efficiency - heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain = heaterEfficiency; - } - } - // Duty cycle = ( 69.73 * flow rate * deltaT / primary heater maximum power ) ^ 1/2 // Multiply the duty cycle to the heater efficiency - F32 dutyCycle = sqrt( ( WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * - fabs( targetTemperature - currentTemperature ) * flow ) / PRIMARY_HEATERS_MAXIMUM_POWER_WATTS ) * heaterEfficiency; + F32 dutyCycle = sqrt( ( WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * fabs( targetTemperature - currentTemperature ) * flow ) / PRIMARY_HEATERS_MAXIMUM_POWER_WATTS ); + dutyCycle *= heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain; + dutyCycle = MIN( dutyCycle, HEATERS_MAX_DUTY_CYCLE ); + dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); - // Check the boundaries of the calculated duty cycle - dutyCycle = MIN( dutyCycle, HEATERS_MAX_DUTY_CYCLE ); - dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); - return dutyCycle; } @@ -678,8 +712,8 @@ static F32 calculateTrimmerHeaterDutyCycle( F32 targetTemperature, F32 currentTemperature, F32 flow, BOOL checkEfficiency ) { // Get the primary heater's efficiency and the last fill temperature from the ModeFill - F32 heaterEfficiency = heatersStatus[ DG_TRIMMER_HEATER ].heaterEstGain; - F32 dutyCycle = 0.0; + F32 heaterEstGain = heatersStatus[ DG_TRIMMER_HEATER ].heaterEstGain; + F32 dutyCycle = 0.0F; #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_HEATERS_EFFICIENCY ) != SW_CONFIG_ENABLE_VALUE ) @@ -692,12 +726,9 @@ } // Duty cycle = ( 69.73 * flow rate * deltaT / primary heater maximum power ) and multiply the duty cycle to the heater efficiency - dutyCycle = ( ( flow * WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * - ( targetTemperature - currentTemperature ) * heaterEfficiency ) / TRIMMER_HEATER_MAX_POWER_W ) * heaterEfficiency; - - // Check the boundaries of the calculated duty cycle + dutyCycle = ( ( flow * WATER_SPECIFIC_HEAT_DIVIDED_BY_MINUTES * ( targetTemperature - currentTemperature ) ) / TRIMMER_HEATER_MAX_POWER_W ) * heaterEstGain; dutyCycle = MIN( dutyCycle, HEATERS_MAX_DUTY_CYCLE ); - dutyCycle = MAX( dutyCycle, HEATERS_MIN_DUTY_CYCLE ); + dutyCycle = MAX( dutyCycle, ( HEATERS_MAX_DUTY_CYCLE * -1.0F ) ); return dutyCycle; } @@ -782,22 +813,21 @@ { HEATERS_DATA_T data; - data.mainPrimayHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle * 100.0; + data.mainPrimayHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle * 100.0; // The duty cycle of the primary heater is divided into 2 parts and is applied to main // and small primary heaters. So they are always the same. - data.smallPrimaryHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle * 100.0; - data.trimmerHeaterDC = heatersStatus[ DG_TRIMMER_HEATER ].dutycycle * 100.0; + data.smallPrimaryHeaterDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle * 100.0; + data.trimmerHeaterDC = heatersStatus[ DG_TRIMMER_HEATER ].dutyCycle * 100.0; data.primaryTargetTemp = heatersStatus[ DG_PRIMARY_HEATER ].targetTemp; data.trimmerTargetTemp = heatersStatus[ DG_TRIMMER_HEATER ].targetTemp; data.primaryHeaterState = heatersStatus[ DG_PRIMARY_HEATER ].state; data.trimmerHeaterState = heatersStatus[ DG_TRIMMER_HEATER ].state; data.primaryEfficiency = heatersStatus[ DG_PRIMARY_HEATER ].heaterEstGain * 100; data.primaryCalcTargetTemp = heatersStatus[ DG_PRIMARY_HEATER ].calculatedTemperature; data.trimmerCalcCurrentTemp = heatersStatus[ DG_TRIMMER_HEATER ].calculatedTemperature; + dataPublicationTimerCounter = 0; broadcastData( MSG_ID_DG_HEATERS_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( HEATERS_DATA_T ) ); - - dataPublicationTimerCounter = 0; } } @@ -810,29 +840,37 @@ *************************************************************************/ static void monitorHeatersVoltage( void ) { - F32 mainPriVoltage = getIntADCVoltageConverted( INT_ADC_PRIMARY_HEATER_24_VOLTS ); - // TODO it is assumed that the main and small primary heaters have equal voltage since the PWMs are divided into 2 - // before applying the PWMs to the heaters. Right now, there is no ADC channel available for the small primary - // heater so the main primary heater's ADC channel is used for the small primary heater as well. - F32 smallPriVoltage = getIntADCVoltageConverted( INT_ADC_PRIMARY_HEATER_24_VOLTS ); - F32 trimmerVoltage = getIntADCVoltageConverted( INT_ADC_TRIMMER_HEATER_24_VOLTS ); + // NOTE: Default to using Primary heater voltage from FPGA + F32 mainPriVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_PRIM_HTR_GND_V ); +#ifndef _RELEASE_ + if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) ) + { + // V3 use CPU based value for Primary, same as Secondary + mainPriVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_SEC_HTR_V ); + } +#endif + F32 smallPriVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_SEC_HTR_V ); + F32 trimmerVoltage = getMonitoredLineLevel( MONITORED_LINE_24V_TRIM_HTR_V ); // Voltage to PWM is reverse. If PWM = 0 -> V = 24V - F32 mainPri = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle > NEARLY_ZERO ? heatersStatus[ DG_PRIMARY_HEATER ].dutycycle : 1.0; - F32 smallPri = heatersStatus[ DG_PRIMARY_HEATER ].dutycycle > NEARLY_ZERO ? heatersStatus[ DG_PRIMARY_HEATER ].dutycycle : 1.0; - F32 trimmer = heatersStatus[ DG_TRIMMER_HEATER ].dutycycle > NEARLY_ZERO ? heatersStatus[ DG_TRIMMER_HEATER ].dutycycle : 1.0; + F32 mainPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle; + F32 smallPriDC = heatersStatus[ DG_PRIMARY_HEATER ].dutyCycle; + F32 trimmerDC = heatersStatus[ DG_TRIMMER_HEATER ].dutyCycle; - F32 mainPriVoltageTol = HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * mainPriVoltage; - F32 smallPriVoltageTol = HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * smallPriVoltage; - F32 trimmerVoltageTol = HEATERS_MAX_VOLTAGE_OUT_OF_RANGE_TOL * trimmerVoltage; + F32 mainPriExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0F - mainPriDC ); + F32 smallPriExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0F - smallPriDC ); + F32 trimmerExpectedVoltage = HEATERS_MAX_OPERATING_VOLTAGE_V * ( 1.0F - trimmerDC ); - BOOL isMainPriOut = ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * mainPri ) - mainPriVoltage ) > mainPriVoltageTol ? TRUE : FALSE ); - BOOL isSmallPriOut = ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * smallPri ) - smallPriVoltage ) > smallPriVoltageTol ? TRUE : FALSE ); - BOOL isTrimmerOut = ( fabs( ( HEATERS_MAX_OPERATING_VOLTAGE_V * trimmer ) - trimmerVoltage ) > trimmerVoltageTol ? TRUE : FALSE ); + BOOL isMainPriOut = ( fabs( mainPriExpectedVoltage - mainPriVoltage ) > HEATERS_VOLTAGE_TOLERANCE_V ? TRUE : FALSE ); + BOOL isSmallPriOut = ( fabs( smallPriExpectedVoltage - smallPriVoltage ) > HEATERS_VOLTAGE_TOLERANCE_V ? TRUE : FALSE ); + BOOL isTrimmerOut = ( fabs( trimmerExpectedVoltage - trimmerVoltage ) > HEATERS_VOLTAGE_TOLERANCE_V ? TRUE : FALSE ); - //checkPersistentAlarm( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isMainPriOut, mainPri, mainPriVoltageTol ); - //checkPersistentAlarm( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isSmallPriOut, smallPri, smallPriVoltageTol ); - //checkPersistentAlarm( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, isTrimmerOut, trimmer, trimmerVoltageTol ); + if ( getCurrentOperationMode() != DG_MODE_INIT ) + { + checkPersistentAlarm( ALARM_ID_DG_MAIN_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isMainPriOut, mainPriDC, HEATERS_VOLTAGE_TOLERANCE_V ); + checkPersistentAlarm( ALARM_ID_DG_SMALL_PRIMARY_HEATER_VOLTAGE_OUT_OF_RANGE, isSmallPriOut, smallPriDC, HEATERS_VOLTAGE_TOLERANCE_V ); + checkPersistentAlarm( ALARM_ID_DG_TRIMMER_HEATER_VOLTAGE_OUT_OF_RANGE, isTrimmerOut, trimmerDC, HEATERS_VOLTAGE_TOLERANCE_V ); + } } Index: firmware/App/Controllers/LoadCell.c =================================================================== diff -u -r7fb16c92973a551dda1d801d5f255f88c0c81f12 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision 7fb16c92973a551dda1d801d5f255f88c0c81f12) +++ firmware/App/Controllers/LoadCell.c (.../LoadCell.c) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -7,8 +7,8 @@ * * @file LoadCell.c * -* @author (last) Dara Navaei -* @date (last) 03-Aug-2022 +* @author (last) Michael Garthwaite +* @date (last) 07-Sep-2022 * * @author (original) Saeed Nejatali * @date (original) 25-Feb-2020 @@ -48,23 +48,23 @@ #define LOAD_CELL_MIN_ALLOWED_WEIGHT_BEFORE_TARE_GRAMS 1600.0F ///< Load cell minimum allowed weight before tare in grams. #define LOAD_CELL_WEIGHT_OUT_RANGE_PERSISTENT_PERIOD_MS (5 * MS_PER_SECOND) ///< Load cell weight out of range persistent period in milliseconds. #define LOAD_CELL_PRIMARY_BACKUP_MAX_DRIFT_PERSISTENT_PERIOD_MS (5 * MS_PER_SECOND) ///< Load cell primary and backup maximum allowed weight drift persistent period in milliseconds. -#define EMPTY_RESERVOIR_WEIGHT_GRAMS 1600 ///< Reservoirs empty weight in grams. -#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_FIRST_TARE_GRAMS 300 ///< Max allowed extra weight before first tare in grams. -#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_TARE_GRAMS 60 ///< Max allowed extra weight before tare in grams. +#define EMPTY_RESERVOIR_WEIGHT_GRAMS 1600.0F ///< Reservoirs empty weight in grams. +#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_FIRST_TARE_GRAMS 300.0F ///< Max allowed extra weight before first tare in grams. +#define MAX_ALLOWED_EXTRA_WEIGHT_BEFORE_TARE_GRAMS 60.0F ///< Max allowed extra weight before tare in grams. #define LOAD_CELL_PRIMARY_BACKUP_MAX_ALLOWED_DRIFT_GRAMS 60.0F ///< Load cell primary and backup maximum allowed weight drift in grams. #define DATA_PUBLISH_COUNTER_START_COUNT 0 ///< Data publish counter start count. /// Load cell data structure. typedef struct { U32 rawReading; ///< Latest raw load cell reading. - OVERRIDE_F32_T weight; ///< Latest load cell weight. + F32 weight; ///< Latest load cell weight. F32 autoCalOffset; ///< Load cell auto-calibration offset. F32 loadCellVelocity_g_min; ///< Velocity (in g/min) of load cell. F32 smallFilterReadings[ SIZE_OF_SMALL_LOAD_CELL_AVG ]; ///< Load cell samples for small load cell moving average. F64 smallFilterTotal; ///< Small filter rolling total - used to calc small load cell moving average. - F32 smallFilteredWeight; ///< Load cell small filtered (100 100Hz raw sample) weight. + OVERRIDE_F32_T smallFilteredWeight; ///< Load cell small filtered (100 100Hz raw sample) weight. F32 largeFilterReadings[ SIZE_OF_LARGE_LOAD_CELL_AVG ]; ///< Load cell samples for large load cell moving average. F64 largeFilterTotal; ///< Large filter rolling total - used to calc small load cell moving average. @@ -82,6 +82,7 @@ static U32 smallReadingsIdx; ///< Index for next sample in load cell small rolling average sample array. static U32 largeReadingsIdx; ///< Index for next sample in load cell large rolling average sample array. static DG_LOAD_CELLS_CAL_RECORD_T loadCellsCalRecord; ///< Load cells calibration record. +static BOOL hasLoadCellBeenTared[ NUM_OF_LOAD_CELLS ]; ///< Flags indicating whether loadcells have been tared yet. // ********** private function prototypes ********** @@ -105,21 +106,24 @@ loadCellDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; loadCellFilterTimerCount = 0; + // Initialize load cell filter data and set calibration data as benign until loaded from non-volatile memory for ( i = 0; i < NUM_OF_LOAD_CELLS; i++ ) { benignPolynomialCalRecord( &loadCellsCalRecord.loadCells[ i ] ); - loadcells[ i ].rawReading = 0; - loadcells[ i ].weight.data = 0.0; - loadcells[ i ].weight.ovData = 0.0; - loadcells[ i ].weight.ovInitData = 0.0; - loadcells[ i ].weight.override = OVERRIDE_RESET; - loadcells[ i ].autoCalOffset = 0.0; - loadcells[ i ].largeFilterTotal = 0.0; - loadcells[ i ].largeFilteredWeight = 0.0; - loadcells[ i ].smallFilterTotal = 0.0; - loadcells[ i ].smallFilteredWeight = 0.0; + hasLoadCellBeenTared[ i ] = FALSE; + loadcells[ i ].rawReading = 0; + loadcells[ i ].weight = 0.0; + loadcells[ i ].autoCalOffset = 0.0; + loadcells[ i ].largeFilterTotal = 0.0; + loadcells[ i ].largeFilteredWeight = 0.0; + loadcells[ i ].smallFilterTotal = 0.0; + loadcells[ i ].smallFilteredWeight.data = 0.0; + loadcells[ i ].smallFilteredWeight.ovData = 0.0; + loadcells[ i ].smallFilteredWeight.ovInitData = 0.0; + loadcells[ i ].smallFilteredWeight.override = OVERRIDE_RESET; + for ( j = 0; j < SIZE_OF_SMALL_LOAD_CELL_AVG; j++ ) { loadcells[ i ].smallFilterReadings[ j ] = 0.0; @@ -198,11 +202,11 @@ // Apply the calibration factors to the data. // load_cell_weight = fourth_order_coeff * (load_cell^4) + third_order_coeff * (load_cell^3) + second_order_coeff * (load_cell^2) + gain * load_cell + offset - loadcells[ ii ].weight.data = pow( loadCell, 4 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].fourthOrderCoeff + - pow( loadCell, 3 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].thirdOrderCoeff + - pow( loadCell, 2 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].secondOrderCoeff + - loadCell * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].gain + - loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].offset; + loadcells[ ii ].weight = pow( loadCell, 4 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].fourthOrderCoeff + + pow( loadCell, 3 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].thirdOrderCoeff + + pow( loadCell, 2 ) * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].secondOrderCoeff + + loadCell * loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].gain + + loadCellsCalRecord.loadCells[ (CAL_DATA_DG_LOAD_CELLS_T)ii ].offset; loadcells[ ii ].loadCellVelocity_g_min = ( getLoadCellWeight( (LOAD_CELL_ID_T)ii ) - loadcells[ ii ].smallFilterReadings[ smallReadingsIdx ] ) * (F32)SEC_PER_MIN; @@ -213,13 +217,13 @@ loadcells[ ii ].smallFilterTotal += getLoadCellWeight( (LOAD_CELL_ID_T)ii ); // Calculate the load cell value before applying calibration to it - loadcells[ ii ].smallFilteredWeight = (F32)( loadcells[ ii ].smallFilterTotal / (F64)SIZE_OF_SMALL_LOAD_CELL_AVG ); + loadcells[ ii ].smallFilteredWeight.data = (F32)( loadcells[ ii ].smallFilterTotal / (F64)SIZE_OF_SMALL_LOAD_CELL_AVG ); // Monitor the load cells weight monitorLoadCellsWeightOutOfRange( (LOAD_CELL_ID_T)ii ); // Apply the tare offset. NOTE: tare must be applied after checking the weight out of range. - loadcells[ ii ].smallFilteredWeight -= loadcells[ ii ].autoCalOffset; + loadcells[ ii ].smallFilteredWeight.data -= loadcells[ ii ].autoCalOffset; } smallReadingsIdx = INC_WRAP( smallReadingsIdx, 0, SIZE_OF_SMALL_LOAD_CELL_AVG - 1 ); @@ -231,8 +235,8 @@ { // Update large filter with new small filter weight sample loadcells[ ii ].largeFilterTotal -= loadcells[ ii ].largeFilterReadings[ largeReadingsIdx ]; - loadcells[ ii ].largeFilterReadings[ largeReadingsIdx ] = loadcells[ ii ].smallFilteredWeight; - loadcells[ ii ].largeFilterTotal += loadcells[ ii ].smallFilteredWeight; + loadcells[ ii ].largeFilterReadings[ largeReadingsIdx ] = getLoadCellSmallFilteredWeight((LOAD_CELL_ID_T) ii); + loadcells[ ii ].largeFilterTotal += getLoadCellSmallFilteredWeight((LOAD_CELL_ID_T) ii); loadcells[ ii ].largeFilteredWeight = (F32)( loadcells[ ii ].largeFilterTotal / (F64)SIZE_OF_LARGE_LOAD_CELL_AVG ); } @@ -325,7 +329,7 @@ F32 weight = getLoadCellSmallFilteredWeight( loadCellID ); // Check if the load cell is being tared for the first time - if ( fabs( loadcells[ loadCellID ].autoCalOffset ) < NEARLY_ZERO ) + if ( hasLoadCellBeenTared[ loadCellID ] != TRUE ) { // For the first tare, the weight of the reservoir should be considered // The current weight of the load cell should not be greater than the weight of the reservoir + the extra weight @@ -340,7 +344,8 @@ if ( FALSE == isWeightOutOfRange ) { // Add old auto calibration offset to get back to actual weight value - loadcells[ loadCellID ].autoCalOffset = ( loadcells[ loadCellID ].smallFilteredWeight + loadcells[ loadCellID ].autoCalOffset ); + loadcells[ loadCellID ].autoCalOffset = ( loadcells[ loadCellID ].smallFilteredWeight.data + loadcells[ loadCellID ].autoCalOffset ); + hasLoadCellBeenTared[ loadCellID ] = TRUE; } else { @@ -373,14 +378,11 @@ *************************************************************************/ F32 getLoadCellWeight( LOAD_CELL_ID_T loadCellID ) { - F32 result = loadcells[ loadCellID ].weight.data; + F32 result = 0.0; if ( loadCellID < NUM_OF_LOAD_CELLS ) { - if ( OVERRIDE_KEY == loadcells[ loadCellID ].weight.override ) - { - result = loadcells[ loadCellID ].weight.ovData; - } + result = loadcells[ loadCellID ].weight; } else { @@ -405,7 +407,12 @@ if ( loadCellID < NUM_OF_LOAD_CELLS ) { - result = loadcells[ loadCellID ].smallFilteredWeight; + result = loadcells[ loadCellID ].smallFilteredWeight.data; + + if ( OVERRIDE_KEY == loadcells[ loadCellID ].smallFilteredWeight.override ) + { + result = loadcells[ loadCellID ].smallFilteredWeight.ovData; + } } else { @@ -553,8 +560,8 @@ { result = TRUE; // Add tare to given value so reported load will be what is requested when tare is subtracted later - loadcells[ loadCellID ].weight.ovData = value + loadcells[ loadCellID ].autoCalOffset; - loadcells[ loadCellID ].weight.override = OVERRIDE_KEY; + loadcells[ loadCellID ].smallFilteredWeight.ovData = value; + loadcells[ loadCellID ].smallFilteredWeight.override = OVERRIDE_KEY; } } @@ -578,8 +585,8 @@ if ( TRUE == isTestingActivated() ) { result = TRUE; - loadcells[ loadCellID ].weight.override = OVERRIDE_RESET; - loadcells[ loadCellID ].weight.ovData = loadcells[ loadCellID ].weight.ovInitData; + loadcells[ loadCellID ].smallFilteredWeight.override = OVERRIDE_RESET; + loadcells[ loadCellID ].smallFilteredWeight.ovData = loadcells[ loadCellID ].smallFilteredWeight.ovInitData; } } Index: firmware/App/Controllers/TemperatureSensors.c =================================================================== diff -u -r3b70632c04247a6973960e1f37ae73eb4384a6b7 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision 3b70632c04247a6973960e1f37ae73eb4384a6b7) +++ firmware/App/Controllers/TemperatureSensors.c (.../TemperatureSensors.c) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -76,15 +76,13 @@ #define CELSIUS_TO_KELVIN_CONVERSION 273.15F ///< Celsius to Kelvin temperature conversion. #define ADC_BOARD_TEMP_SENSORS_CONVERSION_CONST 272.5F ///< ADC board temperature sensors conversion constant. -#define TWELVE_BIT_RESOLUTION 4096U ///< 12 bit resolution conversion. #define ADC_BOARD_TEMP_SENSORS_CONST 0x800000 ///< ADC board temperature sensors constant. #define EXTERNAL_TEMP_SENSORS_ERROR_VALUE 0x80 ///< External temperature sensors error value. #define HEATERS_INTERNAL_TEMP_SENSOR_FAULT 0x01 ///< Heaters internal temperature sensor fault. #define TEMP_SENSORS_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Temperature sensors publish data time interval. #define TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Temperature sensors FPGA error timeout in milliseconds. -#define FPGA_RAW_ADC_READ_INTERVAL_COUNT 8 ///< Time interval in counts to read the raw ADC reads from FPGA. #define TEMP_SENSORS_ERROR_BIT_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Temperature sensors error bit timeout in milliseconds. #define TEMP_SENSORS_MIN_ALLOWED_DEGREE_C 0.0F ///< Temperature sensors minimum allowed temperature in C. @@ -93,16 +91,9 @@ #define NON_FLUID_PATH_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C 80.0F ///< Non fluid temperature sensors path maximum allowed temperature in C. #define TEMP_SENSORS_OUT_OF_RANGE_TIME_OUT_MS ( 5 * MS_PER_SECOND ) ///< Temperature sensor out of range persistent period in milliseconds. #define DATA_PUBLISH_COUNTER_START_COUNT 30 ///< Data publish counter start count. +#define BARO_SENSOR_REFERENCE_TEMP_C 2000 ///< Barometric sensor reference temperature in C. +#define BARO_SENSOR_WAIT_FOR_COEFF_TIME_OUT_MS ( 20 * MS_PER_SECOND ) ///< Barometric sensor wait for coefficients timeout in milliseconds. -// The count cannot be within 0.1V of the rail on both sides therefore: -// ADC count = ((2^12) - 1 / ref voltage) * voltage -// Max allowed voltage = 3.0 - 0.1 = 2.0V -// Min allowed voltage = 0.1 - 0.0 = 0.1V -// Max count = ((2^12) - 1 / ref voltage) * voltage -> ((4096 - 1)/3.0) * (3.0 - 0.1) -// Min count = ((2^12) - 1 / ref voltage) * voltage -> ((4096 - 1)/3.0) * (0.1 - 0.0) -#define TEMP_SENSORS_MAX_ALLOWED_ADC_COUNT 3959U ///< Temperature sensors max allowed ADC count. -#define TEMP_SESNORS_MIN_ALLOWED_ADC_COUNT 137U ///< Temperature sensors min allowed ADC count. - /// Temperature sensor exec states. typedef enum tempSensors_Exec_States { @@ -121,23 +112,45 @@ S32 rawADCReads[ MAX_NUM_OF_RAW_ADC_SAMPLES ]; ///< Raw ADC reads array S32 adcNextIndex; ///< Next ADC read index S32 adcRunningSum; ///< ADC running sum - U32 readCount; ///< Read counts from FPGA OVERRIDE_F32_T temperatureValues; ///< Temperature values with override F32 maxAllowedTemp; ///< Maximum allowed temperature of the sensor U32 alarmStartTime; ///< Alarm start time U08 sensorErrorBitStatus; ///< Temperature sensor error bit status BOOL fpgaErrorStatus; ///< Temperature sensor FPGA error status BOOL adcErrorStatus; ///< Temperature sensor ADC error status + S32 baroTempSnsrDiff; ///< Barometric sensor temperature difference } TEMP_SENSOR_T; +/// Barometric sensor temperature conversion +typedef struct +{ + U16 refTemperature; ///< Barometric sensor reference temperature. + U16 temperatureCoeff; ///< Barometric sensor temperature coefficient. + OVERRIDE_U32_T coeffsCRC; ///< Barometric sensor coefficients CRC. + U32 waitForCoeffStartTimeMS; ///< Barometric sensor wait for coefficients start time in milliseconds. + BOOL hasCRCBeenChecked; ///< Barometric sensor has CRC been checked flag. +} BARO_SENSOR_CONSTS_T; + +/// Barometric sensor coefficients +typedef struct +{ + U16 mfgInfo; ///< Barometric sensor manufacturing info. + U16 pressSensitivity; ///< Barometric sensor pressure sensitivity. + U16 pressOffset; ///< Barometric sensor pressure offset. + U16 tempCoeffOfPressSens; ///< Barometric sensor temperature coefficient of pressure sensor. + U16 tempCoeffPressOffset; ///< Barometric sensor temperature coefficient of pressure offset. + U16 referenceTemp; ///< Barometric sensor reference temperature. + U16 tempCoeffOfTemp; ///< Barometric sensor temperature coefficient of Temperature sensor. + U16 crc; ///< Barometric sensor CRC of the coefficients. +} BARO_SENSORS_COEFFS_T; + // ********** private data ********** static TEMPSENSORS_EXEC_STATES_T tempSensorsExecState; ///< TemperatureSensor exec state. static TEMP_SENSOR_T tempSensors [ NUM_OF_TEMPERATURE_SENSORS ]; ///< Temperature sensors' data structure. -static U32 fpgaRawADCReadInterval; ///< FPGA raw ADC read interval count. static U32 elapsedTime; ///< Elapsed time variable. static U32 internalHeatersConversionTimer; ///< Conversion timer variable to calculate the heaters internal temperature. - +static BARO_SENSOR_CONSTS_T baroConvConsts; ///< Barometric sensor conversion constants. static U32 dataPublicationTimerCounter; ///< Temperature sensors data publish timer counter. static OVERRIDE_U32_T tempSensorsPublishInterval = { TEMP_SENSORS_DATA_PUBLISH_INTERVAL, TEMP_SENSORS_DATA_PUBLISH_INTERVAL, 0, 0 }; ///< Temperature sensors publish time interval override. @@ -162,22 +175,30 @@ }; ///< Thermocouple inverse coefficient for positive cold junction temperature. static const U32 TEMP_EQUATION_RESISTOR_CALC = 1 << ( TEMP_SENSORS_ADC_BITS - 1 ); ///< Temperature sensors resistor calculation (2^(24 - 1)). -static const F32 TEMP_EQUATION_COEFF_A = 3.9083E-3; ///< ADC to temperature conversion coefficient A. -static const F32 TEMP_EQUATION_COEFF_B = -5.775E-7; ///< ADC to temperature conversion coefficient B. +static const F32 TEMP_EQUATION_COEFF_A = 3.9083E-3; ///< ADC to temperature conversion coefficient A. +static const F32 TEMP_EQUATION_COEFF_B = -5.775E-7; ///< ADC to temperature conversion coefficient B. +static const U32 TWO_TO_POWER_OF_8 = ( 1 << 8 ); ///< 2^8. +static const U32 TWO_TO_POWER_OF_23 = ( 1 << 23 ); ///< 2^23. +// The count cannot be within 0.1V of the rail on both sides therefore: +// Maximum ADC count -> (2^24) * ( 3.0V - 0.1V ) / 3V +// Minimum ADC count -> (2^24) * ( 0.1V - 0.0V ) / 3V +static const U32 TEMP_SENSORS_MAX_ADC_COUNT = ( BITS_24_FULL_SCALE * ( 3.0F - 0.1F ) ) / 3.0F; ///< Temperature sensors max allowed ADC count. +static const U32 TEMP_SESNORS_MIN_ADC_COUNT = ( BITS_24_FULL_SCALE * ( 0.1F - 0.0F ) ) / 3.0F; ///< Temperature sensors min allowed ADC count. + // ********** private function prototypes ********** 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, F32 adcConversionCoeff ); static void getHeaterInternalTemp( U32 TCIndex, U32 CJIndex ); -static void processTempSnsrsADCRead( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount, BOOL fpgaCheck ); -static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U16 adc, U32 fpgaError, U32 fpgaCount ); -static BOOL isADCReadValid( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ); +static void processTempSnsrsADCRead( U32 sensorIndex, U32 adc ); +static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U16 adc ); static void processADCRead( U32 sensorIndex, S32 adc ); static void publishTemperatureSensorsData( void ); static void monitorTemperatureSenors( void ); +static void checkBaroSensorCRC( void ); static void adjustTemperatureSensorsRefResistance( void ); /*********************************************************************//** @@ -186,19 +207,20 @@ * @details Inputs: none * @details Outputs: tempSensorsSelfTestState, tempSensorsExecState, * elapsedTime, internalHeatersConversionTimer, dataPublicationTimerCounter, - * tempSensors, fpgaRawADCReadInterval + * tempSensors, baroConvConsts * @return none *************************************************************************/ void initTemperatureSensors( void ) { U08 i; - // Initialize the variables - tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; - elapsedTime = 0; - internalHeatersConversionTimer = 0; - dataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; - fpgaRawADCReadInterval = 0; + tempSensorsExecState = TEMPSENSORS_EXEC_STATE_START; + elapsedTime = 0; + internalHeatersConversionTimer = 0; + dataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + baroConvConsts.coeffsCRC.data = 0; + baroConvConsts.hasCRCBeenChecked = FALSE; + baroConvConsts.waitForCoeffStartTimeMS = 0; /* NOTE: The temperature sensors do not have conversion coefficient. * The conversion coefficients are used for the heaters internal temperature sensors and @@ -214,6 +236,9 @@ benignPolynomialCalRecord( &tempSensorCalRecord.tempSensors[ i ] ); } + // Initialize the barometric sensor's temperature conversion constants + memset( &baroConvConsts, 0x0, sizeof( BARO_SENSOR_CONSTS_T ) ); + // Initialize TPi, THd, and TPo constants tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].gain = PRIMARY_HEATER_EXT_TEMP_SENSORS_GAIN; tempSensors[ TEMPSENSORS_INLET_PRIMARY_HEATER ].refResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; @@ -269,7 +294,7 @@ tempSensors[ TEMPSENSORS_TRIMMER_HEATER_INTERNAL ].maxAllowedTemp = HEATERS_INTERNAL_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; // FPGA board temperature conversion coefficient - tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].conversionCoeff = 503.975 / (F32)TWELVE_BIT_RESOLUTION; + tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].conversionCoeff = 503.975 / (F32)BITS_12_FULL_SCALE; tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].maxAllowedTemp = NON_FLUID_PATH_TEMP_SENSORS_MAX_ALLOWED_DEGREE_C; F32 conversionCoeff = 1.0 / 13584.0; @@ -308,10 +333,12 @@ // Persistent alarm for the temperature sensors error bit fault check initPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_ERROR_BIT_FAULT, TEMP_SENSORS_ERROR_BIT_TIMEOUT_MS, TEMP_SENSORS_ERROR_BIT_TIMEOUT_MS ); - // Persistent alarm for temperature sensors ADC error - // When the FPGA read count does not increment for a period of time, it is considered as an internal error of the temperature sensors - // driver. This is internal because FPGA does not error out if the FPGA read count does not increment. - initPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS ); + // Initialize the FPGA persistent alarms + initFPGAPersistentAlarm( TWO_WIRE_ADC_TEMP_SENSORS, ALARM_ID_DG_TWO_WIRE_SENSORS_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS); + initFPGAPersistentAlarm( THD_ADC_TEMP_SENSORS, ALARM_ID_DG_THD_SENSORS_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS); + initFPGAPersistentAlarm( TDI_ADC_TEMP_SENSORS, ALARM_ID_DG_TDI_SENSORS_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS); + initFPGAPersistentAlarm( TRO_ADC_TEMP_SENSORS, ALARM_ID_DG_TRO_SENSORS_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS); + initFPGAPersistentAlarm( BARO_SENSOR, ALARM_ID_DG_BARO_SENSOR_FPGA_FAULT, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS); } /*********************************************************************//** @@ -447,6 +474,11 @@ { temperature = getF32OverrideValue( &tempSensors[ TEMPSENSORS_OUTLET_REDUNDANT ].temperatureValues ); } + + if ( TEMPSENSORS_OUTLET_REDUNDANT == sensorIndex ) + { + temperature = getF32OverrideValue( &tempSensors[ TEMPSENSORS_INLET_DIALYSATE ].temperatureValues ); + } } #endif } @@ -461,6 +493,19 @@ /*********************************************************************//** * @brief + * The getBaroSensorTemperatureDiff function returns the barometric pressure + * sensor's temperature difference. + * @details Inputs: tempSensors + * @details Outputs: none + * @return barometric pressure sensor temperature difference + *************************************************************************/ +S32 getBaroSensorTemperatureDiff( void ) +{ + return tempSensors[ TEMPSENSORS_BAROMETRIC_TEMP_SENSOR ].baroTempSnsrDiff; +} + +/*********************************************************************//** + * @brief * The getADC2TempConversion function calculates the temperature from the * moving average ADC samples. * @details Inputs: tempEquationCoeffA, tempEquationCoeffB @@ -565,46 +610,33 @@ * @details Outputs: none * @param sensorIndex ID of temperature sensor to process * @param adc ADC value for the temperature sensor - * @param fpgaError reported FPGA error status - * @param fpgaCount reported FPGA read count - * @param fpgaCheck whether to check the FPGA error and count prior to converting - * the ADC to temperature * @return none *************************************************************************/ -static void processTempSnsrsADCRead( U32 sensorIndex, U32 adc, U32 fpgaError, U32 fpgaCount, BOOL fpgaCheck ) +static void processTempSnsrsADCRead( U32 sensorIndex, U32 adc ) { - BOOL isADCValid = TRUE; S32 convertedADC = (S32)( adc & MASK_OFF_U32_MSB ); - if ( TRUE == fpgaCheck ) - { - // All the sensors have ADC read and count values that have to be checked - // but the FPGA read and error counts are shared among some of the sensors so if that counts has been checked - // once, do not check it again - isADCValid = isADCReadValid( sensorIndex, fpgaError, fpgaCount ); - } - - // Some of the temperature sensors have an MSB bit that is used as an - // error flag. This flag will be a TRUE by default. - BOOL isTemperatureNotValid = FALSE; - switch( sensorIndex ) { - case TEMPSENSORS_LOAD_CELL_A1_B1: // 267 - case TEMPSENSORS_LOAD_CELL_A2_B2: // 279 - case TEMPSENSORS_CONDUCTIVITY_SENSOR_1: // 283 - case TEMPSENSORS_CONDUCTIVITY_SENSOR_2: // 287 - case TEMPSENSORS_OUTLET_PRIMARY_HEATER: // 291 - case TEMPSENSORS_INLET_PRIMARY_HEATER: // 295 - case TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR: // 299 - case TEMPSENSORS_OUTLET_REDUNDANT: // 303 - case TEMPSENSORS_INTERNAL_TRO_RTD: // 307 - case TEMPSENSORS_INLET_DIALYSATE: // 311 - case TEMPSENSORS_INTERNAL_TDI_RTD: // 315 + case TEMPSENSORS_LOAD_CELL_A1_B1: + case TEMPSENSORS_LOAD_CELL_A2_B2: + case TEMPSENSORS_CONDUCTIVITY_SENSOR_1: + case TEMPSENSORS_CONDUCTIVITY_SENSOR_2: + case TEMPSENSORS_OUTLET_PRIMARY_HEATER: + case TEMPSENSORS_INLET_PRIMARY_HEATER: + case TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR: + case TEMPSENSORS_OUTLET_REDUNDANT: + case TEMPSENSORS_INTERNAL_TRO_RTD: + case TEMPSENSORS_INLET_DIALYSATE: + case TEMPSENSORS_INTERNAL_TDI_RTD: case TEMPSENSORS_HEAT_DISINFECT: case TEMPSENSORS_INTERNAL_THD_RTD: { U08 i; + // Some of the temperature sensors have an MSB bit that is used as an + // error flag. This flag will be a TRUE by default. + BOOL isErrorBitNotValid = FALSE; + U32 faultySensorIndex = 0; // Shift bits by 31 to right to check the error bit status tempSensors[ sensorIndex ].sensorErrorBitStatus = adc >> SHIFT_BITS_BY_31; @@ -613,22 +645,17 @@ { // If that bit is a 1, there is either CRC error or Status error that are ored on top of each other // NOTE: only a few sensors have the error bit available but for simplicity, all the sensors are looped. - // This variable is zeroed in the init function and the sensors that do not use this bit are never checked ( and set) to + // This variable is zeroed in the init function and the sensors that do not use this bit are never checked (and set) to // any other values so those sensors will never trigger this fault. // If any of the sensors have this bit to be 1, set the error occurred be 1 - isTemperatureNotValid |= ( tempSensors[ i ].sensorErrorBitStatus > 0 ? TRUE : FALSE ); + if ( tempSensors[ i ].sensorErrorBitStatus > 0 ) + { + isErrorBitNotValid = TRUE; + faultySensorIndex = i; + } } -#ifndef DISABLE_FPGA_ALARMS_UNTIL_THE_NEW_PERSISTENT - // TODO for debugging only remove - if ( TRUE == isTemperatureNotValid ) - { - BOOL test = FALSE; - } - // TODO remove for debugging only - - checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_ERROR_BIT_FAULT, isTemperatureNotValid, sensorIndex, TEMP_SENSORS_ERROR_BIT_TIMEOUT_MS ); -#endif + checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_ERROR_BIT_FAULT, isErrorBitNotValid, faultySensorIndex, TEMP_SENSORS_ERROR_BIT_TIMEOUT_MS ); } break; @@ -639,12 +666,7 @@ break; } - // To update the moving average of a temperature sensor, both ADC and internal - // error flags must be valid - if ( ( TRUE == isADCValid ) && ( FALSE == isTemperatureNotValid ) ) - { - processADCRead( sensorIndex, convertedADC ); - } + processADCRead( sensorIndex, convertedADC ); } /*********************************************************************//** @@ -658,61 +680,13 @@ * @details Outputs: none * @param sensorIndex ID of temperature sensor to process * @param adc reported ADC value for temperature sensor - * @param fpgaError reported error status by FPGA - * @param fpgaCount reported read count by FPGA * @return none *************************************************************************/ -static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U16 adc, U32 fpgaError, U32 fpgaCount ) +static void processHtrsTempSnsrsADCRead( U32 sensorIndex, U16 adc ) { - if ( TRUE == isADCReadValid( sensorIndex, fpgaError, fpgaCount ) ) - { - S16 convert = (S16)adc; - processADCRead( sensorIndex, (S32)convert ); - } -} + S16 convert = (S16)adc; -/*********************************************************************//** - * @brief - * The isADCReadValid function checks if there is an FPGA error and FPGA - * count. If there is any FPGA, it raises an alarm. If the count has changed - * and the ADC value is not the same as the previous ADC read, it returns a - * TRUE, signaling that the ADC is valid to be processed. - * @details Inputs: tempSensors - * @details Outputs: tempSensors - * @param sensorIndex Temperature sensor index - * @param fpgaError FPGA error count - * @param fpgaCount FPGA read count - * @return returns TRUE if ADC was valid otherwise FALSE - *************************************************************************/ -static BOOL isADCReadValid( U32 sensorIndex, U32 fpgaError, U32 fpgaCount ) -{ - U08 i; - BOOL isADCValid = FALSE; - BOOL isTemperatureNotValid = FALSE; - // Check the status of FPGA error and FPGA count - BOOL isFPGAErrorZero = ( 0 == fpgaError ? TRUE : FALSE ); - BOOL isFPGACountChanging = ( tempSensors[ sensorIndex ].readCount != fpgaCount ? TRUE : FALSE ); - - if ( ( TRUE == isFPGAErrorZero ) && ( TRUE == isFPGACountChanging ) ) - { - tempSensors[ sensorIndex ].readCount = fpgaCount; - isADCValid = TRUE; - } - - tempSensors[ sensorIndex ].fpgaErrorStatus = ( ( FALSE == isFPGACountChanging ) || ( FALSE == isFPGAErrorZero ) ? TRUE : FALSE ); - - for ( i = 0; i < NUM_OF_TEMPERATURE_SENSORS; i++ ) - { - // Loop through all the sensors and read their FPGA error status - isTemperatureNotValid |= tempSensors[ sensorIndex ].fpgaErrorStatus; - } -#ifndef DISABLE_FPGA_ALARMS_UNTIL_THE_NEW_PERSISTENT - checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_FPGA_FAULT, isTemperatureNotValid, sensorIndex, TEMP_SENSORS_FPGA_ERROR_TIMEOUT_MS ); - - return isADCValid; -#else - return TRUE; -#endif + processADCRead( sensorIndex, (S32)convert ); } /*********************************************************************//** @@ -742,17 +716,16 @@ avgADCReads = tempSensors[ sensorIndex ].adcRunningSum >> SHIFT_BITS_BY_2_FOR_AVERAGING; // Calculate the average // Check if the average ADC is within the accepted range - tempSensors[ sensorIndex ].adcErrorStatus = ( ( (U32)avgADCReads < TEMP_SESNORS_MIN_ALLOWED_ADC_COUNT ) || - ( (U32)avgADCReads > TEMP_SENSORS_MAX_ALLOWED_ADC_COUNT ) ? TRUE : FALSE ); + tempSensors[ sensorIndex ].adcErrorStatus = ( ( (U32)avgADCReads < TEMP_SESNORS_MIN_ADC_COUNT ) || + ( (U32)avgADCReads > TEMP_SENSORS_MAX_ADC_COUNT ) ? TRUE : FALSE ); for ( i = 0; i < NUM_OF_TEMPERATURE_SENSORS; i++ ) { // Loop through the ADC errors isADCNotValid |= tempSensors[ sensorIndex ].adcErrorStatus; } -#ifndef DISABLE_FPGA_ALARMS_UNTIL_THE_NEW_PERSISTENT + checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSORS_ADC_FAULT, isADCNotValid, sensorIndex, avgADCReads ); -#endif // Different sensors have different ADC to temperature conversion methods switch( sensorIndex ) @@ -775,7 +748,7 @@ case TEMPSENSORS_FPGA_BOARD_SENSOR: // Temperature(C) = ((ADC x 503.975) / 4096) - 273.15 // The value of 503.975/4096 has been calculated and stored in the conversion coefficient variable of the structure - temperature = ( avgADCReads * tempSensors[ sensorIndex ].conversionCoeff ) - CELSIUS_TO_KELVIN_CONVERSION; + temperature = ( avgADCReads * tempSensors[ sensorIndex ].conversionCoeff ) - CELSIUS_TO_KELVIN_CONVERSION; break; case TEMPSENSORS_LOAD_CELL_A1_B1: @@ -791,7 +764,12 @@ break; case TEMPSENSORS_BAROMETRIC_TEMP_SENSOR: - temperature = 30.0; + { + tempSensors[ sensorIndex ].baroTempSnsrDiff = (S32)avgADCReads - ( baroConvConsts.refTemperature * TWO_TO_POWER_OF_8 ); + S64 baroSnsrTemperature = BARO_SENSOR_REFERENCE_TEMP_C + ( ( tempSensors[ sensorIndex ].baroTempSnsrDiff * + baroConvConsts.temperatureCoeff ) / TWO_TO_POWER_OF_23 ); + temperature = (F32)( (U32)( baroSnsrTemperature ) / 100 ); + } break; default: @@ -811,7 +789,7 @@ * The handleExecStart function waits for a period of time and switches to * the state that reads the ADC values from FPGA. * @details Inputs: elapsedTime - * @details Outputs: elapsedTime + * @details Outputs: elapsedTime, baroCoeffsWaitToRcvStartTime * @return the next state of the state machine *************************************************************************/ static TEMPSENSORS_EXEC_STATES_T handleExecStart( void ) @@ -825,8 +803,9 @@ // A delay to let FPGA to boot up else if ( TRUE == didTimeout( elapsedTime, ADC_FPGA_READ_DELAY ) ) { - elapsedTime = 0; - state = TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; + elapsedTime = 0; + baroConvConsts.waitForCoeffStartTimeMS = getMSTimerCount(); + state = TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; } return state; @@ -846,66 +825,72 @@ U32 errorCount = 0; U32 readCount = 0; - // Look at the error counter and the specific error flag to make sure the error is a temperature sensor - // Add a byte array to have bits for each sensor to find out exactly what sensor failed - if ( ++fpgaRawADCReadInterval >= FPGA_RAW_ADC_READ_INTERVAL_COUNT ) - { - errorCount = (U32)getFPGARTDErrorCount(); - readCount = (U32)getFPGARTDReadCount(); - processTempSnsrsADCRead( TEMPSENSORS_INLET_PRIMARY_HEATER, getFPGATPiTemp(), errorCount, readCount, TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_OUTLET_PRIMARY_HEATER, getFPGATPoTemp(), errorCount, readCount, FALSE ); - processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_1, getFPGACD1Temp(), errorCount, readCount, FALSE ); - processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_2, getFPGACD2Temp(), errorCount, readCount, FALSE ); + errorCount = (U32)getFPGARTDErrorCount(); + readCount = (U32)getFPGARTDReadCount(); + checkFPGAPersistentAlarms( TWO_WIRE_ADC_TEMP_SENSORS, errorCount, readCount ); + processTempSnsrsADCRead( TEMPSENSORS_INLET_PRIMARY_HEATER, getFPGATPiTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_OUTLET_PRIMARY_HEATER, getFPGATPoTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_1, getFPGACD1Temp() ); + processTempSnsrsADCRead( TEMPSENSORS_CONDUCTIVITY_SENSOR_2, getFPGACD2Temp() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR, getFPGACondSnsrInternalTemp() ); + #ifndef _RELEASE_ - if ( ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) != SW_CONFIG_ENABLE_VALUE ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) + if ( ( getSoftwareConfigStatus( SW_CONFIG_ENABLE_V3_SYSTEM ) != SW_CONFIG_ENABLE_VALUE ) && ( getCurrentOperationMode() != DG_MODE_INIT ) ) #endif - { - errorCount = (U32)getFPGATHdErrorCount(); - readCount = (U32)getFPGATHdReadCount(); - processTempSnsrsADCRead( TEMPSENSORS_HEAT_DISINFECT, getFPGATHdTemp(), errorCount, readCount, TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_THD_RTD, getFPGATHdInternalTemp(), errorCount, readCount, FALSE ); - } + { + errorCount = (U32)getFPGATHdErrorCount(); + readCount = (U32)getFPGATHdReadCount(); - errorCount = (U32)getFPGATRoErrorCount(); - readCount = (U32)getFPGATRoReadCount(); - processTempSnsrsADCRead( TEMPSENSORS_OUTLET_REDUNDANT, getFPGATRoTemp(), errorCount, readCount, TRUE ); + checkFPGAPersistentAlarms( THD_ADC_TEMP_SENSORS, errorCount, readCount ); + processTempSnsrsADCRead( TEMPSENSORS_HEAT_DISINFECT, getFPGATHdTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_THD_RTD, getFPGATHdInternalTemp() ); - errorCount = (U32)getFPGATDiErrorCount(); - readCount = (U32)getFPGATDiReadCount(); - processTempSnsrsADCRead( TEMPSENSORS_INLET_DIALYSATE, getFPGATDiTemp(), errorCount, readCount, TRUE ); + // Make sure the baro sensor coefficients are not corrupted + checkBaroSensorCRC(); - errorCount = (U32)getFPGAPrimaryHeaterFlags(); - readCount = (U32)getFPGAPrimaryHeaterReadCount(); - processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, getFPGAPrimaryHeaterTemp(), errorCount, readCount ); - processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, getFPGAPrimaryColdJunctionTemp(), errorCount, readCount ); + baroConvConsts.refTemperature = getFPGABaroReferenceTemperature(); + baroConvConsts.temperatureCoeff = getFPGABaroTempCoeffOfTemperature(); + errorCount = getFPGABaroErrorCount(); + readCount = getFPGABaroReadCount(); - errorCount = (U32)getFPGATrimmerHeaterFlags(); - readCount = (U32)getFPGATrimmerHeaterReadCount(); - processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, getFPGATrimmerHeaterTemp(), errorCount, readCount ); - processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, getFPGATrimmerColdJunctionTemp(), errorCount, readCount ); + checkFPGAPersistentAlarms( BARO_SENSOR, errorCount, readCount ); + processTempSnsrsADCRead( TEMPSENSORS_BAROMETRIC_TEMP_SENSOR, getFPGABaroTemperature() ); + } - // NOTE: FPGA board temperature sensor is different from the rest of the sensors. This sensor does not have FPGA count and error - // coming from FPGA. It is kept here to do moving average on the values. The supporting functions need to see the FPGA read count - // incrementing internally so there will not be any errors. - U32 simulatedCounter = tempSensors[ TEMPSENSORS_FPGA_BOARD_SENSOR ].readCount; - processTempSnsrsADCRead( TEMPSENSORS_FPGA_BOARD_SENSOR, getFPGABoardTemp(), 0, ++simulatedCounter, TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A1_B1, getFPGALoadCellsA1B1Temp(), getFPGAADC1ErrorCount(), getFPGAADC1ReadCount(), TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A2_B2, getFPGALoadCellsA2B2Temp(), getFPGAADC2ErrorCount(), getFPGAADC2ReadCount(), TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_TRO_RTD, getFPGATRoInternalTemp(), getFPGATRoErrorCount(), getFPGATRoReadCount(), TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_TDI_RTD, getFPGATDiInternalTemp(), getFPGATDiErrorCount(), getFPGATDiReadCount(), TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR, getFPGACondSnsrInternalTemp(), getFPGARTDErrorCount(), getFPGARTDReadCount(), TRUE ); - processTempSnsrsADCRead( TEMPSENSORS_BAROMETRIC_TEMP_SENSOR, getFPGABaroTemperature(), getFPGABaroErrorCount(), getFPGABaroReadCount(), TRUE ); + errorCount = (U32)getFPGATRoErrorCount(); + readCount = (U32)getFPGATRoReadCount(); - // Check if time has elapsed to calculate the internal temperature of the heaters - if ( ++internalHeatersConversionTimer >= HEATERS_INTERNAL_TEMPERTURE_CALCULATION_INTERVAL ) - { - getHeaterInternalTemp( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ); - getHeaterInternalTemp( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ); - internalHeatersConversionTimer = 0; - } + checkFPGAPersistentAlarms( TRO_ADC_TEMP_SENSORS, errorCount, readCount ); + processTempSnsrsADCRead( TEMPSENSORS_OUTLET_REDUNDANT, getFPGATRoTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_TRO_RTD, getFPGATRoInternalTemp() ); - fpgaRawADCReadInterval = 0; + errorCount = (U32)getFPGATDiErrorCount(); + readCount = (U32)getFPGATDiReadCount(); + + checkFPGAPersistentAlarms( TDI_ADC_TEMP_SENSORS, errorCount, readCount ); + processTempSnsrsADCRead( TEMPSENSORS_INLET_DIALYSATE, getFPGATDiTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_INTERNAL_TDI_RTD, getFPGATDiInternalTemp() ); + + // The heaters' temperature sensors have read and error counts but the heaters' internal sensors are only updated for information + // and no alarm shall be raised on them including the read and error counts + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, getFPGAPrimaryHeaterTemp() ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION, getFPGAPrimaryColdJunctionTemp() ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, getFPGATrimmerHeaterTemp() ); + processHtrsTempSnsrsADCRead( TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION, getFPGATrimmerColdJunctionTemp() ); + + // The FPGA board sensor does not have read and error count. + // The load cells' temperature sensors are not read and a constant value is reported to firmware by FPGA + processTempSnsrsADCRead( TEMPSENSORS_FPGA_BOARD_SENSOR, getFPGABoardTemp() ); + processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A1_B1, getFPGALoadCellsA1B1Temp() ); + processTempSnsrsADCRead( TEMPSENSORS_LOAD_CELL_A2_B2, getFPGALoadCellsA2B2Temp() ); + + // Check if time has elapsed to calculate the internal temperature of the heaters + if ( ++internalHeatersConversionTimer >= HEATERS_INTERNAL_TEMPERTURE_CALCULATION_INTERVAL ) + { + getHeaterInternalTemp( TEMPSENSORS_PRIMARY_HEATER_THERMO_COUPLE, TEMPSENSORS_PRIMARY_HEATER_COLD_JUNCTION ); + getHeaterInternalTemp( TEMPSENSORS_TRIMMER_HEATER_THERMO_COUPLE, TEMPSENSORS_TRIMMER_HEATER_COLD_JUNCTION ); + internalHeatersConversionTimer = 0; } return TEMPSENSORS_EXEC_STATE_GET_ADC_VALUES; @@ -973,22 +958,52 @@ #endif { U08 i; - F32 temperature = 0.0; + F32 temperature = 0.0F; BOOL isTemperatureOutOfRange = FALSE; + F32 alarmTemperature = 0.0F; + U08 alarmIndex = 0; for ( i = 0; i < NUM_OF_TEMPERATURE_SENSORS; i++ ) { - temperature = getTemperatureValue( i ); - - // Check both temperature and to be in range - if ( ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > tempSensors[ i ].maxAllowedTemp ) ) && - ( getCurrentOperationMode() != DG_MODE_INIT ) ) + switch ( i ) { - isTemperatureOutOfRange |= TRUE; + case TEMPSENSORS_INLET_PRIMARY_HEATER: + case TEMPSENSORS_HEAT_DISINFECT: + case TEMPSENSORS_OUTLET_PRIMARY_HEATER: + case TEMPSENSORS_CONDUCTIVITY_SENSOR_1: + case TEMPSENSORS_CONDUCTIVITY_SENSOR_2: + case TEMPSENSORS_OUTLET_REDUNDANT: + case TEMPSENSORS_INLET_DIALYSATE: + case TEMPSENSORS_FPGA_BOARD_SENSOR: + case TEMPSENSORS_LOAD_CELL_A1_B1: + case TEMPSENSORS_LOAD_CELL_A2_B2: + case TEMPSENSORS_INTERNAL_TRO_RTD: + case TEMPSENSORS_INTERNAL_TDI_RTD: + case TEMPSENSORS_INTERNAL_THD_RTD: + case TEMPSENSORS_INTERNAL_COND_TEMP_SENSOR: + case TEMPSENSORS_BAROMETRIC_TEMP_SENSOR: + // All the temperature sensors are monitored except the heaters' temperature sensors. + // The heaters' temperature sensors are only broadcast for information + temperature = getTemperatureValue( i ); + + // Check both temperature and to be in range + if ( ( ( temperature < TEMP_SENSORS_MIN_ALLOWED_DEGREE_C ) || ( temperature > tempSensors[ i ].maxAllowedTemp ) ) && + ( getCurrentOperationMode() != DG_MODE_INIT ) ) + { + isTemperatureOutOfRange |= TRUE; + alarmIndex = i; + alarmTemperature = temperature; + } + break; + + default: + // Ignore the rest of the sensors + break; } + } - //checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, isTemperatureOutOfRange, i, temperature ); + checkPersistentAlarm( ALARM_ID_DG_TEMPERATURE_SENSOR_OUT_OF_RANGE, isTemperatureOutOfRange, alarmIndex, alarmTemperature ); } } @@ -1002,7 +1017,7 @@ *************************************************************************/ static void adjustTemperatureSensorsRefResistance( void ) { - // The default are DVT changes + // The defaults are DVT values U32 primaryAndCondSensorsRefResistance = PRIMARY_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; U32 externalTempSesnorsRefResitance = TRIMMER_HEATER_EXT_TEMP_SENSORS_REF_RESISTANCE; @@ -1026,7 +1041,52 @@ tempSensors[ TEMPSENSORS_INLET_DIALYSATE ].refResistance = externalTempSesnorsRefResitance; } +/*********************************************************************//** + * @brief + * The checkBaroSensorCRC function gets all the barometric sensor coefficients + * and calls crc4 function to calculate the CRC of the coefficients and compares + * them to the provided CRC by the manufacturer. + * @details Inputs: hasBaroCoeffsBeenChecked + * @details Outputs: hasBaroCoeffsBeenChecked + * @return none + *************************************************************************/ +static void checkBaroSensorCRC( void ) +{ + U32 baroCRC = (U32)getFPGABaroCoeffsCRC(); + BOOL hasCRCChanged = ( baroCRC != getU32OverrideValue( &baroConvConsts.coeffsCRC ) ? TRUE : FALSE ); + // Once FPGA is ready get the barometric sensor's temperature conversion constants + if ( TRUE == hasCRCChanged ) + { + U08 calculatedCRC; + BARO_SENSORS_COEFFS_T baroCoeffs; + + baroCoeffs.mfgInfo = getFPGABaroMfgInfo(); + baroCoeffs.pressSensitivity = getFPGABaroPressureSensitivity(); + baroCoeffs.pressOffset = getFPGABaroPressureOffset(); + baroCoeffs.tempCoeffOfPressSens = getFPGABaroTempCoeffOfPressSensitvity(); + baroCoeffs.tempCoeffPressOffset = getFPGABaroTempCoeffOfPressOffset(); + baroCoeffs.referenceTemp = getFPGABaroReferenceTemperature(); + baroCoeffs.tempCoeffOfTemp = getFPGABaroTempCoeffOfTemperature(); + baroCoeffs.crc = MASK_OFF_LSB & getFPGABaroCoeffsCRC(); + calculatedCRC = crc4( (U16*)&baroCoeffs, sizeof( baroCoeffs ) ); + baroConvConsts.coeffsCRC.data = baroCRC; + baroCRC = (U16)( baroCRC & MASK_OFF_MSB ) & MASK_OFF_NIBBLE_MSB; + baroConvConsts.hasCRCBeenChecked = TRUE; + + if ( calculatedCRC != baroCRC ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, calculatedCRC, baroCoeffs.crc ); + } + } + else if ( ( TRUE == didTimeout( baroConvConsts.waitForCoeffStartTimeMS, BARO_SENSOR_WAIT_FOR_COEFF_TIME_OUT_MS ) ) && + ( FALSE == baroConvConsts.hasCRCBeenChecked ) ) + { + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_BAROMETRIC_SENSOR_COEFFS_BAD_CRC, 0, baroCRC ); + } +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Controllers/TemperatureSensors.h =================================================================== diff -u -ra4669c80291e85fa5ce17d77ebcfd0c882831202 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Controllers/TemperatureSensors.h (.../TemperatureSensors.h) (revision a4669c80291e85fa5ce17d77ebcfd0c882831202) +++ firmware/App/Controllers/TemperatureSensors.h (.../TemperatureSensors.h) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -7,8 +7,8 @@ * * @file TemperatureSensors.h * -* @author (last) Dara Navaei -* @date (last) 12-Jul-2022 +* @author (last) Michael Garthwaite +* @date (last) 30-Aug-2022 * * @author (original) Dara Navaei * @date (original) 08-Apr-2020 @@ -80,6 +80,7 @@ F32 loadCellA2B2; ///< Load cell A2/B2 temperature sensor F32 internalTHDORTD; ///< THDo RTD channel temperature sensor F32 internalTDIRTD; ///< TDI RTD channel temperature sensor + F32 interalTHDRTD; ///< THd RTD channel temperature sensor F32 internalCondSnsrTemp; ///< Conductivity Sensor internal temperature sensor U32 primaryThermoCoupleRaw; ///< Primary heaters thermocouple raw ADC value // TODO remove later? U32 primaryColdjuncRaw; ///< Primary heaters cold junction raw ADC value // TODO remove later? Index: firmware/App/DGCommon.h =================================================================== diff -u -r33d262afee2fd0dd9d714ed86a21b8907ed84e25 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/DGCommon.h (.../DGCommon.h) (revision 33d262afee2fd0dd9d714ed86a21b8907ed84e25) +++ firmware/App/DGCommon.h (.../DGCommon.h) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -25,7 +25,7 @@ #define DG_VERSION_MAJOR 0 #define DG_VERSION_MINOR 6 #define DG_VERSION_MICRO 0 -#define DG_VERSION_BUILD 30 +#define DG_VERSION_BUILD 31 // ********** build switches ********** Index: firmware/App/Modes/ModeService.c =================================================================== diff -u -ra4669c80291e85fa5ce17d77ebcfd0c882831202 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Modes/ModeService.c (.../ModeService.c) (revision a4669c80291e85fa5ce17d77ebcfd0c882831202) +++ firmware/App/Modes/ModeService.c (.../ModeService.c) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -7,8 +7,8 @@ * * @file ModeService.c * -* @author (last) Dara Navaei -* @date (last) 03-Aug-2022 +* @author (last) Michael Garthwaite +* @date (last) 07-Sep-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -54,10 +54,11 @@ U32 transitionToServiceMode( void ) { // Deenergize all the actuators - setCPLDCleanLEDColor( CPLD_CLEAN_LED_OFF ); + deenergizeActuators(); + initServiceMode(); - return 0; + return serviceState; } /*********************************************************************//** @@ -76,7 +77,7 @@ break; default: - // TODO - s/w fault + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_SERVICE_MODE_INVALID_EXEC_STATE, serviceState ) serviceState = DG_SERVICE_STATE_START; break; } Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -r3b70632c04247a6973960e1f37ae73eb4384a6b7 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 3b70632c04247a6973960e1f37ae73eb4384a6b7) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -26,6 +26,7 @@ #include "Pressures.h" #include "Reservoirs.h" #include "ROPump.h" +#include "RTC.h" #include "SystemComm.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" @@ -95,7 +96,7 @@ pendingStartDGChemicalDisinfectRequest = FALSE; // Reset the heaters efficiency for another treatment - resetHeatersEfficiency(); + resetHeatersEstimationGain(); // Initialize the reservoirs parameters for another treatment. // This is to make sure the boolean flag for the first fill is set to TRUE. @@ -116,6 +117,8 @@ deenergizeActuators(); + setCPLDCleanLEDColor( CPLD_CLEAN_LED_OFF ); + return standbyState; } @@ -180,29 +183,35 @@ // if HD requests water sample, go to water sample state else if ( TRUE == flushFilterRequest ) { - flushFilterRequest = FALSE; + flushFilterRequest = FALSE; filterFlushStartTime = getMSTimerCount(); + setValveState( VPI, VALVE_STATE_OPEN ); + state = DG_STANDBY_MODE_STATE_FLUSH_FILTER; } else if ( TRUE == pendingStartDGRequest ) { pendingStartDGRequest = FALSE; + signalSyncToHD(); requestNewOperationMode( DG_MODE_GENE ); } else if ( TRUE == pendingStartDGFlushRequest ) { pendingStartDGFlushRequest = FALSE; + requestNewOperationMode( DG_MODE_FLUS ); } else if ( TRUE == pendingStartDGHeatDisinfectRequest ) { pendingStartDGHeatDisinfectRequest = FALSE; + requestNewOperationMode( DG_MODE_HEAT ); } else if ( TRUE == pendingStartDGChemicalDisinfectRequest ) { pendingStartDGChemicalDisinfectRequest = FALSE; + requestNewOperationMode( DG_MODE_CHEM ); } @@ -230,7 +239,7 @@ state = DG_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE; } - if ( FILTER_FLUSH_DATA_PUBLISH_INTERVAL <= filterFlushPublishTimerCounter++ ) + if ( ++filterFlushPublishTimerCounter >= FILTER_FLUSH_DATA_PUBLISH_INTERVAL ) { STANDBY_MODE_DATA_T data; @@ -380,8 +389,11 @@ if ( DG_STANDBY_MODE_STATE_IDLE == standbyState ) { - result = TRUE; + result = TRUE; pendingStartDGRequest = TRUE; + + // Reset the volume accumulator for the next run + resetROGenerateVolumeL(); } return result; @@ -399,9 +411,10 @@ BOOL result = FALSE; // If DG is in standby mode or in the solo mode and the standby mode is in Idle state, request DG flush - if ( ( DG_MODE_STAN == getCurrentOperationMode() && DG_STANDBY_MODE_STATE_IDLE == standbyState ) || ( DG_MODE_SOLO == getCurrentOperationMode() ) ) + if ( ( DG_MODE_STAN == getCurrentOperationMode() ) && ( DG_STANDBY_MODE_STATE_IDLE == standbyState ) || ( DG_MODE_SOLO == getCurrentOperationMode() ) ) { DG_CMD_RESPONSE_T cmdResponse; + OPN_CLS_STATE_T concCap = getSwitchStatus( CONCENTRATE_CAP ); OPN_CLS_STATE_T diaCap = getSwitchStatus( DIALYSATE_CAP ); cmdResponse.commandID = DG_CMD_START_FLUSH; Index: firmware/App/Modes/OperationModes.c =================================================================== diff -u -r98a1a2a624373a1d140daed0136522ab6e635237 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision 98a1a2a624373a1d140daed0136522ab6e635237) +++ firmware/App/Modes/OperationModes.c (.../OperationModes.c) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -7,8 +7,8 @@ * * @file OperationModes.c * -* @author (last) Dara Navaei -* @date (last) 15-Jul-2022 +* @author (last) Michael Garthwaite +* @date (last) 08-Aug-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -416,6 +416,34 @@ /*********************************************************************//** * @brief + * The testSetOperationMode function will transition to a given operation + * mode if the transition is legal. + * @details Inputs: none + * @details Outputs: modeRequest[] + * @param newMode ID of requested mode to transition to + * @return TRUE if request successful, FALSE if not + *************************************************************************/ +BOOL testSetOperationMode( DG_OP_MODE_T newMode ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + DG_OP_MODE_T check = MODE_TRANSITION_TABLE[ currentMode ][ newMode ]; + + // Is mode transition legal? + if ( check == newMode ) + { + requestNewOperationMode( newMode ); + result = TRUE; + } + } + + return result; +} + +/*********************************************************************//** + * @brief * The testSetDGOpModePublishIntervalOverride function overrides the * DG operation mode publish interval. * @details Inputs: none Index: firmware/App/Services/AlarmMgmtSWFaults.h =================================================================== diff -u -r3b70632c04247a6973960e1f37ae73eb4384a6b7 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision 3b70632c04247a6973960e1f37ae73eb4384a6b7) +++ firmware/App/Services/AlarmMgmtSWFaults.h (.../AlarmMgmtSWFaults.h) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -85,6 +85,7 @@ SW_FAULT_ID_PERSISTENT_ALARM_INVALID_INDEX, SW_FAULT_ID_CONCENTRATE_PUMP_EXEC_INVALID_STATE, // 55 SW_FAULT_ID_CONCENTRATE_PUMP_INVALID_PUMP_ID, + SW_FAULT_ID_SEMAPHORE_IN_USE_TIMEOUT, SW_FAULT_ID_SERVICE_MODE_INVALID_EXEC_STATE, SW_FAULT_ID_UV_REACTORS_INVALID_EXEC_STATE, SW_FAULT_ID_UV_REACTORS_INVALID_SELF_TEST_STATE, @@ -131,6 +132,9 @@ SW_FAULT_ID_PHANTOM_INTERRUPT, // 100 SW_FAULT_ID_ILLEGAL_MEM_ACCESS, SW_FAULT_ID_INVALID_CHEMICAL_BOTTLE_SELECTED, + SW_FAULT_ID_INVALID_FPGA_SENSOR_GROUP_SELECTED, + SW_FAULT_ID_INVALID_FPGA_ERROR_GROUP_SELECTED, + SW_FAULT_ID_INVALID_LED_COLOR_SELECTED, // 105 NUM_OF_SW_FAULT_IDS } SW_FAULT_ID_T; Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r98a1a2a624373a1d140daed0136522ab6e635237 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 98a1a2a624373a1d140daed0136522ab6e635237) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -7,8 +7,8 @@ * * @file Reservoirs.c * -* @author (last) Dara Navaei -* @date (last) 03-Aug-2022 +* @author (last) Michael Garthwaite +* @date (last) 08-Aug-2022 * * @author (original) Sean * @date (original) 18-Mar-2020 @@ -1063,4 +1063,32 @@ return result; } +/*********************************************************************//** + * @brief + * The testTareReservoir function tares a given reservoir. It is assumed + * that the given reservoir has already been drained. + * @details Inputs: drainVolumeTargetMl + * @details Outputs: drainVolumeTargetMl + * @param value ID of reservoir to tare + * @return TRUE if tare successful, FALSE if not + *************************************************************************/ +BOOL testTareReservoir( U32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + if ( value < NUM_OF_DG_RESERVOIRS ) + { + result = TRUE; + tareLoadCellRequest = TRUE; + testSetReservoirDrainVolumeMlOverride( 0 ); + tareLoadCellsAtEmpty( (DG_RESERVOIR_ID_T)value ); + testResetReservoirDrainVolumeMlOverride(); + } + } + + return result; +} + /**@}*/ Index: firmware/App/Services/Reservoirs.h =================================================================== diff -u -r98a1a2a624373a1d140daed0136522ab6e635237 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision 98a1a2a624373a1d140daed0136522ab6e635237) +++ firmware/App/Services/Reservoirs.h (.../Reservoirs.h) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -7,8 +7,8 @@ * * @file Reservoirs.h * -* @author (last) Dara Navaei -* @date (last) 31-May-2022 +* @author (last) Michael Garthwaite +* @date (last) 08-Aug-2022 * * @author (original) Sean * @date (original) 18-Mar-2020 @@ -141,7 +141,8 @@ BOOL testSetReservoirFillVolumeMlOverride( U32 value ); BOOL testResetReservoirFillVolumeMlOverride( void ); BOOL testSetReservoirDrainVolumeMlOverride( U32 value ); -BOOL testResetReservoirDrainVolumeMlOverride( void ); +BOOL testResetReservoirDrainVolumeMlOverride( void ); +BOOL testTareReservoir( U32 value ); /**@}*/ Index: firmware/App/Services/SystemComm.c =================================================================== diff -u -r46bf7baaa9d8095e0405b018fcd4bc594907797e -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision 46bf7baaa9d8095e0405b018fcd4bc594907797e) +++ firmware/App/Services/SystemComm.c (.../SystemComm.c) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -7,8 +7,8 @@ * * @file SystemComm.c * -* @author (last) Dara Navaei -* @date (last) 12-Jul-2022 +* @author (last) Michael Garthwaite +* @date (last) 08-Aug-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -888,6 +888,10 @@ handleDGScheduledRunsRequest( message ); break; + case MSG_ID_HD_REQUEST_DG_SERVICE_MODE: + handleServiceModeRequest( message ); + break; + // NOTE: This case must be last case MSG_ID_DG_TESTER_LOGIN_REQUEST: handleTesterLogInRequest( message ); @@ -1196,6 +1200,14 @@ handleResendAllAlarmsCommand( message ); break; + case MSG_ID_DG_SET_OP_MODE_REQUEST: + handleTestSetOpModeRequest( message ); + break; + + case MSG_ID_DG_RESERVOIR_TARE_REQUEST: + handleTestTareReservoirRequest( message ); + break; + default: // TODO - unrecognized message ID received - ignore break; Index: firmware/App/Services/SystemCommMessages.c =================================================================== diff -u -r3b70632c04247a6973960e1f37ae73eb4384a6b7 -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision 3b70632c04247a6973960e1f37ae73eb4384a6b7) +++ firmware/App/Services/SystemCommMessages.c (.../SystemCommMessages.c) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -301,6 +301,9 @@ payloadPtr += sizeof( U32 ); data = almData2.data.uInt.data; memcpy( payloadPtr, &data, sizeof( U32 ) ); + // Pad with space for 3 U32s - set to zero - unused for DG + payloadPtr += ( sizeof( U32) * 3 ); + memset( payloadPtr, 0, sizeof( U32) * 3 ); // serialize the message (w/ sync, CRC, and appropriate CAN padding) and add serialized message data to appropriate comm buffer result = serializeMessage( msg, COMM_BUFFER_OUT_CAN_DG_ALARM, ACK_REQUIRED ); @@ -390,6 +393,30 @@ /*********************************************************************//** * @brief + * The handleRTCSyncFromHD function handles an HD date/time broadcast message + * from the HD. + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return none + *************************************************************************/ +void handleRTCSyncFromHD( MESSAGE_T *message ) +{ + // Only sync RTC to HD date/time when ... + if ( TRUE == syncDG2HDDateTime() ) + { + if ( sizeof( RTC_DATA_T ) == message->hdr.payloadLen ) + { + RTC_DATA_T epoch; + + memcpy( &epoch, message->payload, sizeof( RTC_DATA_T ) ); + setRTCEpoch( epoch.epochTime ); + } + } +} + +/*********************************************************************//** + * @brief * The handleAlarmClear function handles a clear alarm message from the HD. * @details Inputs: none * @details Outputs: message handled @@ -556,14 +583,15 @@ void handleDGSendConcentrateMixingRatios( MESSAGE_T *message ) { MESSAGE_T msg; - - DG_ACID_CONCENTRATES_RECORD_T acid = getAcidConcentrateCalRecord(); - DG_BICARB_CONCENTRATES_RECORD_T bicarb = getBicarbConcentrateCalRecord(); + DG_ACID_CONCENTRATES_RECORD_T acid; + DG_BICARB_CONCENTRATES_RECORD_T bicarb; // By the time these are requested, the prepare time is no longer needed since the concentrate lines are // primed before the actual treatment starts - U32 fillPrepTimeMS = 0; + U32 fillPrepTimeMS = 0; + U08 *payloadPtr = msg.payload; - U08 *payloadPtr = msg.payload; + getAcidConcentrateCalRecord( &acid ); + getBicarbConcentrateCalRecord( &bicarb ); // Create a message record blankMessage( &msg ); @@ -1103,7 +1131,7 @@ if ( TRUE == heaterCmd.startHeater ) { - BOOL isSet = setHeaterTargetTemperature( DG_TRIMMER_HEATER, heaterCmd.targetTemp ); + BOOL isSet = setHeaterTargetTemperature( DG_TRIMMER_HEATER, getTrimmerHeaterTargetTemperature() ); if ( TRUE == isSet ) { @@ -1431,12 +1459,13 @@ if ( message->hdr.payloadLen == sizeof( U32 ) + sizeof( U32 ) ) { U32 mode; + U32 subMode; - // NOTE: the HD operations modes broadcast message contains the mode and submode states - // In this case, only the mode is needed. The mode is received to check if HD is in treatment - // and therefore, DG can void the last disinfect. memcpy( payloadPtr, &mode, sizeof( U32 ) ); - setHDOperationMode( mode ); + payloadPtr += sizeof( U32 ); + memcpy( payloadPtr, &subMode, sizeof( U32 ) ); + + setHDOperationMode( mode, subMode ); status = TRUE; } @@ -3691,6 +3720,30 @@ /*********************************************************************//** * @brief +* The handleResendAllAlarmsCommand function handles a request to re-send +* all active DG alarms. +* @details Inputs: none +* @details Outputs: message handled +* @param message a pointer to the message to handle +* @return none +*************************************************************************/ +void handleResendAllAlarmsCommand( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + // verify payload length + if ( 0 == message->hdr.payloadLen ) + { + handleResendActiveAlarmsRequest(); + result = TRUE; + } + + // respond to request + sendTestAckResponseMsg( (MSG_ID_T)message->hdr.msgID, result ); +} + +/*********************************************************************//** +* @brief * The handleServiceModeRequest function handles a request to enter service * mode. * @details Inputs: none Index: firmware/App/Services/SystemCommMessages.h =================================================================== diff -u -r46bf7baaa9d8095e0405b018fcd4bc594907797e -rd5f2ac4d84453feb1b782f35f9d69432977a95f6 --- firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision 46bf7baaa9d8095e0405b018fcd4bc594907797e) +++ firmware/App/Services/SystemCommMessages.h (.../SystemCommMessages.h) (revision d5f2ac4d84453feb1b782f35f9d69432977a95f6) @@ -7,8 +7,8 @@ * * @file SystemCommMessages.h * -* @author (last) Dara Navaei -* @date (last) 25-May-2022 +* @author (last) Michael Garthwaite +* @date (last) 07-Sep-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -158,6 +158,12 @@ // MSG_ID_HD_OP_MODE BOOL handleSetHDOperationMode( MESSAGE_T *message ); +// MSG_ID_UI_REQUEST_SERVICE_MODE +void handleServiceModeRequest( MESSAGE_T *message ); + +// MSG_ID_DG_RESPONSE_SERVICE_MODE_REQUEST +BOOL sendServiceModeResponse( BOOL accepted, U32 rejCode ); + // *********** public test support message functions ********** // MSG_TESTER_LOG_IN @@ -395,6 +401,15 @@ // MSG_ID_HD_REQUEST_DG_ALARMS void handleResendAllAlarmsCommand( MESSAGE_T *message ); +// MSG_ID_DG_SET_OP_MODE_REQUEST +void handleTestSetOpModeRequest( MESSAGE_T *message ); + +// MSG_ID_DG_RESERVOIR_TARE_REQUEST +void handleTestTareReservoirRequest( MESSAGE_T *message ); + +// MSG_ID_HD_OP_MODE +BOOL handleSetHDOperationMode( MESSAGE_T *message ); + /**@}*/ #endif