Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r7462b03d6159cb3cd5ffc20ef2914222d69af13c -r4b25bf00656b9067a13541014fa1333386a7ed95 --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 7462b03d6159cb3cd5ffc20ef2914222d69af13c) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 4b25bf00656b9067a13541014fa1333386a7ed95) @@ -7,8 +7,8 @@ * * @file ROPump.c * -* @author (last) Dara Navaei -* @date (last) 03-Nov-2022 +* @author (last) Michael Garthwaite +* @date (last) 21-Nov-2022 * * @author (original) Sean * @date (original) 04-Apr-2020 @@ -133,7 +133,8 @@ static RO_PI_FLOW_PROFILES_T currentROPumpProfile; ///< RO Pump flow profile table. -///< Most values are currently the same until future efforts into fine tuning op modes. +///< Most values are currently the same until future efforts into tuning op modes. +///< TODO: Fine tune each op mode. static PI_CONTROLLER_PROFILE_DATA_T roPIFlowProfiles[ NUM_OF_RO_PI_FLOW_PROFILES ] = { // Kp Ki uMin uMax maxErrorSumStep Control Interval { ROP_FLOW_CONTROL_P_COEFFICIENT, ROP_FLOW_CONTROL_I_COEFFICIENT, MIN_RO_PUMP_DUTY_CYCLE, MAX_RO_PUMP_DUTY_CYCLE, ROP_PWM_STEP_LIMIT, ROP_CONTROL_INTERVAL }, ///< RO_PI_FLOW_PROFILE_FLUSH @@ -157,7 +158,7 @@ static void setROPumpControlSignalDutyCycle( F32 dutyCycle ); static void stopROPump( void ); static void publishROPumpData( void ); -static F32 getROFeedbackVoltage( void ); +static F32 getROFeedbackDutyCycle( void ); /*********************************************************************//** * @brief @@ -218,9 +219,9 @@ * The setROPumpTargetFlowRate function sets a new target flow rate for the * RO pump. * @details Inputs: targetROPumpPressure, targetROPumpFlowRate, - * roPumpControlMode, rampUp2FlowTimeoutCounter + * roPumpControlMode, rampUp2FlowTimeoutCounter, currentROPumpProfile * @details Outputs: targetROPumpPressure, targetROPumpFlowRate, - * roPumpControlMode, rampUp2FlowTimeoutCounter + * roPumpControlMode, rampUp2FlowTimeoutCounter, roPumpPWMDutyCyclePct * @param roFlowRate which is target RO flow rate * @param maxPressure which is the maximum allowed pressure that the RO pump * can reach @@ -338,10 +339,10 @@ * The execROPumpMonitor function executes the RO pump monitor. The RO flow * sensor is read, filtered, converted to L/min and calibrated. * @details Inputs: measuredFlowReadingsSum, flowFilterCounter, - * measuredROFlowRateLPM, measuredROFlowRateLPM, roPumpState, - * flowOutOfRangeCounter, roPumpControlMode + * measuredROFlowRateLPM, roPumpState, roPumpFeedbackDutyCyclePct, + * flowOutOfRangeCounter, roPumpControlMode, Ppo * @details Outputs: measuredFlowReadingsSum, flowFilterCounter, - * measuredROFlowRateLPM, measuredROFlowRateLPM + * measuredROFlowRateLPM, roVolumeL, roPumpFeedbackDutyCyclePct * @return none *************************************************************************/ void execROPumpMonitor( void ) @@ -396,9 +397,9 @@ // 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.data = 1.0F - ( roFeedbackVoltage / ROP_FEEDBACK_0_PCT_DUTY_CYCLE_VOLTAGE ); - isDutyCylceOutOfRange = ( fabs( getROFeedbackVoltage() - roPumpDutyCyclePctSet ) > ROP_DUTY_CYCLE_OUT_OF_RANGE_TOLERANCE ? TRUE : FALSE ); + isDutyCylceOutOfRange = ( fabs( getROFeedbackDutyCycle() - roPumpDutyCyclePctSet ) > ROP_DUTY_CYCLE_OUT_OF_RANGE_TOLERANCE ? TRUE : FALSE ); - checkPersistentAlarm( ALARM_ID_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE, isDutyCylceOutOfRange, getROFeedbackVoltage(), roPumpDutyCyclePctSet ); + checkPersistentAlarm( ALARM_ID_RO_PUMP_DUTY_CYCLE_OUT_OF_RANGE, isDutyCylceOutOfRange, getROFeedbackDutyCycle(), 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 ) ) @@ -538,17 +539,17 @@ /*********************************************************************//** * @brief - * The getROFeedbackVoltage function returns the RO pump feedback - * voltage. + * The getROFeedbackDutyCyle function returns the RO pump feedback + * duty cycle. * @details Inputs: roPumpFeedbackDutyCyclePct * @details Outputs: none - * @return ro pump voltage feedback + * @return ro pump feedback duty cycle *************************************************************************/ -static F32 getROFeedbackVoltage( void ) +static F32 getROFeedbackDutyCycle( void ) { - F32 feedbackVotlage = getF32OverrideValue( &roPumpFeedbackDutyCyclePct ); + F32 feedbackdutyCycle = getF32OverrideValue( &roPumpFeedbackDutyCyclePct ); - return feedbackVotlage; + return feedbackdutyCycle; } /*********************************************************************//** @@ -627,7 +628,7 @@ RO_PUMP_STATE_T state = RO_PUMP_CONTROL_TO_TARGET_FLOW_STATE; // Control at set interval - if ( ++roControlTimerCounter >= roPumpControlInterval && roPumpControlMode == PUMP_CONTROL_MODE_CLOSED_LOOP ) + if ( ( ++roControlTimerCounter >= roPumpControlInterval ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == roPumpControlMode ) ) { // Get the pressure to use it for setting the control F32 actualPressure = getMeasuredDGPressure( PRESSURE_SENSOR_RO_PUMP_OUTLET ); @@ -778,7 +779,7 @@ pumpData.roPumpDutyCycle = roPumpDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR; pumpData.roMeasFlowRateLPM = getMeasuredFlowRateLPM( RO_FLOW_SENSOR ); pumpData.roPumpState = (U32)roPumpState; - pumpData.roPumpFBDutyCycle = getROFeedbackVoltage() * FRACTION_TO_PERCENT_FACTOR; + pumpData.roPumpFBDutyCycle = getROFeedbackDutyCycle() * 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; @@ -807,8 +808,7 @@ roPIFlowProfiles[ profileID ].Kp, roPIFlowProfiles[ profileID ].Ki, roPIFlowProfiles[ profileID ].uMin, roPIFlowProfiles[ profileID ].uMax ); - setPIControllerStepLimit( PI_CONTROLLER_ID_RO_PUMP_FLOW, CONTROLLER_SIGNAL_MAX_ERROR_PER_STEP, - roPIFlowProfiles[ profileID ].maxErrorSumStep ); + setPIControllerStepLimit( PI_CONTROLLER_ID_RO_PUMP_FLOW, roPIFlowProfiles[ profileID ].maxErrorSumStep ); currentROPumpProfile = profileID; } else @@ -861,6 +861,7 @@ return dutyCyclePct; } + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ @@ -998,14 +999,14 @@ /*********************************************************************//** * @brief - * The testSetDrainPumpMeasuredRPMOverride function overrides the drain pump - * measured RPM data. + * The testSetROPumpMeasuredFeedbackDutyCycleOverride function overrides the + * feedback duty cycle. * @details Inputs: none - * @details Outputs: drainPumpMeasuredRPM - * @param value override drain pump measured data + * @details Outputs: roPumpFeedbackDutyCyclePct + * @param value override feedback duty cycle. * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetROPumpMeasuredFeedbackVoltageOverride( F32 value ) +BOOL testSetROPumpMeasuredFeedbackDutyCycleOverride( F32 value ) { BOOL status = FALSE; @@ -1026,13 +1027,13 @@ /*********************************************************************//** * @brief - * The testResetDrainPumpMeasuredRPMOverride function resets the drain pump - * measured RPM data. + * The testResetROPumpMeasuredFeedbackDutyCycleOverride function resets the + * feedback duty cycle. * @details Inputs: none - * @details Outputs: drainPumpMeasuredRPM + * @details Outputs: roPumpFeedbackDutyCyclePct * @return TRUE if override reset successful, FALSE if not *************************************************************************/ -BOOL testResetROPumpMeasuredFeedbackVoltageOverride( void ) +BOOL testResetROPumpMeasuredFeedbackDutyCycleOverride( void ) { BOOL status = FALSE;