Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r6f62e99f0beb50422927a666ce79ef517dc19e7e -rc7ed4f90b600fe684097654f150e4972646ffec9 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 6f62e99f0beb50422927a666ce79ef517dc19e7e) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision c7ed4f90b600fe684097654f150e4972646ffec9) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2022 Diality Inc. - All Rights Reserved. +* Copyright (c) 2020-2022 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file ROPump.c * * @author (last) Dara Navaei -* @date (last) 05-Jan-2022 +* @date (last) 24-Feb-2022 * * @author (original) Sean * @date (original) 04-Apr-2020 @@ -67,7 +67,7 @@ #define FLOW_SAMPLES_TO_AVERAGE ( 250 / TASK_PRIORITY_INTERVAL ) ///< Averaging flow data over 250 ms intervals. #define FLOW_AVERAGE_MULTIPLIER ( 1.0 / (F32)FLOW_SAMPLES_TO_AVERAGE ) ///< Optimization - multiplying is faster than dividing. -#define RO_FLOW_ADC_TO_LPM_FACTOR 300 ///< Conversion factor from ADC counts to LPM (liters/min) for RO flow rate (multiply this by inverse of FPGA reading). +#define RO_FLOW_ADC_TO_LPM_FACTOR 300.0 ///< Conversion factor from ADC counts to LPM (liters/min) for RO flow rate (multiply this by inverse of FPGA reading). #define ROP_FLOW_TO_PWM_SLOPE 0.1 ///< Slope of flow to PWM line equation. #define ROP_FLOW_TO_PWM_INTERCEPT 0.0 ///< Intercept of flow to PWM line equation. @@ -86,10 +86,11 @@ #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. + /// Enumeration of RO pump states. typedef enum ROPump_States { @@ -139,6 +140,7 @@ static U32 flowFilterCounter = 0; ///< Flow filtering counter. static DG_FLOW_SENSORS_CAL_RECORD_T flowSensorsCalRecord; ///< Flow sensors calibration record. static OVERRIDE_F32_T measuredROFlowRateWithConcPumpsLPM = { 0.0, 0.0, 0.0, 0 }; ///< Measure RO flow rate with concentrate pumps (L/min). +static DG_RO_PUMP_CAL_RECORD_T roPumpCalRecord; ///< RO pump calibration record. // ********** private function prototypes ********** @@ -159,7 +161,7 @@ * @details Inputs: roControlTimerCounter,roPumpOpenLoopTargetDutyCycle, * roPumpFlowRateRunningSum, roPumpPressureRunningSum, measuredFlowReadingsSum, * flowFilterCounter, flowVerificationCounter, roPumpState, roPumpControlMode - * roPumpDataPublicationTimerCounter + * roPumpDataPublicationTimerCounter, rawFlowLP * @details Outputs: none * @return none *************************************************************************/ @@ -191,7 +193,7 @@ roPumpOpenLoopTargetDutyCycle = 0; measuredFlowReadingsSum = 0; flowFilterCounter = 0; - roPumpDataPublicationTimerCounter = 0; + roPumpDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; roPumpState = RO_PUMP_OFF_STATE; roPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; isROPumpOn = FALSE; @@ -378,7 +380,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 +401,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 @@ -493,10 +485,14 @@ SELF_TEST_STATUS_T execROPumpSelfTest( void ) { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + BOOL calStatus = FALSE; - BOOL calStatus = getNVRecord2Driver( GET_CAL_FLOW_SENSORS, (U08*)&flowSensorsCalRecord, sizeof( DG_FLOW_SENSORS_CAL_RECORD_T ), - NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD ); + calStatus |= getNVRecord2Driver( GET_CAL_FLOW_SENSORS, (U08*)&flowSensorsCalRecord, sizeof( DG_FLOW_SENSORS_CAL_RECORD_T ), + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_DG_FLOW_SENSORS_INVALID_CAL_RECORD ); + calStatus |= getNVRecord2Driver( GET_CAL_RO_PUMP_RECORD, (U08*)&roPumpCalRecord, sizeof( DG_RO_PUMP_CAL_RECORD_T ), + NUM_OF_CAL_DATA_FLOW_SENSORS, ALARM_ID_NO_ALARM ); + if ( TRUE == calStatus ) { result = SELF_TEST_STATUS_PASSED; @@ -824,7 +820,7 @@ { RO_PUMP_DATA_T pumpData; - pumpData.roPumpTgtFlowRate = getTargetROPumpFlowRate(); + pumpData.roPumpTgtFlowRateLM = getTargetROPumpFlowRate(); pumpData.roPumpTgtPressure = getTargetROPumpPressure(); pumpData.measROFlowRate = getMeasuredROFlowRateLPM(); pumpData.roPumpDutyCycle = roPumpDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR;