Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -ra3a01327c8fe80f65f6658ae6cbef4910a4a8033 -r8e7158d8231435496fcf1d5649e51babf859ccc7 --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision a3a01327c8fe80f65f6658ae6cbef4910a4a8033) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 8e7158d8231435496fcf1d5649e51babf859ccc7) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2021 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file DialInFlow.c * * @author (last) Sean Nash -* @date (last) 30-Jun-2020 +* @date (last) 01-Dec-2020 * * @author (original) Sean * @date (original) 16-Dec-2019 @@ -21,16 +21,18 @@ #include "gio.h" #include "mibspi.h" +#include "DialInFlow.h" #include "FPGA.h" #include "InternalADC.h" #include "NVDataMgmt.h" #include "OperationModes.h" +#include "PersistentAlarm.h" #include "PIControllers.h" +#include "SafetyShutdown.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" #include "TaskPriority.h" #include "Timers.h" -#include "DialInFlow.h" /** * @addtogroup DialysateInletFlow @@ -39,53 +41,66 @@ // ********** private definitions ********** -#define DIAL_IN_FLOW_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the dialIn flow data is published on the CAN bus +/// interval (ms/task time) at which the dialIn flow data is published on the CAN bus. +#define DIAL_IN_FLOW_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) #define MAX_DIAL_IN_PUMP_PWM_STEP_UP_CHANGE 0.0133 ///< max duty cycle change when ramping up ~ 200 mL/min/s. #define MAX_DIAL_IN_PUMP_PWM_STEP_DN_CHANGE 0.02 ///< max duty cycle change when ramping down ~ 300 mL/min/s. -#define MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.88 ///< controller will error if PWM duty cycle > 90%, so set max to 88% -#define MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.12 ///< controller will error if PWM duty cycle < 10%, so set min to 12% +#define MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.88 ///< controller will error if PWM duty cycle > 90%, so set max to 88%. +#define MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE 0.12 ///< controller will error if PWM duty cycle < 10%, so set min to 12%. #define DIP_CONTROL_INTERVAL ( 10000 / TASK_GENERAL_INTERVAL ) ///< interval (ms/task time) at which the dialIn pump is controlled -#define DIP_P_COEFFICIENT 0.00035 ///< P term for dialIn pump control -#define DIP_I_COEFFICIENT 0.00035 ///< I term for dialIn pump control +#define DIP_P_COEFFICIENT 0.00035 ///< P term for dialIn pump control. +#define DIP_I_COEFFICIENT 0.00035 ///< I term for dialIn pump control. #define DIP_HOME_RATE 100 ///< target pump speed (in estimate mL/min) for homing. #define DIP_HOME_TIMEOUT_MS 10000 ///< maximum time allowed for homing to complete (in ms). -#define DIP_SPEED_CALC_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the dialysate inlet pump speed is calculated. +/// interval (ms/task time) at which the blood pump speed is calculated (every 40 ms). +#define DIP_SPEED_CALC_INTERVAL ( 40 / TASK_PRIORITY_INTERVAL ) +/// number of hall sensor counts kept in buffer to hold last 1 second of count data. +#define DIP_SPEED_CALC_BUFFER_LEN ( 1000 / DIP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) #define DIP_HALL_EDGE_COUNTS_PER_REV 48 ///< number of hall sensor edge counts per motor revolution. -#define DIP_MAX_FLOW_VS_SPEED_DIFF_ML_MIN 50.0 ///< maximum difference between measured flow and flow implied by measured motor speed. +#define DIP_MAX_FLOW_VS_SPEED_DIFF_RPM 200.0 ///< maximum difference between measured motor speed and speed implied by measured flow. #define DIP_MAX_MOTOR_SPEED_WHILE_OFF_RPM 100.0 ///< maximum motor speed (RPM) while motor is commanded off. #define DIP_MAX_ROTOR_VS_MOTOR_DIFF_RPM 5.0 ///< maximum difference in speed between motor and rotor (in rotor RPM). #define DIP_MAX_MOTOR_SPEED_ERROR_RPM 300.0 ///< maximum difference in speed between measured and commanded RPM. -#define DIP_FLOW_VS_SPEED_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) for flow vs. motor speed error condition. -#define DIP_OFF_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) for motor off error condition. -#define DIP_MOTOR_SPEED_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) motor speed error condition. -#define DIP_ROTOR_SPEED_ERROR_PERSIST ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) rotor speed error condition. +#define DIP_FLOW_VS_SPEED_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) for flow vs. motor speed error condition. +#define DIP_OFF_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) for motor off error condition. +#define DIP_MOTOR_SPEED_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) motor speed error condition. +#define DIP_ROTOR_SPEED_ERROR_PERSIST ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) rotor speed error condition. +#define DIP_DIRECTION_ERROR_PERSIST (250 / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) pump direction error condition. -#define DIP_MAX_CURR_WHEN_STOPPED_MA 150.0 ///< motor controller current should not exceed this when pump should be stopped -#define DIP_MIN_CURR_WHEN_RUNNING_MA 150.0 ///< motor controller current should always exceed this when pump should be running -#define DIP_MAX_CURR_WHEN_RUNNING_MA 1000.0 ///< motor controller current should not exceed this when pump should be running -#define DIP_MAX_CURR_ERROR_DURATION_MS 2000 ///< motor controller current errors persisting beyond this duration will trigger an alarm +#define DIP_MAX_CURR_WHEN_STOPPED_MA 150.0 ///< motor controller current should not exceed this when pump should be stopped. +#define DIP_MIN_CURR_WHEN_RUNNING_MA 150.0 ///< motor controller current should always exceed this when pump should be running. +#define DIP_MAX_CURR_WHEN_RUNNING_MA 2000.0 ///< motor controller current should not exceed this when pump should be running. +#define DIP_MAX_CURR_ERROR_DURATION_MS 2000 ///< motor controller current errors persisting beyond this duration will trigger an alarm. -#define DIP_SPEED_ADC_TO_RPM_FACTOR 1.280938 ///< conversion factor from ADC counts to RPM for dialIn pump motor -#define DIP_CURRENT_ADC_TO_MA_FACTOR 3.002 ///< conversion factor from ADC counts to mA for dialIn pump motor +#define DIP_SPEED_ADC_TO_RPM_FACTOR 1.280938 ///< conversion factor from ADC counts to RPM for dialIn pump motor. +#define DIP_CURRENT_ADC_TO_MA_FACTOR 3.002 ///< conversion factor from ADC counts to mA for dialIn pump motor. -#define DIP_REV_PER_LITER 150.24 ///< rotor revolutions per liter -#define DIP_ML_PER_MIN_TO_PUMP_RPM_FACTOR ( DIP_REV_PER_LITER / ML_PER_LITER ) ///< -#define DIP_GEAR_RATIO 32.0 ///< dialIn pump motor to dialIn pump gear ratio -#define DIP_MOTOR_RPM_TO_PWM_DC_FACTOR 0.00028 ///< ~28 BP motor RPM = 1% PWM duty cycle -#define DIP_PWM_ZERO_OFFSET 0.1 ///< 10% PWM duty cycle = zero speed -#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 ) ///< +#define DIP_REV_PER_LITER 150.0 ///< rotor revolutions per liter. +/// Macro converts flow rate to motor RPM. +#define DIP_ML_PER_MIN_TO_PUMP_RPM_FACTOR ( DIP_REV_PER_LITER / ML_PER_LITER ) +#define DIP_GEAR_RATIO 32.0 ///< dialIn pump motor to dialIn pump gear ratio. +#define DIP_MOTOR_RPM_TO_PWM_DC_FACTOR 0.00028 ///< ~28 BP motor RPM = 1% PWM duty cycle. +#define DIP_PWM_ZERO_OFFSET 0.1 ///< 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 ) -#define DIAL_IN_PUMP_ADC_FULL_SCALE_V 3.0 ///< BP analog signals are 0-3V (while int. ADC ref V may be different) +#define DIAL_IN_PUMP_ADC_FULL_SCALE_V 3.0 ///< BP analog signals are 0-3V (while int. ADC ref V may be different). #define DIAL_IN_PUMP_ADC_ZERO 1998 ///< Mid-point (zero) for ADC readings. -#define SIGN_FROM_12_BIT_VALUE(v) ( (S16)(v) - (S16)DIAL_IN_PUMP_ADC_ZERO ) ///< Macro converts a 12-bit ADC reading to a signed 16-bit value. - -#define SIZE_OF_ROLLING_AVG ( ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) * 10 ) ///< measured dialIn flow is filtered w/ moving average - +///< Macro converts a 12-bit ADC reading to a signed 16-bit value. +#define SIGN_FROM_12_BIT_VALUE(v) ( (S16)(v) - (S16)DIAL_IN_PUMP_ADC_ZERO ) + +/// measured dialIn flow is filtered w/ moving average. +#define SIZE_OF_ROLLING_AVG ( ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) * 10 ) + +/// dialysate flow sensor signal strength low alarm persistence. +#define FLOW_SIG_STRGTH_ALARM_PERSIST ( 5 * MS_PER_SECOND ) +#define MIN_FLOW_SIG_STRENGTH 0.9 ///< Minimum flow sensor signal strength (90%). + /// Enumeration of dialysate inlet pump states. typedef enum DialInPump_States { @@ -133,28 +148,31 @@ static F32 dialInFlowCalGain = 1.0; ///< dialysate flow calibration gain. static F32 dialInFlowCalOffset = 0.0; ///< dialysate flow calibration offset. -static OVERRIDE_U32_T dialInFlowDataPublishInterval = { DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, 0 }; ///< interval (in ms) at which to publish dialIn flow data to CAN bus -static OVERRIDE_S32_T targetDialInFlowRate = { 0, 0, 0, 0 }; ///< requested dialIn flow rate +/// interval (in ms) at which to publish dialIn flow data to CAN bus +static OVERRIDE_U32_T dialInFlowDataPublishInterval = { DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, DIAL_IN_FLOW_DATA_PUB_INTERVAL, 0 }; +static S32 targetDialInFlowRate = 0; ///< requested dialIn flow rate static OVERRIDE_F32_T measuredDialInFlowRate = { 0.0, 0.0, 0.0, 0 }; ///< measured dialysate inlet flow rate static OVERRIDE_F32_T dialInPumpRotorSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured dialysate inlet pump rotor speed static OVERRIDE_F32_T dialInPumpSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured dialysate inlet pump motor speed static OVERRIDE_F32_T adcDialInPumpMCSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured dialysate inlet pump motor controller speed static OVERRIDE_F32_T adcDialInPumpMCCurrentmA = { 0.0, 0.0, 0.0, 0 }; ///< measured dialysate inlet pump motor controller current +static OVERRIDE_F32_T dialInFlowSignalStrength = { 0.0, 0.0, 0.0, 0 }; ///< measured dialysate flow signal strength (%) static U32 dipControlTimerCounter = 0; ///< determines when to perform control on dialIn flow static U32 dipRotorRevStartTime = 0; ///< dialysate inlet pump rotor rotation start time (in ms) static BOOL dipStopAtHomePosition = FALSE; ///< stop dialysate inlet pump at next home position static U32 dipHomeStartTime = 0; ///< when did dialysate inlet pump home command begin? (in ms) -static U16 dipLastMotorHallSensorCount = 0; ///< last hall sensor count for the dialysate inlet pump motor -static MOTOR_DIR_T dipMotorDirectionFromHallSensors = MOTOR_DIR_FORWARD; ///< pump direction according to hall sensor count +static U16 dipLastMotorHallSensorCounts[ DIP_SPEED_CALC_BUFFER_LEN ]; ///< last hall sensor count for the dialysate inlet pump motor +static U32 dipMotorSpeedCalcIdx = 0; ///< index into 1 second buffer of motor speed hall sensor counts static U32 dipMotorSpeedCalcTimerCtr = 0; ///< counter determines interval for calculating dialysate inlet pump motor speed from hall sensor count. static U32 errorDialInFlowVsMotorSpeedPersistTimerCtr = 0; ///< persistence timer counter for flow vs. motor speed error condition. static U32 errorDialInMotorOffPersistTimerCtr = 0; ///< persistence timer counter for motor off check error condition. static U32 errorDialInMotorSpeedPersistTimerCtr = 0; ///< persistence timer counter for motor speed error condition. static U32 errorDialInRotorSpeedPersistTimerCtr = 0; ///< persistence timer counter for rotor speed error condition. +static U32 errorDialInPumpDirectionPersistTimerCtr = 0; ///< persistence timer counter for pump direction error condition. static F32 flowReadings[ SIZE_OF_ROLLING_AVG ]; ///< holds flow samples for a rolling average static U32 flowReadingsIdx = 0; ///< index for next sample in rolling average array @@ -185,39 +203,50 @@ static void checkDialInPumpSpeeds( void ); static void checkDialInPumpFlowAgainstSpeed( void ); static void checkDialInPumpMCCurrent( void ); +static void checkDialInFlowSensorSignalStrength( void ); static DATA_GET_PROTOTYPE( U32, getPublishDialInFlowDataInterval ); /*********************************************************************//** * @brief * The initDialInFlow function initializes the DialInFlow module. - * @details - * Inputs : none - * Outputs : DialInFlow module initialized. + * @details Inputs: none + * @details Outputs: DialInFlow module initialized. * @return none *************************************************************************/ void initDialInFlow( void ) -{ - dipLastMotorHallSensorCount = getFPGADialInPumpHallSensorCount(); +{ + U32 i; stopDialInPump(); setDialInPumpDirection( MOTOR_DIR_FORWARD ); // zero rolling flow average buffer resetDialInFlowMovingAverage(); + // zero motor hall sensors counts buffer + dipMotorSpeedCalcIdx = 0; + for ( i = 0; i < DIP_SPEED_CALC_BUFFER_LEN; i++ ) + { + dipLastMotorHallSensorCounts[ i ] = 0; + } + // initialize dialysate inlet flow PI controller initializePIController( PI_CONTROLLER_ID_DIALYSATE_FLOW, MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE, DIP_P_COEFFICIENT, DIP_I_COEFFICIENT, MIN_DIAL_IN_PUMP_PWM_DUTY_CYCLE, MAX_DIAL_IN_PUMP_PWM_DUTY_CYCLE ); + + // initialize persistent alarm for flow sensor signal strength too low + initPersistentAlarm( PERSISTENT_ALARM_DIALYSATE_FLOW_SIGNAL_STRENGTH, + ALARM_ID_DIALYSATE_FLOW_SIGNAL_STRENGTH_TOO_LOW, + FALSE, FLOW_SIG_STRGTH_ALARM_PERSIST, FLOW_SIG_STRGTH_ALARM_PERSIST ); } /*********************************************************************//** * @brief * The setDialInPumpTargetFlowRate function sets a new target flow rate and * pump direction. - * @details - * Inputs : isDialInPumpOn, dialInPumpDirectionSet - * Outputs : targetDialInFlowRate, dialInPumpdirection, dialInPumpPWMDutyCyclePct + * @details Inputs: isDialInPumpOn, dialInPumpDirectionSet + * @details Outputs: targetDialInFlowRate, dialInPumpdirection, dialInPumpPWMDutyCyclePct * @param flowRate new target dialIn flow rate * @param dir new dialIn flow direction * @param mode new control mode @@ -234,7 +263,7 @@ if ( flowRate <= MAX_DIAL_IN_FLOW_RATE ) { resetDialInFlowMovingAverage(); - targetDialInFlowRate.data = ( dir == MOTOR_DIR_FORWARD ? (S32)flowRate : (S32)flowRate * -1 ); + targetDialInFlowRate = ( dir == MOTOR_DIR_FORWARD ? (S32)flowRate : (S32)flowRate * -1 ); dialInPumpDirection = dir; dialInPumpControlMode = mode; // set PWM duty cycle target to an estimated initial target to ramp to based on target flow rate - then we'll control to flow when ramp completed @@ -282,14 +311,13 @@ /*********************************************************************//** * @brief * The signalDialInPumpHardStop function stops the dialIn pump immediately. - * @details - * Inputs : none - * Outputs : DialIn pump stopped, set point reset, state changed to off + * @details Inputs: none + * @details Outputs: DialIn pump stopped, set point reset, state changed to off * @return none *************************************************************************/ void signalDialInPumpHardStop( void ) { - targetDialInFlowRate.data = 0; + targetDialInFlowRate = 0; stopDialInPump(); dialInPumpState = DIAL_IN_PUMP_OFF_STATE; dialInPumpPWMDutyCyclePct = 0.0; @@ -302,9 +330,8 @@ * The signalDialInPumpRotorHallSensor function handles the dialysate inlet pump rotor * hall sensor detection. Calculates rotor speed (in RPM). Stops pump if * there is a pending request to home the pump. - * @details - * Inputs : dipRotorRevStartTime, dipStopAtHomePosition - * Outputs : dipRotorRevStartTime, dialInPumpRotorSpeedRPM + * @details Inputs: dipRotorRevStartTime, dipStopAtHomePosition + * @details Outputs: dipRotorRevStartTime, dialInPumpRotorSpeedRPM * @return none *************************************************************************/ void signalDialInPumpRotorHallSensor( void ) @@ -327,9 +354,8 @@ /*********************************************************************//** * @brief * The homeDialInPump function initiates a dialysate inlet pump home operation. - * @details - * Inputs : dialInPumpState - * Outputs : dipStopAtHomePosition, dipHomeStartTime, dialysate inlet pump started (slow) + * @details Inputs: dialInPumpState + * @details Outputs: dipStopAtHomePosition, dipHomeStartTime, dialysate inlet pump started (slow) * @return none *************************************************************************/ BOOL homeDialInPump( void ) @@ -346,30 +372,44 @@ return result; } +/*********************************************************************//** + * @brief + * The isDialInPumpRunning function returns whether the dialysate inlet pump + * is currently running or not. + * @details Inputs: isDialInPumpOn + * @details Outputs: none + * @return isDialInPumpOn + *************************************************************************/ +BOOL isDialInPumpRunning( void ) +{ + return isDialInPumpOn; +} + /*********************************************************************//** * @brief * The execDialInFlowMonitor function executes the dialIn flow monitor. - * @details - * Inputs : none - * Outputs : measuredDialInFlowRate, adcDialInPumpMCSpeedRPM, adcDialInPumpMCCurrentmA + * @details Inputs: none + * @details Outputs: measuredDialInFlowRate, adcDialInPumpMCSpeedRPM, adcDialInPumpMCCurrentmA * @return none *************************************************************************/ void execDialInFlowMonitor( void ) { + HD_OP_MODE_T opMode = getCurrentOperationMode(); U16 dipRPM = getIntADCReading( INT_ADC_DIAL_IN_PUMP_SPEED ); U16 dipmA = getIntADCReading( INT_ADC_DIAL_IN_PUMP_MOTOR_CURRENT ); F32 dipFlow = ( getFPGADialysateFlow() * dialInFlowCalGain ) + dialInFlowCalOffset; adcDialInPumpMCSpeedRPM.data = (F32)(SIGN_FROM_12_BIT_VALUE(dipRPM)) * DIP_SPEED_ADC_TO_RPM_FACTOR; adcDialInPumpMCCurrentmA.data = (F32)(SIGN_FROM_12_BIT_VALUE(dipmA)) * DIP_CURRENT_ADC_TO_MA_FACTOR; + dialInFlowSignalStrength.data = getFPGADialysateFlowSignalStrength(); filterDialInFlowReadings( dipFlow ); // calculate dialysate inlet pump motor speed/direction from hall sensor count updateDialInPumpSpeedAndDirectionFromHallSensors(); // don't start enforcing checks until out of init/POST mode - if ( getCurrentOperationMode() != MODE_INIT ) + if ( opMode != MODE_INIT ) { // check pump direction checkDialInPumpDirection(); @@ -379,7 +419,9 @@ checkDialInPumpSpeeds(); checkDialInPumpFlowAgainstSpeed(); // check for home position, zero/low speed - checkDialInPumpRotor(); + checkDialInPumpRotor(); + // check flow sensor signal strength + checkDialInFlowSensorSignalStrength(); } // publish dialIn flow data on interval @@ -389,9 +431,8 @@ /*********************************************************************//** * @brief * The execDialInFlowController function executes the dialIn flow controller. - * @details - * Inputs : dialInPumpState - * Outputs : dialInPumpState + * @details Inputs: dialInPumpState + * @details Outputs: dialInPumpState * @return none *************************************************************************/ void execDialInFlowController( void ) @@ -424,17 +465,16 @@ * @brief * The handleDialInPumpOffState function handles the dialIn pump off state * of the dialIn pump controller state machine. - * @details - * Inputs : targetDialInFlowRate, dialInPumpDirection - * Outputs : dialInPumpPWMDutyCyclePctSet, dialInPumpDirectionSet, isDialInPumpOn + * @details Inputs: targetDialInFlowRate, dialInPumpDirection + * @details Outputs: dialInPumpPWMDutyCyclePctSet, dialInPumpDirectionSet, isDialInPumpOn * @return next state *************************************************************************/ static DIAL_IN_PUMP_STATE_T handleDialInPumpOffState( void ) { DIAL_IN_PUMP_STATE_T result = DIAL_IN_PUMP_OFF_STATE; // if we've been given a flow rate, setup ramp up and transition to ramp up state - if ( getTargetDialInFlowRate() != 0 ) + if ( targetDialInFlowRate != 0 ) { // set initial PWM duty cycle dialInPumpPWMDutyCyclePctSet = DIP_PWM_ZERO_OFFSET + MAX_DIAL_IN_PUMP_PWM_STEP_UP_CHANGE; @@ -453,17 +493,16 @@ * @brief * The handleDialInPumpRampingUpState function handles the ramp up state * of the dialIn pump controller state machine. - * @details - * Inputs : dialInPumpPWMDutyCyclePctSet - * Outputs : dialInPumpPWMDutyCyclePctSet + * @details Inputs: dialInPumpPWMDutyCyclePctSet + * @details Outputs: dialInPumpPWMDutyCyclePctSet * @return next state *************************************************************************/ static DIAL_IN_PUMP_STATE_T handleDialInPumpRampingUpState( void ) { DIAL_IN_PUMP_STATE_T result = DIAL_IN_PUMP_RAMPING_UP_STATE; // have we been asked to stop the dialIn pump? - if ( 0 == getTargetDialInFlowRate() ) + if ( 0 == targetDialInFlowRate ) { // start ramp down to stop dialInPumpPWMDutyCyclePctSet -= MAX_DIAL_IN_PUMP_PWM_STEP_DN_CHANGE; @@ -498,17 +537,16 @@ * @brief * The handleDialInPumpRampingDownState function handles the ramp down state * of the dialIn pump controller state machine. - * @details - * Inputs : dialInPumpPWMDutyCyclePctSet - * Outputs : dialInPumpPWMDutyCyclePctSet + * @details Inputs: dialInPumpPWMDutyCyclePctSet + * @details Outputs: dialInPumpPWMDutyCyclePctSet * @return next state *************************************************************************/ static DIAL_IN_PUMP_STATE_T handleDialInPumpRampingDownState( void ) { DIAL_IN_PUMP_STATE_T result = DIAL_IN_PUMP_RAMPING_DOWN_STATE; // have we essentially reached zero speed - if ( dialInPumpPWMDutyCyclePctSet < (MAX_DIAL_IN_PUMP_PWM_STEP_UP_CHANGE + DIP_PWM_ZERO_OFFSET) ) + if ( dialInPumpPWMDutyCyclePctSet < (MAX_DIAL_IN_PUMP_PWM_STEP_DN_CHANGE + DIP_PWM_ZERO_OFFSET) ) { stopDialInPump(); result = DIAL_IN_PUMP_OFF_STATE; @@ -541,9 +579,8 @@ * @brief * The handleDialInPumpControlToTargetState function handles the "control to * target" state of the dialIn pump controller state machine. - * @details - * Inputs : none - * Outputs : dialInPumpState + * @details Inputs: none + * @details Outputs: dialInPumpState * @return next state *************************************************************************/ static DIAL_IN_PUMP_STATE_T handleDialInPumpControlToTargetState( void ) @@ -555,7 +592,7 @@ { if ( dialInPumpControlModeSet == PUMP_CONTROL_MODE_CLOSED_LOOP ) { - F32 tgtFlow = (F32)getTargetDialInFlowRate(); + F32 tgtFlow = (F32)targetDialInFlowRate; F32 actFlow = getMeasuredDialInFlowRate(); F32 newPWM; @@ -573,9 +610,8 @@ * @brief * The setDialInPumpControlSignalPWM function sets the PWM duty cycle for * the dialysate inlet pump to a given %. - * @details - * Inputs : none - * Outputs : dialIn pump stop signal activated, PWM duty cycle zeroed + * @details Inputs: none + * @details Outputs: dialIn pump stop signal activated, PWM duty cycle zeroed * @param newPWM new duty cycle % to apply to PWM * @return none *************************************************************************/ @@ -587,9 +623,8 @@ /*********************************************************************//** * @brief * The stopDialInPump function sets the dialIn pump stop signal. - * @details - * Inputs : none - * Outputs : dialIn pump stop signal activated, PWM duty cycle zeroed + * @details Inputs: none + * @details Outputs: dialIn pump stop signal activated, PWM duty cycle zeroed * @return none *************************************************************************/ static void stopDialInPump( void ) @@ -603,9 +638,8 @@ /*********************************************************************//** * @brief * The releaseDialInPumpStop function clears the dialIn pump stop signal. - * @details - * Inputs : none - * Outputs : dialIn pump stop signal + * @details Inputs: none + * @details Outputs: dialIn pump stop signal * @return none *************************************************************************/ static void releaseDialInPumpStop( void ) @@ -617,9 +651,8 @@ * @brief * The setDialInPumpDirection function sets the set dialIn pump direction to * the given direction. - * @details - * Inputs : dialInPumpState - * Outputs : dialInPumpState + * @details Inputs: dialInPumpState + * @details Outputs: dialInPumpState * @param dir dialIn pump direction to set * @return none *************************************************************************/ @@ -647,9 +680,8 @@ * @brief * The getPublishDialInFlowDataInterval function gets the dialIn flow data * publication interval. - * @details - * Inputs : dialInFlowDataPublishInterval - * Outputs : none + * @details Inputs: dialInFlowDataPublishInterval + * @details Outputs: none * @return the current dialIn flow data publication interval (in task intervals). *************************************************************************/ U32 getPublishDialInFlowDataInterval( void ) @@ -668,30 +700,21 @@ * @brief * The getTargetDialInFlowRate function gets the current target dialIn flow * rate. - * @details - * Inputs : targetDialInFlowRate - * Outputs : none + * @details Inputs: targetDialInFlowRate + * @details Outputs: none * @return the current target dialIn flow rate (in mL/min). *************************************************************************/ S32 getTargetDialInFlowRate( void ) { - S32 result = targetDialInFlowRate.data; - - if ( OVERRIDE_KEY == targetDialInFlowRate.override ) - { - result = targetDialInFlowRate.ovData; - } - - return result; -} + return targetDialInFlowRate; +} /*********************************************************************//** * @brief * The getMeasuredDialInFlowRate function gets the measured dialIn flow * rate. - * @details - * Inputs : measuredDialInFlowRate - * Outputs : none + * @details Inputs: measuredDialInFlowRate + * @details Outputs: none * @return the current dialIn flow rate (in mL/min). *************************************************************************/ F32 getMeasuredDialInFlowRate( void ) @@ -704,15 +727,34 @@ } return result; -} +} + +/*********************************************************************//** + * @brief + * The getMeasuredDialInFlowSignalStrength function gets the measured dialIn flow + * signal strength. + * @details Inputs: dialInFlowSignalStrength + * @details Outputs: none + * @return the current dialIn flow signal strength (in %). + *************************************************************************/ +F32 getMeasuredDialInFlowSignalStrength( void ) +{ + F32 result = dialInFlowSignalStrength.data; + + if ( OVERRIDE_KEY == dialInFlowSignalStrength.override ) + { + result = dialInFlowSignalStrength.ovData; + } + + return result; +} /*********************************************************************//** * @brief * The getMeasuredDialInPumpRotorSpeed function gets the measured dialIn flow * rate. - * @details - * Inputs : dialInPumpRotorSpeedRPM - * Outputs : none + * @details Inputs: dialInPumpRotorSpeedRPM + * @details Outputs: none * @return the current dialIn flow rate (in mL/min). *************************************************************************/ F32 getMeasuredDialInPumpRotorSpeed( void ) @@ -731,9 +773,8 @@ * @brief * The getMeasuredDialInPumpSpeed function gets the measured dialIn flow * rate. - * @details - * Inputs : dialInPumpSpeedRPM - * Outputs : none + * @details Inputs: dialInPumpSpeedRPM + * @details Outputs: none * @return the current dialIn flow rate (in mL/min). *************************************************************************/ F32 getMeasuredDialInPumpSpeed( void ) @@ -752,9 +793,8 @@ * @brief * The getMeasuredDialInPumpMCSpeed function gets the measured dialIn pump * speed. - * @details - * Inputs : adcDialInPumpMCSpeedRPM - * Outputs : none + * @details Inputs: adcDialInPumpMCSpeedRPM + * @details Outputs: none * @return the current dialIn pump speed (in RPM). *************************************************************************/ F32 getMeasuredDialInPumpMCSpeed( void ) @@ -773,9 +813,8 @@ * @brief * The getMeasuredDialInPumpMCCurrent function gets the measured dialIn pump * current. - * @details - * Inputs : adcDialInPumpMCCurrentmA - * Outputs : none + * @details Inputs: adcDialInPumpMCCurrentmA + * @details Outputs: none * @return the current dialIn pump current (in mA). *************************************************************************/ F32 getMeasuredDialInPumpMCCurrent( void ) @@ -794,25 +833,27 @@ * @brief * The publishDialInFlowData function publishes dialIn flow data at the set * interval. - * @details - * Inputs : target flow rate, measured flow rate, measured MC speed, + * @details Inputs: target flow rate, measured flow rate, measured MC speed, * measured MC current - * Outputs : DialIn flow data is published to CAN bus. + * @details Outputs: DialIn flow data is published to CAN bus. * @return none *************************************************************************/ static void publishDialInFlowData( void ) { // publish dialIn flow data on interval if ( ++dialInFlowDataPublicationTimerCounter >= getPublishDialInFlowDataInterval() ) { - S32 flowStPt = (S32)getTargetDialInFlowRate(); - F32 measFlow = getMeasuredDialInFlowRate(); - F32 measRotSpd = getMeasuredDialInPumpRotorSpeed(); - F32 measSpd = getMeasuredDialInPumpSpeed(); - F32 measMCSpd = getMeasuredDialInPumpMCSpeed(); - F32 measMCCurr = getMeasuredDialInPumpMCCurrent(); - F32 pumpPWMPctDutyCycle = dialInPumpPWMDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR; - broadcastDialInFlowData( flowStPt, measFlow, measRotSpd, measSpd, measMCSpd, measMCCurr, pumpPWMPctDutyCycle ); + DIALIN_PUMP_STATUS_PAYLOAD_T payload; + + payload.setPoint = targetDialInFlowRate; + payload.measFlow = getMeasuredDialInFlowRate(); + payload.measRotorSpd = getMeasuredDialInPumpRotorSpeed(); + payload.measPumpSpd = getMeasuredDialInPumpSpeed(); + payload.measMCSpd = getMeasuredDialInPumpMCSpeed(); + payload.measMCCurr = getMeasuredDialInPumpMCCurrent(); + payload.pwmDC = dialInPumpPWMDutyCyclePctSet * FRACTION_TO_PERCENT_FACTOR; + payload.flowSigStrength = getMeasuredDialInFlowSignalStrength() * FRACTION_TO_PERCENT_FACTOR; + broadcastDialInFlowData( &payload ); dialInFlowDataPublicationTimerCounter = 0; } } @@ -821,9 +862,8 @@ * @brief * The resetDialInFlowMovingAverage function resets the properties of the * dialIn flow moving average sample buffer. - * @details - * Inputs : none - * Outputs : flowReadingsTotal, flowReadingsIdx, flowReadingsCount all set to zero. + * @details Inputs: none + * @details Outputs: flowReadingsTotal, flowReadingsIdx, flowReadingsCount all set to zero. * @return none *************************************************************************/ static void resetDialInFlowMovingAverage( void ) @@ -837,9 +877,8 @@ /*********************************************************************//** * @brief * The filterDialInFlowReadings function adds a new flow sample to the filter. - * @details - * Inputs : none - * Outputs : flowReadings[], flowReadingsIdx, flowReadingsCount, flowReadingsTotal + * @details Inputs: none + * @details Outputs: flowReadings[], flowReadingsIdx, flowReadingsCount, flowReadingsTotal * @return none *************************************************************************/ static void filterDialInFlowReadings( F32 flow ) @@ -864,36 +903,37 @@ * The updateDialInPumpSpeedAndDirectionFromHallSensors function calculates * the dialysate inlet pump motor speed and direction from hall sensor counter on * a 1 second interval. - * @details - * Inputs : dipLastMotorHallSensorCount, dipMotorSpeedCalcTimerCtr, current count from FPGA - * Outputs : dipMotorDirectionFromHallSensors, dialInPumpSpeedRPM + * @details Inputs: dipLastMotorHallSensorCount, dipMotorSpeedCalcTimerCtr, current count from FPGA + * @details Outputs: dipMotorDirectionFromHallSensors, dialInPumpSpeedRPM * @return none *************************************************************************/ static void updateDialInPumpSpeedAndDirectionFromHallSensors( void ) { if ( ++dipMotorSpeedCalcTimerCtr >= DIP_SPEED_CALC_INTERVAL ) { U16 dipMotorHallSensorCount = getFPGADialInPumpHallSensorCount(); - U16 incDelta = ( dipMotorHallSensorCount >= dipLastMotorHallSensorCount ? dipMotorHallSensorCount - dipLastMotorHallSensorCount : ( HEX_64_K - dipLastMotorHallSensorCount ) + dipMotorHallSensorCount ); + U32 nextIdx = INC_WRAP( dipMotorSpeedCalcIdx, 0, DIP_SPEED_CALC_BUFFER_LEN - 1 ); + U16 incDelta = ( dipMotorHallSensorCount >= dipLastMotorHallSensorCounts[ nextIdx ] ? \ + dipMotorHallSensorCount - dipLastMotorHallSensorCounts[ nextIdx ] : \ + ( HEX_64_K - dipLastMotorHallSensorCounts[ nextIdx ] ) + dipMotorHallSensorCount ); U16 decDelta = HEX_64_K - incDelta; U16 delta; // determine dialysate inlet pump speed/direction from delta hall sensor count since last interval if ( incDelta < decDelta ) { - dipMotorDirectionFromHallSensors = MOTOR_DIR_FORWARD; delta = incDelta; dialInPumpSpeedRPM.data = ( (F32)delta / (F32)DIP_HALL_EDGE_COUNTS_PER_REV ) * (F32)SEC_PER_MIN; } else { - dipMotorDirectionFromHallSensors = MOTOR_DIR_REVERSE; delta = decDelta; dialInPumpSpeedRPM.data = ( (F32)delta / (F32)DIP_HALL_EDGE_COUNTS_PER_REV ) * (F32)SEC_PER_MIN * -1.0; } // update last count for next time - dipLastMotorHallSensorCount = dipMotorHallSensorCount; + dipLastMotorHallSensorCounts[ nextIdx ] = dipMotorHallSensorCount; + dipMotorSpeedCalcIdx = nextIdx; dipMotorSpeedCalcTimerCtr = 0; } } @@ -903,9 +943,8 @@ * The checkDialInPumpRotor function checks the rotor for the dialysate inlet * pump. If homing, this function will stop when hall sensor detected. If pump * is off or running very slowly, rotor speed will be set to zero. - * @details - * Inputs : dipStopAtHomePosition, dipHomeStartTime, dipRotorRevStartTime - * Outputs : pump may be stopped if homing, dialInPumpRotorSpeedRPM may be set to zero. + * @details Inputs: dipStopAtHomePosition, dipHomeStartTime, dipRotorRevStartTime + * @details Outputs: pump may be stopped if homing, dialInPumpRotorSpeedRPM may be set to zero. * @return none *************************************************************************/ static void checkDialInPumpRotor( void ) @@ -929,25 +968,47 @@ * @brief * The checkDialInPumpDirection function checks the set direction vs. * the direction implied by the sign of the measured MC speed. - * @details - * Inputs : adcDialInPumpMCSpeedRPM, dialInPumpDirectionSet, dialInPumpState - * Outputs : none + * @details Inputs: adcDialInPumpMCSpeedRPM, dialInPumpDirectionSet, dialInPumpState + * @details Outputs: none * @return none *************************************************************************/ static void checkDialInPumpDirection( void ) { - MOTOR_DIR_T dipMCDir; - if ( DIAL_IN_PUMP_CONTROL_TO_TARGET_STATE == dialInPumpState ) { - // check set direction vs. direction from hall sensors or sign of motor controller speed - dipMCDir = ( getMeasuredDialInPumpMCSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); - if ( ( dialInPumpDirectionSet != dipMCDir ) || ( dialInPumpDirectionSet != dipMotorDirectionFromHallSensors ) ) + MOTOR_DIR_T dipMCDir, dipDir; + + dipMCDir = ( getMeasuredDialInPumpMCSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); + dipDir = ( getMeasuredDialInPumpSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); + + // check set direction vs. direction from hall sensors + if ( dialInPumpDirectionSet != dipDir ) { + if ( ++errorDialInPumpDirectionPersistTimerCtr >= DIP_DIRECTION_ERROR_PERSIST ) + { #ifndef DISABLE_PUMP_DIRECTION_CHECKS - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DIAL_IN_PUMP_MC_DIRECTION_CHECK, (U32)dialInPumpDirectionSet, (U32)dipMotorDirectionFromHallSensors ) -#endif + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DIAL_IN_PUMP_MC_DIRECTION_CHECK, (U32)dialInPumpDirectionSet, (U32)dipDir ) +#endif + } } + // check set direction vs. direction from sign of motor controller speed + else if ( dialInPumpDirectionSet != dipMCDir ) + { + if ( ++errorDialInPumpDirectionPersistTimerCtr >= DIP_DIRECTION_ERROR_PERSIST ) + { +#ifndef DISABLE_PUMP_DIRECTION_CHECKS + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DIAL_IN_PUMP_MC_DIRECTION_CHECK, (U32)dialInPumpDirectionSet, (U32)dipMCDir ) +#endif + } + } + else + { + errorDialInPumpDirectionPersistTimerCtr = 0; + } + } + else + { + errorDialInPumpDirectionPersistTimerCtr = 0; } } @@ -959,15 +1020,14 @@ * 2. while pump is controlling, measured motor speed should be within allowed range of commanded speed. * 3. measured motor speed should be within allowed range of measured rotor speed. * All 3 checks have a persistence time that must be met before an alarm is triggered. - * @details - * Inputs : targetDialInFlowRate, dialInPumpSpeedRPM, dialInPumpRotorSpeedRPM - * Outputs : alarm(s) may be triggered + * @details Inputs: targetDialInFlowRate, dialInPumpSpeedRPM, dialInPumpRotorSpeedRPM + * @details Outputs: alarm(s) may be triggered * @return none *************************************************************************/ static void checkDialInPumpSpeeds( void ) { F32 measMotorSpeed = getMeasuredDialInPumpSpeed(); - S32 cmdRate = getTargetDialInFlowRate(); + S32 cmdRate = targetDialInFlowRate; // check for pump running while commanded off if ( 0 == cmdRate ) @@ -978,6 +1038,7 @@ { #ifndef DISABLE_PUMP_SPEED_CHECKS SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DIAL_IN_PUMP_OFF_CHECK, measMotorSpeed ); + activateSafetyShutdown(); #endif } } @@ -1043,9 +1104,8 @@ * against the implied flow of the measured pump speed when in treatment mode * and controlling to target flow. If a sufficient difference persists, a * flow vs. motor speed check error is triggered. - * @details - * Inputs : measuredDialInFlowRate, dialInPumpSpeedRPM, errorDialInFlowVsMotorSpeedPersistTimerCtr - * Outputs : alarm may be triggered + * @details Inputs: measuredDialInFlowRate, dialInPumpSpeedRPM, errorDialInFlowVsMotorSpeedPersistTimerCtr + * @details Outputs: alarm may be triggered * @return none *************************************************************************/ static void checkDialInPumpFlowAgainstSpeed( void ) @@ -1055,15 +1115,15 @@ { F32 flow = getMeasuredDialInFlowRate(); F32 speed = getMeasuredDialInPumpSpeed(); - F32 impliedFlow = ( ( speed / DIP_GEAR_RATIO ) / DIP_REV_PER_LITER ) * (F32)ML_PER_LITER; - F32 delta = fabs( flow - impliedFlow ); + F32 impliedSpeed = ( flow / (F32)ML_PER_LITER ) * DIP_REV_PER_LITER * DIP_GEAR_RATIO; + F32 delta = fabs( speed - impliedSpeed ); - if ( delta > DIP_MAX_FLOW_VS_SPEED_DIFF_ML_MIN ) + if ( delta > DIP_MAX_FLOW_VS_SPEED_DIFF_RPM ) { if ( ++errorDialInFlowVsMotorSpeedPersistTimerCtr >= DIP_FLOW_VS_SPEED_PERSIST ) { #ifndef DISABLE_PUMP_FLOW_CHECKS - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIAL_IN_PUMP_FLOW_VS_MOTOR_SPEED_CHECK, flow, impliedFlow ); + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIAL_IN_PUMP_FLOW_VS_MOTOR_SPEED_CHECK, flow, speed ); #endif } } @@ -1082,9 +1142,8 @@ * @brief * The checkDialInPumpMCCurrent function checks the measured MC current vs. * the set state of the dialIn pump (stopped or running). - * @details - * Inputs : dialInPumpState, dipCurrErrorDurationCtr, adcDialInPumpMCCurrentmA - * Outputs : none + * @details Inputs: dialInPumpState, dipCurrErrorDurationCtr, adcDialInPumpMCCurrentmA + * @details Outputs: none * @return none *************************************************************************/ static void checkDialInPumpMCCurrent( void ) @@ -1129,15 +1188,38 @@ dipCurrErrorDurationCtr = 0; } } +} + +/*********************************************************************//** + * @brief + * The checkDialInFlowSensorSignalStrength function checks the measured + * dialysate flow sensor signal strength is sufficient for accurate flow sensing. + * @details Inputs: + * @details Outputs: + * @return none + *************************************************************************/ +static void checkDialInFlowSensorSignalStrength( void ) +{ +#ifndef DISABLE_PUMP_FLOW_CHECKS + HD_OP_MODE_T opMode = getCurrentOperationMode(); + + // check flow sensor signal strength when appropriate TODO - in pre-treatment, must be far enough along for fluid to be in tubing + if ( MODE_TREA == opMode || ( MODE_PRET == opMode && FALSE ) ) + { + F32 sigStrength = getMeasuredDialInFlowSignalStrength(); + BOOL outOfRange = ( sigStrength < MIN_FLOW_SIG_STRENGTH ? TRUE : FALSE ); + + checkPersistentAlarm( PERSISTENT_ALARM_DIALYSATE_FLOW_SIGNAL_STRENGTH, outOfRange, sigStrength, MIN_FLOW_SIG_STRENGTH ); + } +#endif } /*********************************************************************//** * @brief * The execDialInFlowTest function executes the state machine for the * DialInFlow self-test. - * @details - * Inputs : none - * Outputs : none + * @details Inputs: none + * @details Outputs: none * @return the current state of the DialInFlow self-test. *************************************************************************/ SELF_TEST_STATUS_T execDialInFlowTest( void ) @@ -1182,9 +1264,8 @@ * @brief * The setDialInFlowCalibration function sets the dialysate flow calibration * factors and has them stored in non-volatile memory. - * @details - * Inputs : none - * Outputs : dialInFlowCalGain, dialInFlowCalOffset + * @details Inputs: none + * @details Outputs: dialInFlowCalGain, dialInFlowCalOffset * @param gain gain calibration factor for dialysate flow sensor * @param offset offset calibration factor for dialysate flow sensor * @return TRUE if calibration factors successfully set/stored, FALSE if not @@ -1217,9 +1298,8 @@ * @brief * The getDialInFlowCalibration function retrieves the current dialysate flow * calibration factors. - * @details - * Inputs : dialInFlowCalGain, dialInFlowCalOffset - * Outputs : none + * @details Inputs: dialInFlowCalGain, dialInFlowCalOffset + * @details Outputs: none * @param gain value to populate with gain calibration factor for dialysate flow sensor * @param offset value to populate with offset calibration factor for dialysate flow sensor * @return none @@ -1234,9 +1314,8 @@ * @brief * The testSetDialInFlowDataPublishIntervalOverride function overrides the * dialIn flow data publish interval. - * @details - * Inputs : none - * Outputs : dialInFlowDataPublishInterval + * @details Inputs: none + * @details Outputs: dialInFlowDataPublishInterval * @param value override dialIn flow data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -1260,9 +1339,8 @@ * @brief * The testResetDialInFlowDataPublishIntervalOverride function resets the override * of the dialIn flow data publish interval. - * @details - * Inputs : none - * Outputs : dialInFlowDataPublishInterval + * @details Inputs: none + * @details Outputs: dialInFlowDataPublishInterval * @return TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetDialInFlowDataPublishIntervalOverride( void ) @@ -1283,9 +1361,8 @@ * @brief * The testSetTargetDialInFlowRateOverride function overrides the target * dialysate inlet flow rate.n - * @details - * Inputs : none - * Outputs : targetDialInFlowRate + * @details Inputs: none + * @details Outputs: targetDialInFlowRate * @param value override target dialysate inlet flow rate (in mL/min) * @param ctrlMode override pump control mode to this mode (0 = closed loop, 1 = open loop) * @return TRUE if override successful, FALSE if not @@ -1308,9 +1385,7 @@ } if ( ctrlMode < NUM_OF_PUMP_CONTROL_MODES ) { - targetDialInFlowRate.ovInitData = targetDialInFlowRate.data; // backup current target flow rate - targetDialInFlowRate.ovData = value; - targetDialInFlowRate.override = OVERRIDE_KEY; + targetDialInFlowRate = value; result = setDialInPumpTargetFlowRate( abs(value), dir, (PUMP_CONTROL_MODE_T)ctrlMode ); } } @@ -1320,36 +1395,10 @@ /*********************************************************************//** * @brief - * The testResetTargetDialInFlowRateOverride function resets the override of the - * target dialysate inlet flow rate. - * @details - * Inputs : none - * Outputs : targetDialInFlowRate - * @return TRUE if override reset successful, FALSE if not - *************************************************************************/ -BOOL testResetTargetDialInFlowRateOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - targetDialInFlowRate.data = targetDialInFlowRate.ovInitData; // restore pre-override target flow rate - targetDialInFlowRate.override = OVERRIDE_RESET; - targetDialInFlowRate.ovInitData = 0; - targetDialInFlowRate.ovData = 0; - result = setDialInPumpTargetFlowRate( targetDialInFlowRate.data, dialInPumpDirection, dialInPumpControlMode ); - } - - return result; -} - -/*********************************************************************//** - * @brief * The testResetMeasuredDialInFlowRateOverride function overrides the measured * dialIn flow rate. - * @details - * Inputs : none - * Outputs : measuredDialInFlowRate + * @details Inputs: none + * @details Outputs: measuredDialInFlowRate * @param value override measured dialIn flow rate (in mL/min) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -1371,9 +1420,8 @@ * @brief * The testResetMeasuredDialInFlowRateOverride function resets the override of the * measured dialIn flow rate. - * @details - * Inputs : none - * Outputs : measuredDialInFlowRate + * @details Inputs: none + * @details Outputs: measuredDialInFlowRate * @return TRUE if reset successful, FALSE if not *************************************************************************/ BOOL testResetMeasuredDialInFlowRateOverride( void ) @@ -1394,9 +1442,8 @@ * @brief * The testSetMeasuredDialInPumpRotorSpeedOverride function overrides the measured * dialIn pump rotor speed. - * @details - * Inputs : none - * Outputs : dialInPumpRotorSpeedRPM + * @details Inputs: none + * @details Outputs: dialInPumpRotorSpeedRPM * @param value override measured dialIn pump rotor speed (in RPM) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -1418,9 +1465,8 @@ * @brief * The testResetMeasuredDialInPumpRotorSpeedOverride function resets the override of the * measured dialIn pump rotor speed. - * @details - * Inputs : none - * Outputs : dialInPumpRotorSpeedRPM + * @details Inputs: none + * @details Outputs: dialInPumpRotorSpeedRPM * @return TRUE if reset successful, FALSE if not *************************************************************************/ BOOL testResetMeasuredDialInPumpRotorSpeedOverride( void ) @@ -1441,9 +1487,8 @@ * @brief * The testSetMeasuredDialInPumpSpeedOverride function overrides the measured * dialIn pump motor speed. - * @details - * Inputs : none - * Outputs : dialInPumpSpeedRPM + * @details Inputs: none + * @details Outputs: dialInPumpSpeedRPM * @param value override measured dialIn pump motor speed (in RPM) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -1465,9 +1510,8 @@ * @brief * The testResetMeasuredDialInPumpSpeedOverride function resets the override of the * measured dialIn pump motor speed. - * @details - * Inputs : none - * Outputs : dialInPumpSpeedRPM + * @details Inputs: none + * @details Outputs: dialInPumpSpeedRPM * @return TRUE if reset successful, FALSE if not *************************************************************************/ BOOL testResetMeasuredDialInPumpSpeedOverride( void ) @@ -1488,9 +1532,8 @@ * @brief * The testSetMeasuredDialInPumpMCSpeedOverride function overrides the measured * dialIn pump motor speed. - * @details - * Inputs : none - * Outputs : adcDialInPumpMCSpeedRPM + * @details Inputs: none + * @details Outputs: adcDialInPumpMCSpeedRPM * @param value override measured dialIn pump speed (in RPM) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -1512,9 +1555,8 @@ * @brief * The testResetMeasuredDialInPumpMCSpeedOverride function resets the override of the * measured dialIn pump motor speed. - * @details - * Inputs : none - * Outputs : adcDialInPumpMCSpeedRPM + * @details Inputs: none + * @details Outputs: adcDialInPumpMCSpeedRPM * @return TRUE if reset successful, FALSE if not *************************************************************************/ BOOL testResetMeasuredDialInPumpMCSpeedOverride( void ) @@ -1535,9 +1577,8 @@ * @brief * The testSetMeasuredDialInPumpMCCurrentOverride function overrides the measured * dialIn pump motor current. - * @details - * Inputs : none - * Outputs : adcDialInPumpMCCurrentmA + * @details Inputs: none + * @details Outputs: adcDialInPumpMCCurrentmA * @param value override measured dialIn pump current (in mA) * @return TRUE if override successful, FALSE if not *************************************************************************/ @@ -1559,9 +1600,8 @@ * @brief * The testResetMeasuredDialInPumpMCCurrentOverride function resets the override of the * measured dialIn pump motor current. - * @details - * Inputs : none - * Outputs : adcDialInPumpMCCurrentmA + * @details Inputs: none + * @details Outputs: adcDialInPumpMCCurrentmA * @return TRUE if reset successful, FALSE if not *************************************************************************/ BOOL testResetMeasuredDialInPumpMCCurrentOverride( void ) @@ -1577,5 +1617,50 @@ return result; } + +/*********************************************************************//** + * @brief + * The testSetMeasuredDialInFlowSignalStrengthOverride function overrides the measured + * dialysate flow signal strength. + * @details Inputs: none + * @details Outputs: dialInFlowSignalStrength + * @param value override measured dialysate flow signal strength (in %) + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testSetMeasuredDialInFlowSignalStrengthOverride( F32 value ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + dialInFlowSignalStrength.ovData = value / 100.0; + dialInFlowSignalStrength.override = OVERRIDE_KEY; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testResetMeasuredDialInFlowSignalStrengthOverride function resets the override + * of the measured dialysate flow signal strength. + * @details Inputs: none + * @details Outputs: dialInFlowSignalStrength + * @return TRUE if reset successful, FALSE if not + *************************************************************************/ +BOOL testResetMeasuredDialInFlowSignalStrengthOverride( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + result = TRUE; + dialInFlowSignalStrength.override = OVERRIDE_RESET; + dialInFlowSignalStrength.ovData = dialInFlowSignalStrength.ovInitData; + } + + return result; +} /**@}*/