Index: firmware/App/Controllers/ROPump.c =================================================================== diff -u -r2169bb140369dd394aadedcf1cc0d5ea4832e286 -r91982bb1378f3a4a614313a1c0d9dbf83b81014b --- firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 2169bb140369dd394aadedcf1cc0d5ea4832e286) +++ firmware/App/Controllers/ROPump.c (.../ROPump.c) (revision 91982bb1378f3a4a614313a1c0d9dbf83b81014b) @@ -70,10 +70,15 @@ static F32 roPumpDutyCyclePctSet; ///< Currently set RO pump PWM duty cycle. static OVERRIDE_F32_T roPumpOpenLoopTargetDutyCycle; ///< Target RO pump open loop PWM. -static U32 backupROPumpFlowRate = 0; -static F32 backupROPumpPressure = 0.0F; -static F32 backupROPumpDutyCyclePctSet = 0.0F; -static BOOL backupSet = FALSE; +//typedef enum +//{ +// OVERRIDE_NONE_ACTIVE = 0, +// OVERRIDE_FLOW, +// OVERRIDE_PRESSURE, +// OVERRIDE_DUTYCYCLE +//} OVERRIDE_TYPE_E; +// +//static OVERRIDE_TYPE_E lastOverrideType = OVERRIDE_NONE_ACTIVE; // ********** private function prototypes ********** @@ -277,7 +282,7 @@ signalROPumpHardStop(); } // Check if need to switch control modes - else if ( getTargetROPumpPressure() > 0.0F ) // isTargetPressureActive() == TRUE inside isTargetPressure -> T/F based on data and ov data. + else if ( getTargetROPumpPressure() > 0.0F ) // isTargetPressureActive() == TRUE inside isTargetPressure -> T/F based on data and ov data. { // Transition to target pressure resetPIController( PI_CONTROLLER_ID_RO_PUMP_PRES, roPumpDutyCyclePctSet, 0 ); @@ -369,21 +374,35 @@ { if ( targetROPumpFlowRate.override != OVERRIDE_RESET ) { - if (!backupSet) + if ( targetROPumpFlowRate.ovInitData == 0 ) { - backupROPumpFlowRate = targetROPumpFlowRate.data; - backupROPumpPressure = targetROPumpPressure.data; - backupROPumpDutyCyclePctSet = roPumpOpenLoopTargetDutyCycle.data; - backupSet = TRUE; + targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; } - // Clear previous target data - if ( getTargetROPumpPressure() > 0.0F ) + + if ( targetROPumpPressure.data > 0.0 ) { - targetROPumpPressure.data = 0.0F; + if ( targetROPumpPressure.override != OVERRIDE_RESET ) + { + targetROPumpPressure.data = 0.0; + } + else + { + targetROPumpPressure.ovInitData = targetROPumpPressure.data; + targetROPumpPressure.data = 0.0; + } } - if ( getTargetROPumpDutyCyclePCT() > 0.0F ) + if ( roPumpOpenLoopTargetDutyCycle.data > 0.0 ) { - roPumpOpenLoopTargetDutyCycle.data = 0.0F; + if ( roPumpOpenLoopTargetDutyCycle.override != OVERRIDE_RESET ) + { +// roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; + roPumpOpenLoopTargetDutyCycle.data = 0.0; + } + else + { + roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; + roPumpOpenLoopTargetDutyCycle.data = 0.0; + } } } targetROPumpFlowRate.data = roFlowRate; @@ -421,21 +440,33 @@ { if ( targetROPumpPressure.override != OVERRIDE_RESET ) { - if (!backupSet) + if ( targetROPumpPressure.ovInitData == 0 ) { - backupROPumpFlowRate = targetROPumpFlowRate.data; - backupROPumpPressure = targetROPumpPressure.data; - backupROPumpDutyCyclePctSet = roPumpOpenLoopTargetDutyCycle.data; - backupSet = TRUE; + targetROPumpPressure.ovInitData = targetROPumpPressure.data; } - // Clear previous target data - if ( getTargetROPumpFlowRateMLPM() > 0 ) + if ( targetROPumpFlowRate.data > 0 ) { - targetROPumpFlowRate.data = 0; + if ( targetROPumpFlowRate.override != OVERRIDE_RESET ) + { + targetROPumpFlowRate.data = 0; + } + else + { + targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; + targetROPumpFlowRate.data = 0; + } } - if ( getTargetROPumpDutyCyclePCT() > 0.0F ) + if ( roPumpOpenLoopTargetDutyCycle.data > 0.0 ) { - roPumpOpenLoopTargetDutyCycle.data = 0.0F; + if ( roPumpOpenLoopTargetDutyCycle.override != OVERRIDE_RESET ) + { + roPumpOpenLoopTargetDutyCycle.data = 0.0; + } + else + { + roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; + roPumpOpenLoopTargetDutyCycle.data = 0.0; + } } } targetROPumpPressure.data = roPressure; @@ -447,8 +478,11 @@ } else if ( roPressure == 0.0F ) { - stopPumpRequest = TRUE; result = TRUE; + if ( ( getTargetROPumpFlowRateMLPM() == 0 ) && ( getTargetROPumpDutyCyclePCT() == 0.0 ) ) + { + stopPumpRequest = TRUE; + } } // Requested flow rate is out of range @@ -477,26 +511,36 @@ if ( ( dutyCycle >= MIN_FLUID_PUMP_DUTY_CYCLE_PCT ) && ( dutyCycle <= MAX_FLUID_PUMP_DUTY_CYCLE_PCT ) ) { - if ( roPumpOpenLoopTargetDutyCycle.override != OVERRIDE_RESET ) { - if (!backupSet) + if ( roPumpOpenLoopTargetDutyCycle.ovInitData == 0 ) { - backupROPumpFlowRate = targetROPumpFlowRate.data; - backupROPumpPressure = targetROPumpPressure.data; - backupROPumpDutyCyclePctSet = roPumpOpenLoopTargetDutyCycle.data; - backupSet = TRUE; + roPumpOpenLoopTargetDutyCycle.ovInitData = roPumpOpenLoopTargetDutyCycle.data; } - // Clear previous target data - if ( getTargetROPumpFlowRateMLPM() > 0 ) + if ( targetROPumpFlowRate.data > 0 ) { - targetROPumpFlowRate.data = 0; + if ( targetROPumpFlowRate.override != OVERRIDE_RESET ) + { + targetROPumpFlowRate.data = 0; + } + else + { + targetROPumpFlowRate.ovInitData = targetROPumpFlowRate.data; + targetROPumpFlowRate.data = 0; + } } - if ( getTargetROPumpPressure() > 0.0F ) + if ( targetROPumpPressure.data > 0.0 ) { - targetROPumpPressure.data = 0.0F; + if ( targetROPumpPressure.override != OVERRIDE_RESET ) + { + targetROPumpPressure.data = 0.0; + } + else + { + targetROPumpPressure.ovInitData = targetROPumpPressure.data; + targetROPumpPressure.data = 0.0; + } } - } // Set the new duty cycle of the pump roPumpOpenLoopTargetDutyCycle.data = dutyCycle; @@ -506,8 +550,11 @@ } else if ( dutyCycle == 0.0F ) { - stopPumpRequest = TRUE; result = TRUE; + if ( getTargetROPumpFlowRateMLPM() == 0 && getTargetROPumpPressure() == 0.0 ) + { + stopPumpRequest = TRUE; + } } else { @@ -730,24 +777,33 @@ *************************************************************************/ BOOL testROPumpTargetPressureOverride( MESSAGE_T *message ) { - BOOL result = f32Override( message, &targetROPumpPressure ); - if ( backupSet ) + if ( targetROPumpPressure.override == OVERRIDE_RESET ) { // Restore previous flow and pressure values - if ( targetROPumpFlowRate.override == OVERRIDE_RESET && backupSet ) + targetROPumpPressure.data = targetROPumpPressure.ovInitData; + targetROPumpPressure.ovInitData = 0.0; + if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET ) // isTargetDutyCycleActive { - targetROPumpFlowRate.data = backupROPumpFlowRate; + roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovInitData; } - if ( targetROPumpPressure.override == OVERRIDE_RESET ) + else { - targetROPumpPressure.data = backupROPumpPressure; + roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovData; } - if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET ) + if ( targetROPumpFlowRate.override == OVERRIDE_RESET ) // isTargetFlowActive { - roPumpOpenLoopTargetDutyCycle.data = backupROPumpDutyCyclePctSet; + targetROPumpFlowRate.data = targetROPumpFlowRate.ovInitData; } - backupSet = FALSE; + else + { + targetROPumpFlowRate.data = targetROPumpFlowRate.ovData; + } } +// else if ( targetROPumpFlowRate.override != OVERRIDE_RESET ) +// { +// lastOverrideType = OVERRIDE_PRESSURE; +// } + BOOL result = f32Override( message, &targetROPumpPressure ); setROPumpTargetPressure(getTargetROPumpPressure()); return result; @@ -765,15 +821,33 @@ *************************************************************************/ BOOL testROPumpTargetFlowOverride( MESSAGE_T *message ) { - BOOL result = u32Override( message, &targetROPumpFlowRate, MIN_RO_FLOWRATE_MLPM, MAX_RO_FLOWRATE_MLPM ); - if ( targetROPumpFlowRate.override == OVERRIDE_RESET && backupSet ) + if ( targetROPumpFlowRate.override == OVERRIDE_RESET ) { // Restore previous flow and pressure values - targetROPumpFlowRate.data = backupROPumpFlowRate; - targetROPumpPressure.data = backupROPumpPressure; - roPumpOpenLoopTargetDutyCycle.data = backupROPumpDutyCyclePctSet; - backupSet = FALSE; + targetROPumpFlowRate.data = targetROPumpFlowRate.ovInitData; + targetROPumpFlowRate.ovInitData = 0; + if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET ) // isTargetDutyCycleActive + { + roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovInitData; + } + else + { + roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovData; + } + if ( targetROPumpPressure.override == OVERRIDE_RESET ) // isTargetPressureActive + { + targetROPumpPressure.data = targetROPumpPressure.ovInitData; + } + else + { + targetROPumpPressure.data = targetROPumpPressure.ovData; + } } +// else if ( targetROPumpFlowRate.override != OVERRIDE_RESET ) +// { +// lastOverrideType = OVERRIDE_FLOW; +// } + BOOL result = u32Override( message, &targetROPumpFlowRate, MIN_RO_FLOWRATE_MLPM, MAX_RO_FLOWRATE_MLPM ); setROPumpTargetFlowRateMLPM(getTargetROPumpFlowRateMLPM()); return result; @@ -791,16 +865,34 @@ *************************************************************************/ BOOL testROPumpTargetDutyCycleOverride( MESSAGE_T *message ) { - BOOL result = f32Override( message, &roPumpOpenLoopTargetDutyCycle ); - if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET && backupSet ) + if ( roPumpOpenLoopTargetDutyCycle.override == OVERRIDE_RESET ) { // Restore previous flow and pressure values - targetROPumpFlowRate.data = backupROPumpFlowRate; - targetROPumpPressure.data = backupROPumpPressure; - roPumpOpenLoopTargetDutyCycle.data = backupROPumpDutyCyclePctSet; - backupSet = FALSE; - + roPumpOpenLoopTargetDutyCycle.data = roPumpOpenLoopTargetDutyCycle.ovInitData; + roPumpOpenLoopTargetDutyCycle.ovInitData = 0.0; + if ( targetROPumpFlowRate.override == OVERRIDE_RESET ) // isTargetFlowActive + { + targetROPumpFlowRate.data = targetROPumpFlowRate.ovInitData; + } + else + { + targetROPumpFlowRate.data = targetROPumpFlowRate.ovData; + } + if ( targetROPumpPressure.override == OVERRIDE_RESET ) // isTargetPressureActive + { + targetROPumpPressure.data = targetROPumpPressure.ovInitData; + } + else + { + targetROPumpPressure.data = targetROPumpPressure.ovData; + } } +// else if ( roPumpOpenLoopTargetDutyCycle.override != OVERRIDE_RESET ) +// { +// lastOverrideType = OVERRIDE_DUTYCYCLE; +// } + + BOOL result = f32Override( message, &roPumpOpenLoopTargetDutyCycle ); setROPumpTargetDutyCycle(getTargetROPumpDutyCyclePCT()); return result;