Index: firmware/App/Controllers/BoostPump.c =================================================================== diff -u -r8d272582cbd2cb5fc0c6af0fead2867ce02658b0 -r1cf11f4c1f6a1f1fd40270889723fbec040fc7ec --- firmware/App/Controllers/BoostPump.c (.../BoostPump.c) (revision 8d272582cbd2cb5fc0c6af0fead2867ce02658b0) +++ firmware/App/Controllers/BoostPump.c (.../BoostPump.c) (revision 1cf11f4c1f6a1f1fd40270889723fbec040fc7ec) @@ -78,7 +78,7 @@ static OVERRIDE_U32_T targetBoostPumpFlowRate; ///< Target Boost flow rate (in L/min). static OVERRIDE_F32_T targetBoostPumpPressure; ///< Target Boost max allowed pressure (in PSI). static F32 boostPumpDutyCyclePctSet; ///< Currently set Boost pump PWM duty cycle. -static F32 boostPumpOpenLoopTargetDutyCycle; ///< Target Boost pump open loop PWM. +static OVERRIDE_F32_T boostPumpOpenLoopTargetDutyCycle; ///< Target Boost pump open loop PWM. // ********** private function prototypes ********** @@ -97,7 +97,7 @@ * The initBoostPump function initializes the Boost Pump module. * @details \b Inputs: boostPumpState, boostPumpControlMode, isBoostPumpOn, stopPumpRequest, * boostControlTimerCounter, boostPumpDutyCyclePctSet, boostPumpOpenLoopTargetDutyCycle, boostPumpDataPublicationTimerCounter, - * boostPumpDataPublishInterval, targetBoostPumpFlowRCLOSEDate, targetBoostPumpPressure + * boostPumpDataPublishInterval, targetBoostPumpFlowRate, targetBoostPumpPressure * @details \b Outputs: Boost Pump controller unit initialized * @return none *************************************************************************/ @@ -113,26 +113,29 @@ initializePIController( PI_CONTROLLER_ID_BOOST_PUMP_PRES, MIN_FLUID_PUMP_DUTY_CYCLE_PCT, BOOST_PRESSURE_CONTROL_P_COEFFICIENT, BOOST_PRESSURE_CONTROL_I_COEFFICIENT, MIN_FLUID_PUMP_DUTY_CYCLE_PCT, MAX_FLUID_PUMP_DUTY_CYCLE_PCT, FALSE, 0 ); - boostPumpState = BOOST_PUMP_OFF_STATE; - boostPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; - isBoostPumpOn = FALSE; - stopPumpRequest = FALSE; - boostControlTimerCounter = 0; - boostPumpDutyCyclePctSet = 0.0F; - boostPumpOpenLoopTargetDutyCycle = 0.0F; - boostPumpDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; - boostPumpDataPublishInterval.data = BOOST_DATA_PUB_INTERVAL; - boostPumpDataPublishInterval.ovData = BOOST_CONTROL_INTERVAL; - boostPumpDataPublishInterval.ovInitData = 0; - boostPumpDataPublishInterval.override = OVERRIDE_RESET; - targetBoostPumpFlowRate.data = 0; - targetBoostPumpFlowRate.ovData = 0; - targetBoostPumpFlowRate.ovInitData = 0; - targetBoostPumpFlowRate.override = OVERRIDE_RESET; - targetBoostPumpPressure.data = 0.0F; - targetBoostPumpPressure.ovData = 0.0F; - targetBoostPumpPressure.ovInitData = 0.0F; - targetBoostPumpPressure.override = OVERRIDE_RESET; + boostPumpState = BOOST_PUMP_OFF_STATE; + boostPumpControlMode = NUM_OF_PUMP_CONTROL_MODES; + isBoostPumpOn = FALSE; + stopPumpRequest = FALSE; + boostControlTimerCounter = 0; + boostPumpDutyCyclePctSet = 0.0F; + boostPumpDataPublicationTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; + boostPumpDataPublishInterval.data = BOOST_DATA_PUB_INTERVAL; + boostPumpDataPublishInterval.ovData = BOOST_CONTROL_INTERVAL; + boostPumpDataPublishInterval.ovInitData = 0; + boostPumpDataPublishInterval.override = OVERRIDE_RESET; + targetBoostPumpFlowRate.data = 0; + targetBoostPumpFlowRate.ovData = 0; + targetBoostPumpFlowRate.ovInitData = 0; + targetBoostPumpFlowRate.override = OVERRIDE_RESET; + targetBoostPumpPressure.data = 0.0F; + targetBoostPumpPressure.ovData = 0.0F; + targetBoostPumpPressure.ovInitData = 0.0F; + targetBoostPumpPressure.override = OVERRIDE_RESET; + boostPumpOpenLoopTargetDutyCycle.data = 0.0F; + boostPumpOpenLoopTargetDutyCycle.ovData = 0.0F; + boostPumpOpenLoopTargetDutyCycle.ovInitData = 0.0F; + boostPumpOpenLoopTargetDutyCycle.override = OVERRIDE_RESET; stopBoostPump(); } @@ -215,10 +218,10 @@ } // If the target duty cycle is greater than zero (minimum is 10%) and the mode has been set to open // loop, set the duty cycle - else if ( ( boostPumpOpenLoopTargetDutyCycle > 0.0F ) && ( PUMP_CONTROL_MODE_OPEN_LOOP == boostPumpControlMode ) ) + else if ( ( getTargetBoostPumpDutyCyclePCT() > 0.0F ) && ( PUMP_CONTROL_MODE_OPEN_LOOP == boostPumpControlMode ) ) { - setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpOpenLoopTargetDutyCycle ); - boostPumpDutyCyclePctSet = boostPumpOpenLoopTargetDutyCycle; + setFluidPumpPctToPWMDutyCycle( P40_PUMP, getTargetBoostPumpDutyCyclePCT() ); + boostPumpDutyCyclePctSet = getTargetBoostPumpDutyCyclePCT(); isBoostPumpOn = TRUE; state = BOOST_PUMP_OPEN_LOOP_STATE; } @@ -282,13 +285,18 @@ resetPIController( PI_CONTROLLER_ID_BOOST_PUMP_PRES, boostPumpDutyCyclePctSet, 0 ); state = BOOST_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE; } - else if ( boostPumpOpenLoopTargetDutyCycle > 0.0F && ( PUMP_CONTROL_MODE_OPEN_LOOP == boostPumpControlMode ) ) + else if ( getTargetBoostPumpDutyCyclePCT() > 0.0F && ( PUMP_CONTROL_MODE_OPEN_LOOP == boostPumpControlMode ) ) { - setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpOpenLoopTargetDutyCycle ); - boostPumpDutyCyclePctSet = boostPumpOpenLoopTargetDutyCycle; + setFluidPumpPctToPWMDutyCycle( P40_PUMP, getTargetBoostPumpDutyCyclePCT() ); + boostPumpDutyCyclePctSet = getTargetBoostPumpDutyCyclePCT(); state = BOOST_PUMP_OPEN_LOOP_STATE; } - // Control at set interval + + // Control at set interval or shut off + if ( getTargetBoostPumpFlowRateMLPM() == 0.0F && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) + { + signalBoostPumpHardStop(); + } else if ( ( ++boostControlTimerCounter >= BOOST_CONTROL_INTERVAL ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) { boostPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_BOOST_PUMP_FLOW, getTargetBoostPumpFlowRateMLPM(), getFilteredFlow( P7_FLOW ) ); @@ -311,19 +319,25 @@ { BOOST_PUMP_STATE_T state = BOOST_PUMP_CONTROL_TO_TARGET_PRESSURE_STATE; + // Check if need to switch control modes if ( ( getTargetBoostPumpFlowRateMLPM() > 0.0F ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) { ///transition to target flow resetPIController( PI_CONTROLLER_ID_BOOST_PUMP_FLOW, boostPumpDutyCyclePctSet, 0.0F ); state = BOOST_PUMP_CONTROL_TO_TARGET_FLOW_STATE; } - else if ( boostPumpOpenLoopTargetDutyCycle > 0.0F && ( PUMP_CONTROL_MODE_OPEN_LOOP == boostPumpControlMode ) ) + else if ( getTargetBoostPumpDutyCyclePCT() > 0.0F && ( PUMP_CONTROL_MODE_OPEN_LOOP == boostPumpControlMode ) ) { - setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpOpenLoopTargetDutyCycle ); - boostPumpDutyCyclePctSet = boostPumpOpenLoopTargetDutyCycle; + setFluidPumpPctToPWMDutyCycle( P40_PUMP, getTargetBoostPumpDutyCyclePCT() ); + boostPumpDutyCyclePctSet = getTargetBoostPumpDutyCyclePCT(); state = BOOST_PUMP_OPEN_LOOP_STATE; } - // Control at set interval + + // Control at set interval or shut off + if ( getTargetBoostPumpPressure() == 0.0F && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) + { + signalBoostPumpHardStop(); + } else if ( ( ++boostControlTimerCounter >= BOOST_CONTROL_INTERVAL ) && ( PUMP_CONTROL_MODE_CLOSED_LOOP == boostPumpControlMode ) ) { boostPumpDutyCyclePctSet = runPIController( PI_CONTROLLER_ID_BOOST_PUMP_PRES, getTargetBoostPumpPressure(), getFilteredPressure( M3_PRES ) ); @@ -363,9 +377,9 @@ { targetBoostPumpPressure.data = 0.0F; } - if ( boostPumpOpenLoopTargetDutyCycle > 0.0F ) + if ( getTargetBoostPumpDutyCyclePCT() > 0.0F ) { - boostPumpOpenLoopTargetDutyCycle = 0.0F; + boostPumpOpenLoopTargetDutyCycle.data = 0.0F; } result = TRUE; } @@ -406,9 +420,9 @@ { targetBoostPumpFlowRate.data = 0.0F; } - if ( boostPumpOpenLoopTargetDutyCycle > 0.0F ) + if ( getTargetBoostPumpDutyCyclePCT() > 0.0F ) { - boostPumpOpenLoopTargetDutyCycle = 0.0F; + boostPumpOpenLoopTargetDutyCycle.data = 0.0F; } result = TRUE; } @@ -438,12 +452,12 @@ if ( ( dutyCycle >= MIN_FLUID_PUMP_DUTY_CYCLE_PCT ) && ( dutyCycle <= MAX_FLUID_PUMP_DUTY_CYCLE_PCT ) ) { - boostPumpOpenLoopTargetDutyCycle = dutyCycle; - boostPumpControlMode = PUMP_CONTROL_MODE_OPEN_LOOP; - status = TRUE; + boostPumpOpenLoopTargetDutyCycle.data = dutyCycle; + boostPumpControlMode = PUMP_CONTROL_MODE_OPEN_LOOP; + status = TRUE; // Set the new duty cycle of the pump - setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpOpenLoopTargetDutyCycle ); + setFluidPumpPctToPWMDutyCycle( P40_PUMP, boostPumpOpenLoopTargetDutyCycle.data ); // Clear previous target data if ( getTargetBoostPumpFlowRateMLPM() > 0 ) { @@ -473,7 +487,9 @@ *************************************************************************/ F32 getTargetBoostPumpDutyCyclePCT( void ) { - return boostPumpOpenLoopTargetDutyCycle; + F32 dutyCycle = getF32OverrideValue( &boostPumpOpenLoopTargetDutyCycle ); + + return dutyCycle; } /*********************************************************************//** @@ -486,7 +502,7 @@ *************************************************************************/ F32 getCurrentBoostPumpDutyCyclePCT( void ) { - U16 dutyCyclePct = convertDutyCycleCntToPct( getFluidPumpReadPWMDutyCycle( P40_PUMP ) ); + F32 dutyCyclePct = convertDutyCycleCntToPct( getFluidPumpReadPWMDutyCycle( P40_PUMP ) ); return dutyCyclePct; } @@ -579,7 +595,7 @@ boostPumpState = BOOST_PUMP_OFF_STATE; boostPumpDutyCyclePctSet = 0.0F; boostControlTimerCounter = 0; - boostPumpOpenLoopTargetDutyCycle = 0.0F; + boostPumpOpenLoopTargetDutyCycle.data = 0.0F; stopBoostPump(); } @@ -632,7 +648,7 @@ pumpData.p40PumpSpeed = getFluidPumpRPM( P40_PUMP ); pumpData.p40TargetPressure = getTargetBoostPumpPressure(); pumpData.p40TargetFlow = getTargetBoostPumpFlowRateMLPM(); - pumpData.p40TargetDutyCycle = boostPumpOpenLoopTargetDutyCycle; + pumpData.p40TargetDutyCycle = getTargetBoostPumpDutyCyclePCT(); broadcastData( MSG_ID_FP_BOOST_PUMP_DATA, COMM_BUFFER_OUT_CAN_FP_BROADCAST, (U08*)&pumpData, sizeof( BOOST_PUMP_DATA_T ) ); boostPumpDataPublicationTimerCounter = 0; @@ -676,6 +692,8 @@ { BOOL result = f32Override( message, &targetBoostPumpPressure ); + setBoostPumpTargetPressure(getTargetBoostPumpPressure()); + return result; } @@ -693,7 +711,28 @@ { BOOL result = u32Override( message, &targetBoostPumpFlowRate, MIN_BOOST_FLOWRATE_MLPM, MAX_BOOST_FLOWRATE_MLPM ); + setBoostPumpTargetFlowRateMLPM(getTargetBoostPumpFlowRateMLPM()); + return result; } +/*********************************************************************//** + * @brief + * The testBoostPumpTargetDutyCycleOverride function overrides the RO pump + * duty cycle. + * @details \b Inputs: boostPumpOpenLoopTargetDutyCycle + * @details \b Outputs: boostPumpOpenLoopTargetDutyCycle + * @param message Override message from Dialin which includes the value + * of the target flow + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testBoostPumpTargetDutyCycleOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &boostPumpOpenLoopTargetDutyCycle ); + + setBoostPumpTargetDutyCycle(getTargetBoostPumpDutyCyclePCT()); + + return result; +} + /**@}*/