Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r5bfaf341319b9fd763d07ad0a68a986028c37587 -rf7cdfd3256f195cd8aa06e28009cd5f26b50f08c --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 5bfaf341319b9fd763d07ad0a68a986028c37587) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision f7cdfd3256f195cd8aa06e28009cd5f26b50f08c) @@ -7,8 +7,8 @@ * * @file BloodFlow.c * -* @author (last) Dara Navaei -* @date (last) 06-Nov-2021 +* @author (last) Sean Nash +* @date (last) 15-Nov-2021 * * @author (original) Sean Nash * @date (original) 07-Nov-2019 @@ -50,18 +50,23 @@ #define MIN_BLOOD_PUMP_PWM_DUTY_CYCLE 0.10 ///< Controller will error if PWM duty cycle < 10%, so set min to 10% #define BP_CONTROL_INTERVAL_SEC 10 ///< Blood pump control interval (in seconds). + /// Interval (ms/task time) at which the blood pump is controlled. -static const U32 BP_CONTROL_INTERVAL = ( BP_CONTROL_INTERVAL_SEC * MS_PER_SECOND / TASK_GENERAL_INTERVAL ); +static const U32 BP_CONTROL_INTERVAL = ( BP_CONTROL_INTERVAL_SEC * MS_PER_SECOND / TASK_GENERAL_INTERVAL ); + #define BP_P_COEFFICIENT 0.0001 ///< P term for blood pump control #define BP_I_COEFFICIENT 0.00075 ///< I term for blood pump control #define BP_HOME_RATE 100 ///< Target pump speed (in estimate mL/min) for homing. #define BP_HOME_TIMEOUT_MS 10000 ///< Maximum time (in ms) allowed for homing to complete. -#define BP_MAX_ROTOR_HALL_INTERVAL_MS 20000 ///< Maximum time (in ms) allowed between rotor hall sensor detects (50 mL/min worst case). +#define BP_MAX_ROTOR_HALL_INTERVAL_MS 20000 ///< Maximum time (in ms) allowed between rotor hall sensor detects (50 mL/min worst case). + /// Interval (ms/task time) at which the blood pump speed is calculated (every 40 ms). -#define BP_SPEED_CALC_INTERVAL ( 40 / TASK_PRIORITY_INTERVAL ) +#define BP_SPEED_CALC_INTERVAL ( 40 / TASK_PRIORITY_INTERVAL ) + /// Number of hall sensor counts kept in buffer to hold last 1 second of count data. #define BP_SPEED_CALC_BUFFER_LEN ( MS_PER_SECOND / BP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) + #define BP_MAX_ROTOR_SPEED_RPM 100.0 ///< Maximum rotor speed allowed for blood pump. #define BP_MAX_FLOW_RATE 1320.0 ///< Maximum measured BP flow rate allowed. @@ -98,7 +103,8 @@ #define BP_ML_PER_ROTOR_REV 6.81 ///< Milliliters per rotor revolusion. #define BP_ML_PER_MIN_TO_PUMP_RPM_FACTOR ( BP_REV_PER_LITER / ML_PER_LITER ) ///< Conversion factor from mL/min to motor RPM. #define BP_GEAR_RATIO 32.0 ///< Blood pump motor to blood pump gear ratio. -#define BP_PWM_ZERO_OFFSET 0.1 ///< 10% PWM duty cycle = zero speed. +#define BP_PWM_ZERO_OFFSET 0.1 ///< 10 pct PWM duty cycle = zero speed. + /// Conversion macro from mL/min to estimated PWM duty cycle %. #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 from PWM duty cycle % to commanded pump motor speed. @@ -374,7 +380,7 @@ * hall sensor detection. Calculates rotor speed (in RPM). Stops pump if * there is a pending request to home the pump. * @details Inputs: bpRotorRevStartTime, bpStopAtHomePosition - * @details Outputs: bpRotorRevStartTime, bloodPumpRotorSpeedRPM + * @details Outputs: bpRotorRevStartTime, bloodPumpRotorSpeedRPM, bloodPumpRotorCounter * @return none *************************************************************************/ void signalBloodPumpRotorHallSensor( void ) @@ -759,6 +765,18 @@ SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_BLOOD_FLOW_INVALID_BLOOD_PUMP_DIRECTION, dir ) break; } +} + +/*********************************************************************//** + * @brief + * The getTargetBloodFlowRate function gets the target blood flow rate. + * @details Inputs: targetBloodFlowRate + * @details Outputs: none + * @return the current target blood flow rate (in mL/min). + *************************************************************************/ +S32 getTargetBloodFlowRate( void ) +{ + return targetBloodFlowRate; } /*********************************************************************//** @@ -1121,8 +1139,8 @@ * @brief * The checkBloodPumpMCCurrent function checks the measured MC current vs. * the set state of the blood pump (stopped or running). - * @details Inputs: - * @details Outputs: + * @details Inputs: BP motor controller measured current. + * @details Outputs: Alarm triggered it current too high. * @return none *************************************************************************/ static void checkBloodPumpMCCurrent( void )