Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -re7dd4d4f0d9cbb0d8e7abb994a16f0389251e4ba -r239f565516c73aae797288effcfdf1fca0a361a0 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision e7dd4d4f0d9cbb0d8e7abb994a16f0389251e4ba) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 239f565516c73aae797288effcfdf1fca0a361a0) @@ -86,8 +86,7 @@ #define ROP_PSI_TO_PWM_DC(p) ( 0.2 + ( (F32)((p) - 100) * 0.01 ) ) ///< Conversion factor from target PSI to PWM duty cycle estimate. #define SAFETY_SHUTDOWN_TIMEOUT ( 3 * MS_PER_SECOND ) ///< RO pump safety shutdown activation timeout in ms. -#define ROP_FEEDBACK_0_PCT_DUTY_CYCLE_VOLTAGE 0.0 ///< RO pump 0% duty cycle feedback voltage. -#define ROP_FEEDBACK_100_PCT_DUTY_CYCLE_VOLTAGE 2.5 ///< RO pump 100% duty cycle feedback voltage. +#define ROP_FEEDBACK_0_PCT_DUTY_CYCLE_VOLTAGE 2.51 ///< RO pump 0% duty cycle feedback voltage. #define ROP_DUTY_CYCLE_OUT_OF_RANGE_TOLERANCE 0.05 ///< RO pump duty cycle out of range tolerance. #define DATA_PUBLISH_COUNTER_START_COUNT 50 ///< Data publish counter start count. @@ -335,7 +334,7 @@ void execROPumpMonitor( void ) { U16 roFlowReading = getFPGAROPumpFlowRate(); - U16 roFeedbackVoltage = getIntADCVoltageConverted( INT_ADC_RO_PUMP_FEEDBACK_DUTY_CYCLE ); + F32 roFeedbackVoltage = getIntADCVoltageConverted( INT_ADC_RO_PUMP_FEEDBACK_DUTY_CYCLE ); // Update sum for flow average calculation measuredFlowReadingsSum += (S32)roFlowReading; @@ -378,7 +377,9 @@ } #ifndef IGNORE_RO_PUMP_MONITOR - F32 roFeedbackDutyCycle = ROP_FEEDBACK_100_PCT_DUTY_CYCLE_VOLTAGE / roFeedbackVoltage; + // The feedback voltage is on the 0V line so when the duty cycle is 0, the feedback is 2.5V + // The duty cycle is calculated by getting the 1 - (ratio of feedback / to the voltage at 0 percent duty cycle). + roPumpFeedbackDutyCyclePct = 1.0 - ( roFeedbackVoltage / ROP_FEEDBACK_0_PCT_DUTY_CYCLE_VOLTAGE ); // To monitor the flow, the control mode must be in closed loop mode and the pump should be control to flow state // If the pump is controlled to the maximum pressure, the flow might be different from the target flow for more than 10% @@ -397,28 +398,16 @@ checkPersistentAlarm( ALARM_ID_FLOW_RATE_OUT_OF_LOWER_RANGE, isFlowOutOfLowerRange, currentFlow, targetFlow ); } - if ( ( FALSE == isROPumpOn ) && ( roFeedbackVoltage != ROP_FEEDBACK_0_PCT_DUTY_CYCLE_VOLTAGE ) ) - { - checkPersistentAlarm( ALARM_ID_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE, TRUE, roFeedbackVoltage, ROP_FEEDBACK_0_PCT_DUTY_CYCLE_VOLTAGE ); + // Check whether the Duty cycle is out of range + BOOL isDCOutOfRange = ( fabs( roPumpFeedbackDutyCyclePct - roPumpDutyCyclePctSet ) > ROP_DUTY_CYCLE_OUT_OF_RANGE_TOLERANCE ? TRUE : FALSE ); - // Check if it has timed out - if ( TRUE == isAlarmActive( ALARM_ID_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE ) ) - { - activateSafetyShutdown(); - } - } + checkPersistentAlarm( ALARM_ID_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE, isDCOutOfRange, roPumpFeedbackDutyCyclePct, roPumpDutyCyclePctSet ); - if ( TRUE == isROPumpOn ) + // Check if it the alarm has timed out and if the pump is supposed to be off but it is still on, activate the safety shutdown + if ( ( TRUE == isAlarmActive( ALARM_ID_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE ) ) && ( FALSE == isROPumpOn ) ) { - BOOL isDCOutOfRange = ( fabs( roFeedbackDutyCycle - roPumpDutyCyclePctSet ) > ROP_DUTY_CYCLE_OUT_OF_RANGE_TOLERANCE ? TRUE : FALSE ); - roPumpFeedbackDutyCyclePct = roFeedbackDutyCycle; - - checkPersistentAlarm( ALARM_ID_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE, TRUE, roFeedbackDutyCycle, roPumpDutyCyclePctSet ); + activateSafetyShutdown(); } - else - { - checkPersistentAlarm( ALARM_ID_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE, FALSE, roFeedbackDutyCycle, roPumpDutyCyclePctSet ); - } #endif // Publish RO pump data on interval