Index: firmware/App/Controllers/DrainPump.c =================================================================== diff -u -r1a5efe97f5f39594b45797fded52cafce92afe80 -ra2c32d4d221603054ca9ad7a097112caebf08c4e --- firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 1a5efe97f5f39594b45797fded52cafce92afe80) +++ firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision a2c32d4d221603054ca9ad7a097112caebf08c4e) @@ -43,12 +43,8 @@ // ********** private definitions ********** -#define DRAIN_PUMP_MIN_DAC ( ( (F32)MIN_DRAIN_PUMP_RPM * \ - DRP_SPEED_RPM_TO_ADC_FACTOR ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ///< Drain pump minimum RPM to DAC conversion. -#define DRAIN_PUMP_MAX_DAC ( ( (F32)MAX_DRAIN_PUMP_RPM * \ - DRP_SPEED_RPM_TO_ADC_FACTOR ) + FLOAT_TO_INT_ROUNDUP_OFFSET ) ///< Drain pump maximum RPM to DAC conversion. -#define DRP_SPEED_ADC_TO_RPM_CONVERSION 12.94 // TODO remove ///< Conversion factor from ADC counts to RPM for Drain pump. -#define DRP_SPEED_RPM_TO_ADC_FACTOR ( 1.0 / DRP_SPEED_ADC_TO_RPM_CONVERSION ) // TODO remove ///< Conversion factor from RPM to ADC counts for Drain pump. +#define DRAIN_PUMP_MIN_DAC GET_RPM_2_DAC_CONVERSION( MIN_DRAIN_PUMP_RPM ) ///< Drain pump minimum RPM to DAC conversion. +#define DRAIN_PUMP_MAX_DAC GET_RPM_2_DAC_CONVERSION( MAX_DRAIN_PUMP_RPM ) ///< Drain pump maximum RPM to DAC conversion. #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. @@ -65,10 +61,10 @@ #define DRAIN_PUMP_P_COEFFICIENT 0.5 ///< P term for drain pump delta pressure control. #define DRAIN_PUMP_I_COEFFICIENT 1.0 ///< I term for drain pump delta pressure control. -#define MIN_ALLOWED_TARGET_OUTLET_PRESSURE -10.0 ///< Minimum allowed outlet pressure for closed loop control. -#define MAX_ALLOWED_TARGET_OUTLET_PRESSURE 10.0 ///< Maximum allowed outlet pressure for closed loop control. +#define MIN_ALLOWED_TARGET_OUTLET_PRESSURE -15.0 ///< Minimum allowed outlet pressure for closed loop control. +#define MAX_ALLOWED_TARGET_OUTLET_PRESSURE 15.0 ///< Maximum allowed outlet pressure for closed loop control. -#define OPEN_LOOP_RPM_OUT_OF_RANGE 0.1 ///< Maximum allowed RPM out of range from target RPM in open loop percent. +#define MAX_ALLOWED_OPEN_LOOP_RPM_OUT_OF_RANGE 100 ///< Maximum allowed RPM out of range from target RPM in open loop. #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. @@ -120,11 +116,6 @@ 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). -/* 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. -*/ - /// 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 ); @@ -179,10 +170,7 @@ if ( ( 0 == rpm ) || ( ( rpm >= MIN_DRAIN_PUMP_RPM ) && ( rpm <= MAX_DRAIN_PUMP_RPM ) ) ) { - //drainPumpDAC = (U32)((F32)rpm * DRP_SPEED_RPM_TO_ADC_FACTOR + FLOAT_TO_INT_ROUNDUP_OFFSET); //TODO remove. Yes, it is temporary don't laugh - - drainPumpDAC = (U32)GET_RPM_2_DAC_CONVERSION(rpm); - + drainPumpDAC = (U32)GET_RPM_2_DAC_CONVERSION(rpm); targetDrainPumpRPM = rpm; drainPumpControlMode = PUMP_CONTROL_MODE_OPEN_LOOP; drainPumpControlModeSet = drainPumpControlMode; @@ -336,27 +324,22 @@ currentDrainPumpRPM = CONVERSION_COEFF / getFPGADrainPumpSpeed(); } - /* TODO: The RPM is not converted properly. There will be a story to work on this issue. - * This part of code is commented out until the RPM is calculated from ADC correctly. - * There will be a story to address the RPM conversion. - */ #ifndef IGNORE_DRAIN_PUMP_MONITOR // 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( drainPumpControlModeSet == PUMP_CONTROL_MODE_OPEN_LOOP ) + if( PUMP_CONTROL_MODE_OPEN_LOOP == drainPumpControlModeSet ) { U32 targetRPM = getTargetDrainPumpRPM(); - F32 threshold = OPEN_LOOP_RPM_OUT_OF_RANGE * targetRPM; // 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 ) > threshold; + BOOL isRPMOutOfRange = fabs( targetRPM - currentDrainPumpRPM ) > MAX_ALLOWED_OPEN_LOOP_RPM_OUT_OF_RANGE; - checkPersistentAlarm( ALARM_ID_DRAIN_PUMP_RPM_OUT_OF_RANGE, isRPMOutOfRange, currentDrainPumpRPM, threshold ); + checkPersistentAlarm( ALARM_ID_DRAIN_PUMP_RPM_OUT_OF_RANGE, isRPMOutOfRange, currentDrainPumpRPM, MAX_ALLOWED_OPEN_LOOP_RPM_OUT_OF_RANGE ); } // Check if the pump is in off state and the RPM is greater than the minimum RPM - if ( drainPumpState == DRAIN_PUMP_OFF_STATE ) + if ( DRAIN_PUMP_OFF_STATE == drainPumpState ) { BOOL isRPMTooHigh = currentDrainPumpRPM > MIN_DRAIN_PUMP_RPM; @@ -366,7 +349,6 @@ if ( isAlarmActive( ALARM_ID_DRAIN_PUMP_OFF_FAULT ) ) { activateSafetyShutdown(); - BOOL test = FALSE; } } #endif @@ -400,7 +382,7 @@ } else if ( DRAIN_PUMP_OPEN_LOOP_STATE == pendingDrainPumpCmd ) { - drainPumpDAC = (U32)(pendingDrainPumpCmdTarget * DRP_SPEED_RPM_TO_ADC_FACTOR + FLOAT_TO_INT_ROUNDUP_OFFSET); + drainPumpDAC = (U32)( pendingDrainPumpCmdTarget * RPM_2_DAC_SLOPE - RPM_2_DAC_INTERCEPT + FLOAT_TO_INT_ROUNDUP_OFFSET ); targetDrainPumpRPM = (U32)pendingDrainPumpCmdTarget; drainPumpControlMode = PUMP_CONTROL_MODE_OPEN_LOOP; drainPumpControlModeSet = drainPumpControlMode; @@ -435,23 +417,6 @@ /*********************************************************************//** * @brief - * The execDrainPumpSelfTest function executes the state machine for the drain - * pump self-test. - * @details Inputs: TODO FILL UP - * @details Outputs: TODO FILL UP - * @return the current state of the Drain Pump self test. - *************************************************************************/ -SELF_TEST_STATUS_T execDrainPumpSelfTest( void ) -{ - SELF_TEST_STATUS_T result = SELF_TEST_STATUS_FAILED; - - // TODO - implement self-test(s) - - return result; -} - -/*********************************************************************//** - * @brief * The getTargetDrainPumpRPM function gets the current target drain pump * RPM. * @details Inputs: targetDrainPumpRPM @@ -503,7 +468,7 @@ // If the target drain pump speed was not 0 and the control mode // is open loop, set the drain pump to open loop - if ( ( getTargetDrainPumpRPM() > 0 ) && ( drainPumpControlModeSet == PUMP_CONTROL_MODE_OPEN_LOOP ) ) + if ( ( getTargetDrainPumpRPM() > 0 ) && ( PUMP_CONTROL_MODE_OPEN_LOOP == drainPumpControlModeSet ) ) { // Set drain pump enable pin SET_DRAIN_PUMP_ENABLE(); @@ -516,7 +481,7 @@ } // If the drain pump is set to closed loop, call the proper state // It is checked for the value of delta pressure because it can be anything including 0 - else if ( ( drainPumpControlModeSet == PUMP_CONTROL_MODE_CLOSED_LOOP ) && ( hasClosedLoopBeenRequested ) ) + else if ( ( PUMP_CONTROL_MODE_CLOSED_LOOP == drainPumpControlModeSet ) && ( TRUE == hasClosedLoopBeenRequested ) ) { // set drain pump enable pin SET_DRAIN_PUMP_ENABLE();