Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -rf9b8b75c3686be892799b5446b955fd36ab49fa3 -r8377b4e6ed494cbfc5dfc2bd9ad3c89b85b333cd --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision f9b8b75c3686be892799b5446b955fd36ab49fa3) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 8377b4e6ed494cbfc5dfc2bd9ad3c89b85b333cd) @@ -51,7 +51,7 @@ #define BP_HOME_RATE 50 ///< target pump speed (in estimate mL/min) for homing. #define BP_HOME_TIMEOUT_MS 10000 ///< maximum time allowed for homing to complete (in ms). #define BP_SPEED_CALC_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< interval (ms/task time) at which the blood pump speed is calculated. -#define BP_HALL_EDGE_COUNTS_PER_REV 6 ///< number of hall sensor edge counts per motor revolution. +#define BP_HALL_EDGE_COUNTS_PER_REV 48 ///< number of hall sensor edge counts per motor revolution. #define BP_MAX_CURR_WHEN_STOPPED_MA 150.0 ///< motor controller current should not exceed this when pump should be stopped #define BP_MIN_CURR_WHEN_RUNNING_MA 150.0 ///< motor controller current should always exceed this when pump should be running @@ -69,8 +69,8 @@ #define BP_PWM_FROM_ML_PER_MIN(rate) ( (rate) * BP_ML_PER_MIN_TO_PUMP_RPM_FACTOR * BP_GEAR_RATIO * BP_MOTOR_RPM_TO_PWM_DC_FACTOR + BP_PWM_ZERO_OFFSET ) ///< conversion factor from mL/min to estimated PWM duty cycle %. #define BLOODPUMP_ADC_FULL_SCALE_V 3.0 ///< BP analog signals are 0-3V (while int. ADC ref may be different) -#define BLOODPUMP_ADC_ZERO ( (F32)( INT_ADC_ZERO ) * ( BLOODPUMP_ADC_FULL_SCALE_V / INT_ADC_REF_V ) ) ///< Blood pump ADC channel zero offset. -#define SIGN_FROM_12_BIT_VALUE(v) ( (S16)(v) - (S16)BLOODPUMP_ADC_ZERO ) ///< macro converts 12 bit ADC value to signed 16-bit value. +#define BLOODPUMP_ADC_ZERO 1998 ///< Blood pump ADC channel zero offset. +#define SIGN_FROM_12_BIT_VALUE(v) ( (S16)(v) - (S16)BLOODPUMP_ADC_ZERO ) ///< macro converts 12 bit ADC value to signed 16-bit value. #define BLOOD_FLOW_SAMPLE_FREQ ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Blood flow sample frequency (in task intervals). #define SIZE_OF_ROLLING_AVG ( BLOOD_FLOW_SAMPLE_FREQ * 2 ) ///< measured blood flow is filtered w/ moving average @@ -166,6 +166,8 @@ static void updateBloodPumpSpeedAndDirectionFromHallSensors( void ); static void checkBloodPumpRotor( void ); static void checkBloodPumpDirection( void ); +static void checkBloodPumpSpeeds( void ); +static void checkBloodPumpFlowAgainstSpeed( void ); static void checkBloodPumpMCCurrent( void ); static DATA_GET_PROTOTYPE( U32, getPublishBloodFlowDataInterval ); @@ -179,6 +181,8 @@ *************************************************************************/ void initBloodFlow( void ) { + bpLastMotorHallSensorCount = getFPGABloodPumpHallSensorCount(); + stopBloodPump(); setBloodPumpDirection( MOTOR_DIR_FORWARD ); @@ -348,6 +352,10 @@ // calculate blood pump motor speed/direction from hall sensor count updateBloodPumpSpeedAndDirectionFromHallSensors(); + // check pump speeds and flow + checkBloodPumpSpeeds(); + checkBloodPumpFlowAgainstSpeed(); + // check for home position, zero/low speed checkBloodPumpRotor(); @@ -978,15 +986,29 @@ if ( BLOOD_PUMP_CONTROL_TO_TARGET_STATE == bloodPumpState ) { - // 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 bpMCDir = ( getMeasuredBloodPumpMCSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); - if ( bloodPumpDirectionSet != bpMCDir ) + if ( ( bloodPumpDirectionSet != bpMCDir ) || ( bloodPumpDirectionSet != bpMotorDirectionFromHallSensors ) ) { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_BLOOD_PUMP_MC_DIRECTION_CHECK, (U32)bloodPumpDirectionSet, (U32)bpMCDir ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_BLOOD_PUMP_MC_DIRECTION_CHECK, (U32)bloodPumpDirectionSet, (U32)bpMotorDirectionFromHallSensors ) } } } +static void checkBloodPumpSpeeds( void ) +{ + +} + +static void checkBloodPumpFlowAgainstSpeed( void ) +{ + +} +//ALARM_ID_BLOOD_PUMP_OFF_CHECK = 7, ///< Blood pump failed motor controller off check. +//ALARM_ID_BLOOD_PUMP_ROTOR_SPEED_CHECK = 9, ///< Blood pump failed rotor speed check. Mismatch with rotor and motor speeds. +//ALARM_ID_BLOOD_PUMP_FLOW_VS_MOTOR_SPEED_CHECK = 51, ///< Blood pump failed flow vs. motor speed check. Mismatch with flow rate and rate implied by motor speed. +//ALARM_ID_BLOOD_PUMP_MOTOR_SPEED_CHECK = 54, ///< Blood pump failed motor speed check. Measured vs. commanded. + /*********************************************************************//** * @brief * The checkBloodPumpMCCurrent function checks the measured MC current vs. \n