Index: firmware/App/Controllers/MixingControl.c =================================================================== diff -u -rcd1161514dbaff9e5b222931fff99618e39fd7ec -rf364406cd1f672078ca38ae8aad5bc508e9b64dd --- firmware/App/Controllers/MixingControl.c (.../MixingControl.c) (revision cd1161514dbaff9e5b222931fff99618e39fd7ec) +++ firmware/App/Controllers/MixingControl.c (.../MixingControl.c) (revision f364406cd1f672078ca38ae8aad5bc508e9b64dd) @@ -19,7 +19,6 @@ #include "Common.h" #include "ConcentratePumps.h" #include "Conductivity.h" -#include "DialysatePumps.h" #include "DDDefs.h" #include "DryBiCart.h" #include "Level.h" @@ -55,7 +54,7 @@ #define ACID_VOL_CONTROL_P_COEFFICIENT ( 0.00000997F / 2 ) ///< Acid proportional gain (kp) #define ACID_VOL_CONTROL_I_COEFFICIENT ( 0.00003988F / 5 ) ///< Acid integral gain. (ki) #define MIN_ACID_VOLUME_ML 0.3F ///< Minimum acid volume in mL -#define MAX_ACID_VOLUME_ML 1.0F ///< Maximum acid volume in mL/min. +#define MAX_ACID_VOLUME_ML 1.0F ///< Maximum acid volume in mL. #define BICARB_TARGET_CONDUCTIVITY 2714.0F ///< Target bicarb conductivity #define BICARB_DELTA_CONDUCTIVITY 500.0F ///< Delta bicarb conductivity @@ -195,6 +194,7 @@ static DIALYSATE_MIXING_STATE_T handleDialysateMixOpenLoopState( DIALYSATE_MIXING_ID_T mixId ); static DIALYSATE_MIXING_STATE_T handleDialysateMixRampToTargetState( DIALYSATE_MIXING_ID_T mixId ); static DIALYSATE_MIXING_STATE_T handleDialysateMixControlToTargetState( DIALYSATE_MIXING_ID_T mixId ); +static void handleDialysateCompositionMixing( void ); static void setBicarbMixVol( F32 targetValue ); static void setAcidMixVol( F32 targetValue ); @@ -215,8 +215,8 @@ static F32 getAcidKpGainCoefficient( void ); static F32 getAcidKiGainCoefficient( void ); -static U32 getMixingControlBicarbControlInterval( void ); -static U32 getMixingControlAcidControlInterval( void ); +static U32 getBicarbMixControlInterval( void ); +static U32 getAcidMixControlInterval( void ); // publish the status static void publishMixingControlData( void ); static U32 getMixingControlDataPublishInterval( void ); @@ -346,7 +346,7 @@ * state machine found. * @return none *************************************************************************/ -void execDialysateCompositionMixingController( void ) +static void handleDialysateCompositionMixing( void ) { DIALYSATE_MIXING_ID_T mixId; @@ -378,7 +378,7 @@ * @brief * The execMixingControl function executes the dialysate and bicarb open loop /closed loop * related state machines - * @details \b Inputs: none + * @details \b Inputs: Balancing chamber state * @details \b Outputs: none * @return none. *************************************************************************/ @@ -387,7 +387,7 @@ if( getCurrentBalancingChamberExecState() > BAL_CHAMBER_STATE_IDLE ) { // closed loop bicarb and acid mixing controller - execDialysateCompositionMixingController(); + handleDialysateCompositionMixing(); } // Publish mixing control data @@ -551,7 +551,6 @@ return result; } - /*********************************************************************//** * @brief * The getAcidKiGainCoefficient function gets the Ki Gain for closed loop @@ -569,12 +568,12 @@ /*********************************************************************//** * @brief - * The getmixingControlBicarbMixControlInterval function gets the bicart mix control interval + * The getBicarbMixControlInterval function gets the bicart mix control interval * @details \b Inputs: mixingControlBicarbMixControlInterval * @details \b Outputs: none * @return TRUE if successful, FALSE if not. *************************************************************************/ -static U32 getMixingControlBicarbControlInterval( void ) +static U32 getBicarbMixControlInterval( void ) { U32 result = getU32OverrideValue( &mixingControlBicarbControlInterval ); @@ -583,40 +582,66 @@ /*********************************************************************//** * @brief - * The getMixingControlAcidControlInterval function gets the acid mix control interval + * The getAcidMixControlInterval function gets the acid mix control interval * @details \b Inputs: mixingControlAcidControlInterval * @details \b Outputs: none * @return TRUE if successful, FALSE if not. *************************************************************************/ -static U32 getMixingControlAcidControlInterval( void ) +static U32 getAcidMixControlInterval( void ) { U32 result = getU32OverrideValue( &mixingControlAcidControlInterval ); return result; } +/*********************************************************************//** + * @brief + * The getTotalConductivity function gets the total conductivity of bicarb and acid + * @details \b Inputs: none + * @details \b Outputs: none + * @return conductivity + *************************************************************************/ static F32 getTotalConductivity( void ) { return TOTAL_CONDUCTIVITY; } +/*********************************************************************//** + * @brief + * The getAcidConducivityPost function gets the acid conductivity post + * @details \b Inputs: none + * @details \b Outputs: none + * @return conductivity + *************************************************************************/ static F32 getAcidConducivityPost( void ) { return ACID_CONDUCTIVITY_POST; } +/*********************************************************************//** + * @brief + * The getBicarbConductivityPost function gets the bicarb conductivity post + * @details \b Inputs: none + * @details \b Outputs: none + * @return conductivity + *************************************************************************/ static F32 getBicarbConductivityPost( void ) { return BICARB_CONDUCTIVITY_PRE; } +/*********************************************************************//** + * @brief + * The getBicarbConductivityPre function gets the bicarb conductivity pre + * @details \b Inputs: none + * @details \b Outputs: none + * @return conductivity + *************************************************************************/ static F32 getBicarbConductivityPre( void ) { return BICARB_CONDUCTIVITY_PRE; } - - /*********************************************************************//** * @brief * The getmixingControlFillDataPublishInterval function gets the mix controller @@ -643,16 +668,15 @@ *************************************************************************/ static DIALYSATE_MIXING_STATE_T handleDialysateMixOpenLoopState( DIALYSATE_MIXING_ID_T mixId ) { - DIALYSATE_MIXING_STATE_T result; + DIALYSATE_MIXING_STATE_T result = DIALYSATE_MIXING_OPEN_LOOP_STATE; if ( BICARB_MIX_ID == mixId ) { + //TODO: right now using the fixed conductivity , later use the calculated version API F32 measuredBicarbConductivity = getFilteredConductivity( D17_COND ); F32 bicarbConductivity = getBicarbTargetConductivity(); F32 bicarbDeltaConductivity = getBicarbDeltaConductivity(); - result = DIALYSATE_MIXING_OPEN_LOOP_STATE; - if ( TRUE != getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DOSING_OPEN_LOOP_CONTROL ) ) { // if measured conductivity crossed (targetConductivity- deltaConuctivity) , switch to closed loop @@ -664,12 +688,11 @@ } else if ( ACID_MIX_ID == mixId ) { + //TODO: right now using the fixed conductivity , later use the calculated version API F32 measuredAcidBicarbMixConductivity = getFilteredConductivity( D27_COND ); F32 DialysateConductivity = getDialysateTargetConductivity(); F32 DialysateDeltaConductivity = getDialysateTargetConductivity(); - result = DIALYSATE_MIXING_OPEN_LOOP_STATE; - if ( TRUE != getTestConfigStatus( TEST_CONFIG_DD_ENABLE_DOSING_OPEN_LOOP_CONTROL ) ) { // if measured conductivity crossed (targetConductivity- deltaConuctivity) , switch to closed loop @@ -727,7 +750,7 @@ if ( BICARB_MIX_ID == mixId ) { // control interval for bicarb - if ( ( ++dialysateMix[ mixId ].controlTimerCounter >= getMixingControlBicarbControlInterval() ) ) + if ( ( ++dialysateMix[ mixId ].controlTimerCounter >= getBicarbMixControlInterval() ) ) { F32 bicarbMixVol; @@ -758,19 +781,20 @@ if ( ACID_MIX_ID == mixId ) { // control interval for acid - if ( ( ++dialysateMix[ mixId ].controlTimerCounter >= getMixingControlAcidControlInterval( ) ) ) + if ( ( ++dialysateMix[ mixId ].controlTimerCounter >= getAcidMixControlInterval( ) ) ) { F32 acidMixVol; dialysateMix[ mixId ].controlTimerCounter = 0; + // TODO: use the calculated API F32 measuredDialysateConductivity = getFilteredConductivity( D27_COND ); F32 DialysateConductivity = getTotalConductivity();//getDialysateTargetConductivity(); PI_CONTROLLER_SIGNALS_DATA debugAcidControl; if ( fabs ( DialysateConductivity - measuredDialysateConductivity ) > ACID_DEADBAND_CONTROL ) { - acidMixVol = runPIController( PI_CONTROLLER_ID_ACID_VOL, getTotalConductivity() /*DialysateConductivity*/, measuredDialysateConductivity ); + acidMixVol = runPIController( PI_CONTROLLER_ID_ACID_VOL, DialysateConductivity, measuredDialysateConductivity ); // set acid mix volume if its above dead band threshold , else use previous set value setAcidMixVol( acidMixVol ); } @@ -861,7 +885,6 @@ return result; } - /*********************************************************************//** * @brief * The testmixingControlAcidMixVolumeOverride function sets the override value