Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r958fe9290555ff010f74d81bf4fdb819295607b4 -r900d1b6dbb5dfa9d33213e8f93029366d428390d --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 958fe9290555ff010f74d81bf4fdb819295607b4) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 900d1b6dbb5dfa9d33213e8f93029366d428390d) @@ -117,7 +117,7 @@ static BOOL isROPumpOn; ///< RO pump is currently running. static F32 roPumpPWMDutyCyclePct; ///< Initial RO pump PWM duty cycle. static F32 roPumpDutyCyclePctSet; ///< Currently set RO pump PWM duty cycle. -static F32 roPumpFeedbackDutyCyclePct; ///< RO pump feedback duty cycle in percent. +static OVERRIDE_F32_T roPumpFeedbackDutyCyclePct = { 0, 0, 0, 0 }; ///< RO pump feedback duty cycle in percent. static PUMP_CONTROL_MODE_T roPumpControlMode; ///< Requested RO pump control mode. static F32 pendingROPumpCmdMaxPressure; ///< Delayed (pending) RO pump max pressure (in PSI) setting. static F32 pendingROPumpCmdTargetFlow; ///< Delayed (pending) RO pump target flow rate (in mL/min) setting. @@ -130,6 +130,7 @@ static F32 roPumpOpenLoopTargetDutyCycle; ///< Target RO pump open loop PWM. static F32 roVolumeL; ///< RO water generated in liters. static U32 roPumpControlInterval; ///< RO pump Control interval. +static RO_PI_FLOW_PROFILES_T currentROPumpProfile; ///< RO Pump flow profile table. static PI_CONTROLLER_PROFILE_DATA_T roPIFlowProfiles[ NUM_OF_RO_PI_FLOW_PROFILES ] = @@ -197,7 +198,7 @@ roPumpState = RO_PUMP_OFF_STATE; roPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; isROPumpOn = FALSE; - roPumpFeedbackDutyCyclePct = 0.0F; + roPumpFeedbackDutyCyclePct.data = 0.0F; roVolumeL = 0.0F; targetROPumpFlowRateLPM = 0.0F; roPumpPWMDutyCyclePct = 0.0F; @@ -207,6 +208,7 @@ pendingROPumpCmdCountDown = 0; targetROPumpMaxPressure = 0.0F; roPumpControlInterval = ROP_CONTROL_INTERVAL; + currentROPumpProfile = RO_PI_FLOW_PROFILE_GEN_IDLE; } /*********************************************************************//** @@ -392,10 +394,10 @@ { // 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.0F - ( roFeedbackVoltage / ROP_FEEDBACK_0_PCT_DUTY_CYCLE_VOLTAGE ); - isDutyCylceOutOfRange = ( fabs( roPumpFeedbackDutyCyclePct - roPumpDutyCyclePctSet ) > ROP_DUTY_CYCLE_OUT_OF_RANGE_TOLERANCE ? TRUE : FALSE ); + roPumpFeedbackDutyCyclePct.data = 1.0F - ( roFeedbackVoltage / ROP_FEEDBACK_0_PCT_DUTY_CYCLE_VOLTAGE ); + isDutyCylceOutOfRange = ( fabs( getROFeedbackVoltage() - roPumpDutyCyclePctSet ) > ROP_DUTY_CYCLE_OUT_OF_RANGE_TOLERANCE ? TRUE : FALSE ); - checkPersistentAlarm( ALARM_ID_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE, isDutyCylceOutOfRange, roPumpFeedbackDutyCyclePct, roPumpDutyCyclePctSet ); + checkPersistentAlarm( ALARM_ID_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE, isDutyCylceOutOfRange, getROFeedbackVoltage(), roPumpDutyCyclePctSet ); // 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 ) ) @@ -431,7 +433,7 @@ roPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; roPumpState = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; // Get the initial guess of the duty cycle - roPumpPWMDutyCyclePct = ROP_FLOW_TO_PWM_DC( targetROPumpFlowRateLPM ); + roPumpPWMDutyCyclePct = roPumpFlowToPWM( currentROPumpProfile, targetROPumpFlowRateLPM ); roControlTimerCounter = 0; isROPumpOn = TRUE; } @@ -536,6 +538,21 @@ /*********************************************************************//** * @brief + * The getROFeedbackVoltage function returns the RO pump feedback + * voltage. + * @details Inputs: roPumpFeedbackDutyCyclePct + * @details Outputs: none + * @return ro pump voltage feedback + *************************************************************************/ +static F32 getROFeedbackVoltage( void ) +{ + F32 feedbackVotlage = getF32OverrideValue( &roPumpFeedbackDutyCyclePct ); + + return feedbackVotlage; +} + +/*********************************************************************//** + * @brief * The resetROGenerateVolumeL function resets the RO generated volume in liters. * @details Inputs: none * @details Outputs: roVolumeL @@ -564,7 +581,7 @@ { // Set pump to on isROPumpOn = TRUE; - roPumpDutyCyclePctSet = ROP_FLOW_TO_PWM_DC( getTargetROPumpFlowRateLPM() ); + roPumpDutyCyclePctSet = roPumpFlowToPWM( currentROPumpProfile, getTargetROPumpFlowRateLPM() ); setROPumpControlSignalDutyCycle( roPumpDutyCyclePctSet ); state = RO_PUMP_RAMP_UP_TO_TARGET_FLOW_STATE; } @@ -800,7 +817,7 @@ pumpData.roPumpDutyCycle = roPumpDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR; pumpData.roMeasFlowRateLPM = getMeasuredFlowRateLPM( RO_FLOW_SENSOR ); pumpData.roPumpState = (U32)roPumpState; - pumpData.roPumpFBDutyCycle = roPumpFeedbackDutyCyclePct * FRACTION_TO_PERCENT_FACTOR; + pumpData.roPumpFBDutyCycle = getROFeedbackVoltage() * FRACTION_TO_PERCENT_FACTOR; broadcastData( MSG_ID_RO_PUMP_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&pumpData, sizeof( RO_PUMP_DATA_T ) ); roPumpDataPublicationTimerCounter = 0; @@ -812,7 +829,7 @@ * The setROPIFlowProfile function sets the RO flow PI controller to new coefficients * and calculates the initial duty cycle. * @details Inputs: targetROPumpFlowRateLPM - * @details Outputs: roPumpControlInterval + * @details Outputs: roPumpControlInterval, currentROPumpProfile * @param profileID the ID for which flow profile to be used * @return none *************************************************************************/ @@ -828,6 +845,8 @@ initializePIController( PI_CONTROLLER_ID_RO_PUMP_FLOW, initialControlDutyCycle, roPIFlowProfiles[ profileID ].Kp, roPIFlowProfiles[ profileID ].Ki, roPIFlowProfiles[ profileID ].uMin, roPIFlowProfiles[ profileID ].uMax ); + + currentROPumpProfile = profileID; } else { @@ -1014,4 +1033,55 @@ return result; } +/*********************************************************************//** + * @brief + * The testSetDrainPumpMeasuredRPMOverride function overrides the drain pump + * measured RPM data. + * @details Inputs: none + * @details Outputs: drainPumpMeasuredRPM + * @param value override drain pump measured data + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetROPumpMeasuredFeedbackVoltageOverride( F32 value ) +{ + BOOL status = FALSE; + + // Check if the requested drain pump RPM is within range + if ( ( value >= MIN_RO_PUMP_DUTY_CYCLE ) && ( value <= MAX_RO_PUMP_DUTY_CYCLE ) ) + { + // Check if the user is logged in + if ( TRUE == isTestingActivated() ) + { + roPumpFeedbackDutyCyclePct.ovData = value; + roPumpFeedbackDutyCyclePct.override = OVERRIDE_KEY; + status = TRUE; + } + } + + return status; +} + +/*********************************************************************//** + * @brief + * The testResetDrainPumpMeasuredRPMOverride function resets the drain pump + * measured RPM data. + * @details Inputs: none + * @details Outputs: drainPumpMeasuredRPM + * @return TRUE if override reset successful, FALSE if not + *************************************************************************/ +BOOL testResetROPumpMeasuredFeedbackVoltageOverride( void ) +{ + BOOL status = FALSE; + + // Check if the user is logged in + if ( TRUE == isTestingActivated() ) + { + roPumpFeedbackDutyCyclePct.ovData = roPumpFeedbackDutyCyclePct.ovInitData + roPumpFeedbackDutyCyclePct.override = OVERRIDE_RESET; + status = TRUE; + } + + return status; +} + /**@}*/