Index: firmware/App/Controllers/DrainPump.c =================================================================== diff -u -ra2c32d4d221603054ca9ad7a097112caebf08c4e -rc2fe204db1b8926994b5eee78afa1b516c97d02c --- firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision a2c32d4d221603054ca9ad7a097112caebf08c4e) +++ firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision c2fe204db1b8926994b5eee78afa1b516c97d02c) @@ -22,6 +22,7 @@ #include "DrainPump.h" #include "FPGA.h" +#include "NVDataMgmt.h" #include "OperationModes.h" #include "PersistentAlarm.h" #include "PIControllers.h" @@ -48,7 +49,7 @@ #define DRAIN_PUMP_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Interval (ms/task time) at which the Drain Pump data is published on the CAN bus. -#define DRP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the Drain pump is controlled. +#define DRP_CONTROL_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the Drain pump is controlled. TODO original one is 1 second #define RPM_2_DAC_SLOPE 0.0547 ///< RPM to DAC conversion slope. #define RPM_2_DAC_INTERCEPT 2.9968 ///< RPM to DAC conversion intercept. @@ -104,7 +105,7 @@ static OVERRIDE_U32_T drainPumpDataPublishInterval = { DRAIN_PUMP_DATA_PUB_INTERVAL, DRAIN_PUMP_DATA_PUB_INTERVAL, - 0, 0 }; ///< Interval (in ms) at which to publish RO flow data to CAN bus. + 0, 0 }; ///< Interval (in ms) at which to publish drain pump data to CAN bus. static U32 targetDrainPumpRPM = 0; ///< Target drain pump RPM. static F32 targetDrainPumpOutletPressure = 0.0; ///< Target outlet pressure for the drain pump. @@ -115,6 +116,7 @@ static DRAIN_PUMP_STATE_T pendingDrainPumpCmd = DRAIN_PUMP_OFF_STATE; ///< Delayed (pending) drain pump command. static F32 pendingDrainPumpCmdTarget = 0.0; ///< Delayed (pending) drain pump command target (rpm or PSI depending on command). static U32 pendingDrainPumpCmdCountDown = 0; ///< Delayed (pending) drain pump command count down timer (in task intervals). +static F32 modeRecircTargetFlushVolL = 0.0; ///< Mode recirculation target flush volume in liters. /// ADC to RPM conversion coefficient or RPM to ADC conversion. static const F32 CONVERSION_COEFF = SEC_PER_MIN / ( 2 * TOGGLE_PERIOD_RESOLUTION_SECONDS * ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION ); @@ -127,6 +129,7 @@ static void stopDrainPump( void ); static void publishDrainPumpData( void ); static U32 getPublishDrainPumpDataInterval( void ); +static BOOL processCalibrationData( void ); /*********************************************************************//** * @brief @@ -140,6 +143,7 @@ stopDrainPump(); hasClosedLoopBeenRequested = FALSE; + modeRecircTargetFlushVolL = 0.0; // Initialize the drain pump PI controller initializePIController( PI_CONTROLLER_ID_DRAIN_PUMP, DRAIN_PUMP_MIN_DAC, @@ -297,7 +301,8 @@ targetDrainPumpRPM = 0; drainPumpState = DRAIN_PUMP_OFF_STATE; hasClosedLoopBeenRequested = FALSE; - drainPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; // Set the control mode to none + drainPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; + drainPumpControlModeSet = drainPumpControlMode; drainControlTimerCounter = 0; } @@ -328,12 +333,13 @@ // The RPM is only checked in open loop state that the pump is run at a fixed RPM. // The persistent alarm waits for a couple of seconds before raising an alarm, this is supposed to cover // when the pump is turned on and it takes a while to ramp up to target RPM. - if( PUMP_CONTROL_MODE_OPEN_LOOP == drainPumpControlModeSet ) + if ( PUMP_CONTROL_MODE_OPEN_LOOP == drainPumpControlModeSet ) { - U32 targetRPM = getTargetDrainPumpRPM(); + // Using abs since the read RPM can be above or below the target + U32 rpmDiff = abs( getTargetDrainPumpRPM() - currentDrainPumpRPM ); - // Check if RPM is out of range. Using fabs since the read RPM can be above or below the target. - BOOL isRPMOutOfRange = fabs( targetRPM - currentDrainPumpRPM ) > MAX_ALLOWED_OPEN_LOOP_RPM_OUT_OF_RANGE; + // Check if RPM is out of range + BOOL isRPMOutOfRange = ( rpmDiff > MAX_ALLOWED_OPEN_LOOP_RPM_OUT_OF_RANGE ? TRUE : FALSE ); checkPersistentAlarm( ALARM_ID_DRAIN_PUMP_RPM_OUT_OF_RANGE, isRPMOutOfRange, currentDrainPumpRPM, MAX_ALLOWED_OPEN_LOOP_RPM_OUT_OF_RANGE ); } @@ -417,6 +423,31 @@ /*********************************************************************//** * @brief + * The execDrainPumpSelfTest function executes the drain pump's self-test. + * @details Inputs: none + * @details Outputs: none + * @return PressuresSelfTestResult (SELF_TEST_STATUS_T) + *************************************************************************/ +SELF_TEST_STATUS_T execDrainPumpSelfTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + BOOL calStatus = processCalibrationData(); + + if ( TRUE == calStatus ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; + } + + return result; +} + +/*********************************************************************//** + * @brief * The getTargetDrainPumpRPM function gets the current target drain pump * RPM. * @details Inputs: targetDrainPumpRPM @@ -455,6 +486,19 @@ /*********************************************************************//** * @brief + * The getRecirculationDrainVol function returns the mode recirculation + * target flush volume. + * @details Inputs: modeRecircTargetFlushVolL + * @details Outputs: none + * @return modeRecircTargetFlushVolL which is a float + *************************************************************************/ +F32 getRecirculationDrainVol( void ) +{ + return modeRecircTargetFlushVolL; +} + +/*********************************************************************//** + * @brief * The handleDrainPumpOffState function handles the drain pump off state of * the drain pump controller state machine. * @details Inputs: drainPumpControlModeSet, drainPumpDACSet, drainPumpDAC @@ -610,6 +654,39 @@ } } +/*********************************************************************//** + * @brief + * The processCalibrationData function gets the calibration data and makes + * sure it is valid by checking the calibration date. The calibration date + * should not be 0. + * @details Inputs: none + * @details Outputs: modeRecircTargetFlushVolL + * @return TRUE if the calibration record is valid, otherwise FALSE + *************************************************************************/ +static BOOL processCalibrationData( void ) +{ + BOOL status = TRUE; + + // Get the calibration record from NVDataMgmt + DG_DRAIN_LINE_VOLUME_T calData = getDGDrainLineVolumeRecord(); + + // Check if the calibration data that was received from NVDataMgmt is legitimate + // The calibration date item should not be zero. If the calibration date is 0, + // then the data is not stored in the NV memory or it was corrupted. + if ( 0 == calData.calibrationTime ) + { +#ifndef SKIP_CAL_CHECK + activateAlarmNoData( ALARM_ID_DG_DRAIN_LINE_VOLUME_INVALID_CAL_RECORD ); + status = FALSE; +#endif + } + + // The calibration data was valid, update the local copy + modeRecircTargetFlushVolL = calData.volume; + + return status; +} + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/