Index: firmware/App/Controllers/DrainPump.c =================================================================== diff -u -r3d8b84b8ce7ee9526fbabccb9e51d691a3df6305 -r6915ff465d44eb7bc1552016c4dd5321a51e3402 --- firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 3d8b84b8ce7ee9526fbabccb9e51d691a3df6305) +++ firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 6915ff465d44eb7bc1552016c4dd5321a51e3402) @@ -26,6 +26,7 @@ #include "PersistentAlarm.h" #include "PIControllers.h" #include "Pressures.h" +#include "SafetyShutdown.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" #include "TaskPriority.h" @@ -65,6 +66,12 @@ #define OPEN_LOOP_RPM_OUT_OF_RANGE_PERCENT 0.1 ///< Maximum allowed RPM out of range from target RPM in open loop percent. #define OPEN_LOOP_RPM_OUT_OF_RANGE_TIME_OUT ( 5 * MS_PER_SECOND ) ///< Open loop RPM out of range time out in ms. +#define DRAIN_PUMP_ENABLE_SPI3_PORT_MASK 0x00000020 ///< CS5 - Out put GPIO for pump enable. +#define SET_DRAIN_PUMP_ENABLE() {mibspiREG3->PC3 |= DRAIN_PUMP_ENABLE_SPI3_PORT_MASK;} ///< drain pump enable set macro. +#define CLR_DRAIN_PUMP_ENABLE() {mibspiREG3->PC3 &= ~DRAIN_PUMP_ENABLE_SPI3_PORT_MASK;} ///< drain pump enable clear macro. + +#define SAFETY_SHUTDOWN_TIMEOUT_COUNT ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< drain pump safety shutdown activation timeout in counts. + /// Enumeration of drain pump states. typedef enum DrainPump_States { @@ -83,35 +90,32 @@ NUM_OF_DRAIN_PUMP_SELF_TEST_STATES ///< Number of drain pump self-test states } DRAIN_PUMP_SELF_TEST_STATE_T; -#define DRAIN_PUMP_ENABLE_SPI3_PORT_MASK 0x00000020 ///< CS5 - Out put GPIO for pump enable. -#define SET_DRAIN_PUMP_ENABLE() {mibspiREG3->PC3 |= DRAIN_PUMP_ENABLE_SPI3_PORT_MASK;} ///< drain pump enable set macro. -#define CLR_DRAIN_PUMP_ENABLE() {mibspiREG3->PC3 &= ~DRAIN_PUMP_ENABLE_SPI3_PORT_MASK;} ///< drain pump enable clear macro. - // ********** private data ********** -static DRAIN_PUMP_STATE_T drainPumpState = DRAIN_PUMP_OFF_STATE; ///< current state of drain pump controller state machine -static U32 drainPumpDataPublicationTimerCounter = 0; ///< used to schedule drain pump data publication to CAN bus -static U32 drainPumpDAC = 0; ///< initial drain pump DAC value -static U32 drainPumpDACSet = 0; ///< currently set drain pump DAC value -static PUMP_CONTROL_MODE_T drainPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; ///< requested drain pump control mode -static PUMP_CONTROL_MODE_T drainPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< currently set drain pump control mode +static DRAIN_PUMP_STATE_T drainPumpState = DRAIN_PUMP_OFF_STATE; ///< current state of drain pump controller state machine. +static U32 drainPumpDataPublicationTimerCounter = 0; ///< used to schedule drain pump data publication to CAN bus. +static U32 drainPumpDAC = 0; ///< initial drain pump DAC value. +static U32 drainPumpDACSet = 0; ///< currently set drain pump DAC value. +static PUMP_CONTROL_MODE_T drainPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; ///< requested drain pump control mode. +static PUMP_CONTROL_MODE_T drainPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< currently set drain pump control mode. 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 -static U32 targetDrainPumpRPM = 0; ///< Target drain pump RPM -static F32 targetDrainPumpOutletPressure = 0.0; ///< Target outlet pressure for the drain pump + 0, 0 }; ///< interval (in ms) at which to publish RO flow data to CAN bus. +static U32 targetDrainPumpRPM = 0; ///< Target drain pump RPM. +static F32 targetDrainPumpOutletPressure = 0.0; ///< Target outlet pressure for the drain pump. -static U32 drainControlTimerCounter = 0; ///< Determines when to perform control on drain pump -static BOOL hasClosedLoopBeenRequested = FALSE; ///< Closed loop pump control flag -static U32 currentDrainPumpRPM = 0; ///< Current drain pump RPM from feedback +static U32 drainControlTimerCounter = 0; ///< Determines when to perform control on drain pump. +static BOOL hasClosedLoopBeenRequested = FALSE; ///< Closed loop pump control flag. +static U32 currentDrainPumpRPM = 0; ///< Current drain pump RPM from feedback. +static U32 safetyShutdownTimeoutCounter = 0; ///< Timeout counter to activate safety shutdown. /* TODO These variables are used for POST. POST will be implemented later -static DRAIN_PUMP_SELF_TEST_STATE_T drainPumpSelfTestState = DRAIN_PUMP_SELF_TEST_STATE_START; ///< current drain pump self test state -static U32 drainPumpSelfTestTimerCount = 0; ///< timer counter for drain pump self test +static DRAIN_PUMP_SELF_TEST_STATE_T drainPumpSelfTestState = DRAIN_PUMP_SELF_TEST_STATE_START; ///< current drain pump self test state. +static U32 drainPumpSelfTestTimerCount = 0; ///< timer counter for drain pump self test. */ -/// ADC to RPM conversion coefficient or RPM to ADC conversion +/// ADC to RPM conversion coefficient or RPM to ADC conversion. static const F32 CONVERSION_COEFF = SEC_PER_MIN / ( TOGGLE_PERIOD_RESOLUTION_SECONDS * ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION ); // ********** private function prototypes ********** @@ -127,14 +131,15 @@ * @brief * The initDrainPump function initializes the DrainPump module. * @details Inputs: none - * @details Outputs: hasClosedLoopBeenRequested + * @details Outputs: hasClosedLoopBeenRequested, safetyShutdownTimeoutCounter * @return none *************************************************************************/ void initDrainPump( void ) { stopDrainPump(); - hasClosedLoopBeenRequested = FALSE; + hasClosedLoopBeenRequested = FALSE; + safetyShutdownTimeoutCounter = 0; // Initialize the drain pump PI controller initializePIController( PI_CONTROLLER_ID_DRAIN_PUMP, DRAIN_PUMP_MIN_DAC, @@ -238,8 +243,8 @@ * The execDrainPumpMonitor function executes the drain pump monitor. * RPM = ( 1 / ADC ) * conversion coefficient. * ADC = ( 1 / RPM ) * conversion coefficient. - * @details Inputs: currentDrainPumpRPM - * @details Outputs: currentDrainPumpRPM + * @details Inputs: currentDrainPumpRPM, safetyShutdownTimeoutCounter + * @details Outputs: currentDrainPumpRPM, safetyShutdownTimeoutCounter * @return none *************************************************************************/ void execDrainPumpMonitor( void ) @@ -260,6 +265,17 @@ checkPersistentAlarm( PERSISTENT_ALARM_DRAIN_PUMP_RPM_OUT_OF_RANGE, isRPMOutOfRange, currentDrainPumpRPM, threshold ); } + // Check if the pump is in off state and the RPM is greater than the minimum RPM + if ( drainPumpState == DRAIN_PUMP_OFF_STATE && currentDrainPumpRPM > MIN_DRAIN_PUMP_RPM ) + { + // Check if the RPM is not 0 for more that the specified time and if it is, activate the safety shutdown + if ( ++safetyShutdownTimeoutCounter > SAFETY_SHUTDOWN_TIMEOUT_COUNT ) + { + activateSafetyShutdown(); + safetyShutdownTimeoutCounter = 0; + } + } + // Publish drain pump data on interval publishDrainPumpData(); }