Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -r65d64e90e7e32c1914708d0ff3df18a96e012af2 -rd47b6f178dd68d49962c72a5ccb6e98152a2a1d0 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 65d64e90e7e32c1914708d0ff3df18a96e012af2) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision d47b6f178dd68d49962c72a5ccb6e98152a2a1d0) @@ -128,11 +128,11 @@ #define DIAL_IN_FLOW_A_ZERO 1.267F ///< Y intercept used for alpha flow coefficient calculation. #define DIAL_IN_FLOW_WEAR_A_TERM 0.000000003551F ///< A term used for wear portion of alpha flow coefficient. #define DIAL_IN_FLOW_WEAR_B_TERM 0.002244F ///< B term used for wear portion of alpha flow coefficient. -#define DIAL_IN_FLOW_QHIGHTRANSITION 400.0F /// High flow rate transition for blended algorithm -#define DIAL_IN_FLOW_QLOWTRANSITION 300.0F /// Low flow rate transition for blended algorithm -#define DIAL_IN_FLOW_PEST_A_TERM -0.000491F /// a (2nd order) term in polynomial fit for pressure estimation -#define DIAL_IN_FLOW_PEST_B_TERM -0.04672F /// b (first order) term in polynomial fit for pressure estimation -#define DIAL_IN_FLOW_PEST_C_TERM 18.648F /// c (zero order) term in polynomial fit for pressure estimation +#define DIAL_IN_FLOW_QHIGHTRANSITION 400.0F ///< High flow rate transition for blended algorithm +#define DIAL_IN_FLOW_QLOWTRANSITION 300.0F ///< Low flow rate transition for blended algorithm +#define DIAL_IN_FLOW_PEST_A_TERM -0.000491F ///< a (2nd order) term in polynomial fit for pressure estimation +#define DIAL_IN_FLOW_PEST_B_TERM -0.04672F ///< b (first order) term in polynomial fit for pressure estimation +#define DIAL_IN_FLOW_PEST_C_TERM 18.648F ///< c (zero order) term in polynomial fit for pressure estimation #define DIAL_IN_MAX_ROTOR_COUNT_FOR_WEAR 25000 ///< Maximum rotor count for determining wear of the cartridge (negligible affect beyond this threshold). /// Enumeration of dialysate inlet pump states. @@ -211,7 +211,7 @@ static U32 dipCurrErrorDurationCtr = 0; ///< Used for tracking persistence of dip current errors. static HD_PUMPS_CAL_RECORD_T dialInPumpCalRecord; ///< Dialysate inlet calibration record. -static OVERRIDE_U32_T dialysateInPumpRotorCounter = { 0, 0, 0, 0 }; ///< Running counter for dialin pump rotor revolutions +static OVERRIDE_U32_T dialysateInPumpRotorCounter = { 0, 0, 0, 0 }; ///< Running counter for dialin pump rotor revolutions static F32 filteredDialInFlowMeterReading = 0.0; ///< Storage for current filtered flow meter reading // ********** private function prototypes ********** @@ -233,8 +233,8 @@ static void checkDialInPumpSpeeds( void ); static void checkDialInPumpMCCurrent( void ); static void checkDialInPumpFlowRate( void ); -static F32 calcDialInFlow( void ); -static F32 dialysateInPumpPWMFromTargetFlowRate( F32 QdTarget); +static F32 calcDialInFlow( void ); +static F32 dialysateInPumpPWMFromTargetFlowRate( F32 QdTarget ); static void resetDialInPumpRotorCount( void ); /*********************************************************************//** @@ -489,7 +489,7 @@ if ( ++dialysateFlowDataFreshStatusCounter > DIP_DIALYSATE_FLOW_DATA_ALARM_THRESHOLD ) { filterDialInFlowReadings( 0.0 ); - //activateAlarmNoData( ALARM_ID_HD_DIALYSATE_FLOW_DATA_NOT_RECEIVE ); // TODO: Uncomment this after testing done. DN-17OCT2022 + activateAlarmNoData( ALARM_ID_HD_DIALYSATE_FLOW_DATA_NOT_RECEIVE ); } } else @@ -775,7 +775,7 @@ * The calcDialInFlow function calculates an estimated dialysate flow rate from * a blended algorithm based on flow meter data and dialin pump speed and tubing wear * (measured from count of rotor revolutions since cartridge install). - * @details Inputs: DialInPumpRotorCounter, (target flow rate) + * @details Inputs: DialInPumpRotorCounter, targetDialInFlowRate, dialInPumpRotorSpeedRPM * @details Outputs: measuredDialInFlowRate (ml/min) * @return none *************************************************************************/ @@ -796,21 +796,21 @@ U32 r = getDialInPumpRotorCount(); U32 rotCnt = CAP( r, DIAL_IN_MAX_ROTOR_COUNT_FOR_WEAR ); F32 wear = DIAL_IN_FLOW_WEAR_A_TERM * (F32)rotCnt + DIAL_IN_FLOW_WEAR_B_TERM; - F32 Pest = DIAL_IN_FLOW_PEST_A_TERM * (QdTarget * QdTarget) + DIAL_IN_FLOW_PEST_B_TERM * QdTarget + DIAL_IN_FLOW_PEST_C_TERM; + F32 Pest = DIAL_IN_FLOW_PEST_A_TERM * ( QdTarget * QdTarget ) + DIAL_IN_FLOW_PEST_B_TERM * QdTarget + DIAL_IN_FLOW_PEST_C_TERM; F32 alpha = wear * Pest + DIAL_IN_FLOW_A_ZERO; - F32 calculatedFlow = (alpha * pumpRPM * ML_PER_LITER) / DIP_REV_PER_LITER; + F32 calculatedFlow = ( alpha * pumpRPM * ML_PER_LITER ) / DIP_REV_PER_LITER; - //printf("pumpRPM=%f,rotCnt=%d,wear=%f,Pest=%f,alpha=%f,calculatedFlow=%f\n", pumpRPM,rotCnt,wear,Pest,alpha,calculatedFlow); - if (QdTarget < DIAL_IN_FLOW_QHIGHTRANSITION && QdTarget >= DIAL_IN_FLOW_QLOWTRANSITION) + if ( ( QdTarget < DIAL_IN_FLOW_QHIGHTRANSITION ) && ( QdTarget >= DIAL_IN_FLOW_QLOWTRANSITION ) ) { // use blended flow rate calculation - estimatedFlow = ( (QdTarget - DIAL_IN_FLOW_QLOWTRANSITION)/(DIAL_IN_FLOW_QHIGHTRANSITION-DIAL_IN_FLOW_QLOWTRANSITION) ) * calculatedFlow + - ( (DIAL_IN_FLOW_QHIGHTRANSITION - QdTarget)/(DIAL_IN_FLOW_QHIGHTRANSITION-DIAL_IN_FLOW_QLOWTRANSITION) ) * filteredDialInFlowMeterReading; + estimatedFlow = ( ( QdTarget - DIAL_IN_FLOW_QLOWTRANSITION ) / ( DIAL_IN_FLOW_QHIGHTRANSITION - DIAL_IN_FLOW_QLOWTRANSITION ) ) * calculatedFlow + + ( ( DIAL_IN_FLOW_QHIGHTRANSITION - QdTarget ) / ( DIAL_IN_FLOW_QHIGHTRANSITION - DIAL_IN_FLOW_QLOWTRANSITION ) ) * filteredDialInFlowMeterReading; } else { // use calculated flow rate. Assume target flow rate has already checked for out of bounds on low end. estimatedFlow = calculatedFlow; } } + return estimatedFlow; } @@ -819,19 +819,22 @@ * @brief * The dialysateInPumpPWMFromTargetFlowRate function calculates a motor PWM setting * from the estimator based on target flow rate and tubing wear. - * @details Inputs: QdTarget, dialInPumpRotorCounter + * @details Inputs: dialInPumpRotorCounter * @details Outputs: none - * @return Motor PWM value for target rate + * @param QdTarget target dialysate flow rate + * @return Motor PWM value for given target flow rate *************************************************************************/ -static F32 dialysateInPumpPWMFromTargetFlowRate( F32 QdTarget) +static F32 dialysateInPumpPWMFromTargetFlowRate( F32 QdTarget ) { - F32 uncorrectedPWM = DIP_PWM_FROM_ML_PER_MIN(QdTarget); - U32 r = getDialInPumpRotorCount(); - U32 rotCnt = CAP( r, DIAL_IN_MAX_ROTOR_COUNT_FOR_WEAR ); - F32 wear = DIAL_IN_FLOW_WEAR_A_TERM * (F32)rotCnt + DIAL_IN_FLOW_WEAR_B_TERM; - F32 Pest = DIAL_IN_FLOW_PEST_A_TERM * (QdTarget * QdTarget) + DIAL_IN_FLOW_PEST_B_TERM * QdTarget + DIAL_IN_FLOW_PEST_C_TERM; - F32 alpha = wear * Pest + DIAL_IN_FLOW_A_ZERO; - return uncorrectedPWM / alpha; + F32 uncorrectedPWM = DIP_PWM_FROM_ML_PER_MIN( QdTarget ); + U32 r = getDialInPumpRotorCount(); + U32 rotCnt = CAP( r, DIAL_IN_MAX_ROTOR_COUNT_FOR_WEAR ); + F32 wear = DIAL_IN_FLOW_WEAR_A_TERM * (F32)rotCnt + DIAL_IN_FLOW_WEAR_B_TERM; + F32 Pest = DIAL_IN_FLOW_PEST_A_TERM * (QdTarget * QdTarget) + DIAL_IN_FLOW_PEST_B_TERM * QdTarget + DIAL_IN_FLOW_PEST_C_TERM; + F32 alpha = wear * Pest + DIAL_IN_FLOW_A_ZERO; + F32 correctedPWM = ( uncorrectedPWM / alpha ); + + return correctedPWM; } /*********************************************************************//** @@ -840,7 +843,7 @@ * that is a proxy for cartridge wear. Call this function after a new cartridge * has been installed. * @details Inputs: none - * @details Outputs: dialInPumpRotorCounter + * @details Outputs: dialInPumpRotorCounter is reset to 0 * @return none *************************************************************************/ void resetDialInPumpRotorCount( void ) @@ -1837,4 +1840,5 @@ return result; } + /**@}*/