Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -r714e5bc990074b9b73a46af011bf7204f0d5d5e1 -r231665843bcb057cab17d967fa1543d94a66c9df --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 714e5bc990074b9b73a46af011bf7204f0d5d5e1) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 231665843bcb057cab17d967fa1543d94a66c9df) @@ -7,8 +7,8 @@ * * @file DialInFlow.c * -* @author (last) Dara Navaei -* @date (last) 18-Oct-2022 +* @author (last) Dong Nguyen +* @date (last) 10-Nov-2022 * * @author (original) Sean * @date (original) 16-Dec-2019 @@ -47,7 +47,7 @@ #define MAX_DIAL_IN_PUMP_PWM_STEP_UP_CHANGE 0.0133F ///< Max duty cycle change when ramping up ~ 200 mL/min/s. #define MAX_DIAL_IN_PUMP_PWM_STEP_DN_CHANGE 0.02F ///< Max duty cycle change when ramping down ~ 300 mL/min/s. -#define MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.89F ///< Controller will error if PWM duty cycle > 90%, so set max to 89%. +#define MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.90F ///< Controller will error if PWM duty cycle > 90%, so set max to 90%. #define MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.10F ///< Controller will error if PWM duty cycle < 10%, so set min to 10%. #define MIN_DG_DIAL_FLOW_RATE 10.0F ///< Minimum DG Dialysate Flow Rate (mL/Min) - DN-9NOV2022 @@ -108,16 +108,13 @@ #define DIP_GEAR_RATIO 32.0F ///< DialIn pump motor to dialIn pump gear ratio. #define DIP_PWM_ZERO_OFFSET 0.1F ///< 10% PWM duty cycle = zero speed. -/// Macro converts flow rate to estimate PWM needed to achieve it. -#define DIP_PWM_FROM_ML_PER_MIN(rate) ( (rate) * DIP_ML_PER_MIN_TO_PUMP_RPM_FACTOR * DIP_GEAR_RATIO * DIP_MOTOR_RPM_TO_PWM_DC_FACTOR + DIP_PWM_ZERO_OFFSET /// Conversion from PWM duty cycle % to commanded pump motor speed. PWM range is 10% to 90%. RPM range is 0 to 3200. 3200 / 0.8 = 4000. #define DIP_PWM_TO_MOTOR_SPEED_RPM(pwm) ( ((pwm) - DIP_PWM_ZERO_OFFSET) * 4000.0F ) /// Conversion from pump motor speed to PWM duty cycle. #define DIP_MOTOR_SPEED_RPM_TO_PWM(rpm) ( ( rpm / 4000.0F ) + 0.1 ) -// Macro converts PWM to estimate flow rate needed to achieve it. +// Macro converts PWM to estimate flow rate needed to achieve it. TODO - this macro does not reverse the function that estimates PWM from target flow rate - and it should #define DIP_ML_PER_MIN_FROM_PWM(pwm) ( (pwm) - DIP_PWM_ZERO_OFFSET ) / DIP_ML_PER_MIN_TO_PUMP_RPM_FACTOR / DIP_GEAR_RATIO / DIP_MOTOR_RPM_TO_PWM_DC_FACTOR - /// Measured dialIn flow is filtered w/ moving average. #define SIZE_OF_ROLLING_AVG 4 @@ -322,7 +319,8 @@ dialInPumpDirection = dir; dialInPumpControlMode = mode; // Set PWM duty cycle target to an estimated initial target to ramp to based on target flow rate - then we will control to flow when ramp completed - dialInPumpPWMDutyCyclePct = ( 0 == flowRate ? DIP_PWM_ZERO_OFFSET : dialysateInPumpPWMFromTargetFlowRate( (F32)flowRate ) ); + dialInPumpPWMDutyCyclePct = ( 0 == flowRate ? DIP_PWM_ZERO_OFFSET : dialysateInPumpPWMFromTargetFlowRate( (F32)flowRate ) ); + dialInPumpPWMDutyCyclePct = RANGE( dialInPumpPWMDutyCyclePct, MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE, MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE ); switch ( dialInPumpState ) { @@ -1351,7 +1349,6 @@ static void checkDialInPumpFlowRate( void ) { F32 flow = getMeasuredDialInFlowRate(); - F32 measuredDialInFlow; // Range check on measure DPi flow rate. if ( ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_DIAL_IN_FLOW_OUT_OF_RANGE, ( flow > DIP_MAX_FLOW_RATE ) || ( flow < DIP_MIN_FLOW_RATE ) ) ) ) @@ -1396,9 +1393,10 @@ // Check DG Dialysate flow rate /* TODO: Temporarily comment this out. Will restore it when know better how to handle this alarm. - measuredDialInFlow = getDGDialysateFlowRateLMin() * ML_PER_LITER; if ( ( TRUE == isDialInPumpRunning() ) && ( dialInPumpControlMode != PUMP_CONTROL_MODE_OPEN_LOOP ) ) { + F32 measuredDialInFlow = getDGDialysateFlowRateLMin() * ML_PER_LITER; + if ( ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_DIAL_IN_FLOW_CHECK_FAILURE, measuredDialInFlow < MIN_DG_DIAL_FLOW_RATE ) ) ) { SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_DIAL_IN_FLOW_CHECK_FAILURE, measuredDialInFlow, (F32)targetDialInFlowRate ); @@ -1407,8 +1405,7 @@ else { isPersistentAlarmTriggered( ALARM_ID_HD_DIAL_IN_FLOW_CHECK_FAILURE, FALSE ); - } - */ + } */ } /*********************************************************************//**