Index: firmware/App/Controllers/DrainPump.c =================================================================== diff -u -r00a3d52090bee79dac6e9eed3bd79342fcbca83f -r35246359c5a9080c704e0a6f1563e99a337e2e91 --- firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 00a3d52090bee79dac6e9eed3bd79342fcbca83f) +++ firmware/App/Controllers/DrainPump.c (.../DrainPump.c) (revision 35246359c5a9080c704e0a6f1563e99a337e2e91) @@ -63,7 +63,7 @@ #define MAX_ALLOWED_TARGET_DELTA_PRESSURE 10.0 ///< Maximum allowed delta pressure for closed loop control. #define MAX_ALLOWED_OPEN_LOOP_RPM_OUT_OF_RANGE 20 ///< Maximum allowed RPM out of range from target RPM in open loop. -#define OPEN_LOOP_RPM_OUT_OF_RANGE_TIME_OUT ( 5000 / TASK_PRIORITY_INTERVAL ) ///< Open loop RPM out of range time out in counts. +#define OPEN_LOOP_RPM_OUT_OF_RANGE_TIME_OUT 5000 ///< Open loop RPM out of range time out in ms. /// Enumeration of drain pump states. typedef enum DrainPump_States @@ -110,18 +110,13 @@ static BOOL hasClosedLoopBeenRequested = FALSE; ///< Closed loop pump control flag static U32 currentDrainPumpRPM = 0; ///< Current drain pump RPM from feedback -/* These variables are used for POST. POST will be implemented later +/* 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 */ -/* - * Conversion of ADC count from micro seconds resolution to seconds and also converting toggle to pulse period. - * RPM = ( 1 / ADC ) * conversion coefficient. - * ADC = ( 1 / RPM ) * conversion coefficient. - */ /// ADC to RPM conversion coefficient or RPM to ADC conversion -static const F32 conversionCoeff = SEC_PER_MIN / ( TOGGLE_PERIOD_RESOLUTION_SECONDS * ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION ); +static const F32 CONVERSION_COEFF = SEC_PER_MIN / ( TOGGLE_PERIOD_RESOLUTION_SECONDS * ROTATIONAL_TO_TOGGLE_PERIOD_CONVERSION ); // ********** private function prototypes ********** @@ -248,14 +243,16 @@ /*********************************************************************//** * @brief * The execDrainPumpMonitor function executes the drain pump monitor. + * RPM = ( 1 / ADC ) * conversion coefficient. + * ADC = ( 1 / RPM ) * conversion coefficient. * @details Inputs: currentDrainPumpRPM * @details Outputs: currentDrainPumpRPM * @return none *************************************************************************/ void execDrainPumpMonitor( void ) { // Convert speed ADC to RPM - currentDrainPumpRPM = conversionCoeff / getFPGADrainPumpSpeed(); + currentDrainPumpRPM = CONVERSION_COEFF / getFPGADrainPumpSpeed(); // 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 @@ -265,7 +262,8 @@ // Check if RPM out of range. Using fabs since the read RPM can be above or below the target. BOOL isRPMOutOfRange = fabs( getTargetDrainPumpRPM() - currentDrainPumpRPM ) > MAX_ALLOWED_OPEN_LOOP_RPM_OUT_OF_RANGE; - checkPersistentAlarm( PERSISTENT_ALARM_DRAIN_PUMP_RPM_OUT_OF_RANGE, isRPMOutOfRange, currentDrainPumpRPM ); + // TODO fill the limit argument with the right value + checkPersistentAlarm( PERSISTENT_ALARM_DRAIN_PUMP_RPM_OUT_OF_RANGE, isRPMOutOfRange, currentDrainPumpRPM, 0 ); } // Publish drain pump data on interval @@ -305,13 +303,13 @@ /*********************************************************************//** * @brief - * The execDrainPumpTest function executes the state machine for the drain + * The execDrainPumpSelfTest function executes the state machine for the drain * pump self-test. * @detailsInputs: TODO FILL UP * @details Outputs: TODO FILL UP * @return: the current state of the Drain Pump self test. *************************************************************************/ -SELF_TEST_STATUS_T execDrainPumpTest( void ) +SELF_TEST_STATUS_T execDrainPumpSelfTest( void ) { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_FAILED; @@ -359,23 +357,6 @@ { DRAIN_PUMP_STATE_T result = DRAIN_PUMP_OFF_STATE; -#ifdef DEBUG_ENABLED -#ifdef ENABLE_DIP_SWITCHES - // TODO - test code - remove later - if ( GET_DIP_SW2_TEST() ) - { - setValveState( VPI, VALVE_STATE_OPEN ); - setValveState( VRC, VALVE_STATE_DRAIN_C_TO_NO ); - setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); - setDrainPumpTargetRPM( 1000 ); -#ifdef EMC_TEST_BUILD - setTrimmerHeaterTargetTemperature( 50.0 ); - startTrimmerHeater(); -#endif - } -#endif -#endif - // 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 ) @@ -427,30 +408,14 @@ F32 outletDrainPressure = getMeasuredDGPressure ( PRESSURE_SENSOR_DRAIN_PUMP_OUTLET ); F32 pressureDiff = outletDrainPressure - inletDrainPressure; F32 dac = runPIController( PI_CONTROLLER_ID_DRAIN_PUMP, getTargetDrainPumpDeltaP(), pressureDiff ); + // The PI controller sends the DAC out and it is rounded to the nearest offset and is fed to the FPGA drainPumpDACSet = (U32)( dac + FLOAT_TO_INT_ROUNDUP_OFFSET ); setFPGADrainPumpSpeed( drainPumpDACSet ); drainControlTimerCounter = 0; } -#ifdef DEBUG_ENABLED -#ifdef ENABLE_DIP_SWITCHES - // TODO - test code - remove later - if ( !GET_DIP_SW2_TEST() ) - { - signalDrainPumpHardStop(); - setValveState( VPI, VALVE_STATE_OPEN ); - setValveState( VRC, VALVE_STATE_DRAIN_C_TO_NO ); - setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); -#ifdef EMC_TEST_BUILD - stopTrimmerHeater(); -#endif - result = DRAIN_PUMP_OFF_STATE; - } -#endif -#endif - return result; }