Index: firmware/App/Controllers/DialInFlow.c =================================================================== diff -u -rf9b8b75c3686be892799b5446b955fd36ab49fa3 -r8377b4e6ed494cbfc5dfc2bd9ad3c89b85b333cd --- firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision f9b8b75c3686be892799b5446b955fd36ab49fa3) +++ firmware/App/Controllers/DialInFlow.c (.../DialInFlow.c) (revision 8377b4e6ed494cbfc5dfc2bd9ad3c89b85b333cd) @@ -52,7 +52,7 @@ #define DIP_HOME_RATE 50 ///< 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. -#define DIP_HALL_EDGE_COUNTS_PER_REV 6 ///< number of hall sensor edge counts per motor revolution. +#define DIP_HALL_EDGE_COUNTS_PER_REV 48 ///< number of hall sensor edge counts per motor revolution. #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 @@ -70,8 +70,8 @@ #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_ZERO ( (F32)( INT_ADC_ZERO ) * ( DIAL_IN_PUMP_ADC_FULL_SCALE_V / INT_ADC_REF_V ) ) ///> -#define SIGN_FROM_12_BIT_VALUE(v) ( (S16)(v) - (S16)DIAL_IN_PUMP_ADC_ZERO ) ///> +#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 DIAL_IN_FLOW_SAMPLE_FREQ ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///> #define SIZE_OF_ROLLING_AVG ( DIAL_IN_FLOW_SAMPLE_FREQ * 2 ) ///> measured dialIn flow is filtered w/ moving average @@ -167,6 +167,8 @@ static void updateDialInPumpSpeedAndDirectionFromHallSensors( void ); static void checkDialInPumpRotor( void ); static void checkDialInPumpDirection( void ); +static void checkDialInPumpSpeeds( void ); +static void checkDialInPumpFlowAgainstSpeed( void ); static void checkDialInPumpMCCurrent( void ); static DATA_GET_PROTOTYPE( U32, getPublishDialInFlowDataInterval ); @@ -180,6 +182,8 @@ *************************************************************************/ void initDialInFlow( void ) { + dipLastMotorHallSensorCount = getFPGADialInPumpHallSensorCount(); + stopDialInPump(); setDialInPumpDirection( MOTOR_DIR_FORWARD ); @@ -349,6 +353,10 @@ // calculate dialysate inlet pump motor speed/direction from hall sensor count updateDialInPumpSpeedAndDirectionFromHallSensors(); + // check pump speeds and flow + checkDialInPumpSpeeds(); + checkDialInPumpFlowAgainstSpeed(); + // check for home position, zero/low speed checkDialInPumpRotor(); @@ -899,15 +907,25 @@ if ( DIAL_IN_PUMP_CONTROL_TO_TARGET_STATE == dialInPumpState ) { - // check set direction vs. direction from sign of motor controller speed + // 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 ) + if ( ( dialInPumpDirectionSet != dipMCDir ) || ( dialInPumpDirectionSet != dipMotorDirectionFromHallSensors ) ) { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DIAL_IN_PUMP_MC_DIRECTION_CHECK, (U32)dialInPumpDirectionSet, (U32)dipMCDir ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DIAL_IN_PUMP_MC_DIRECTION_CHECK, (U32)dialInPumpDirectionSet, (U32)dipMotorDirectionFromHallSensors ) } } } +static void checkDialInPumpSpeeds( void ) +{ + +} + +static void checkDialInPumpFlowAgainstSpeed( void ) +{ + +} + /*********************************************************************//** * @brief * The checkDialInPumpMCCurrent function checks the measured MC current vs. \n