Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -re5c6383e93940c2722d3bf73beb1d13a6d3eae6e -ra56db4650fe5652d633e0c51b29da32d5d708608 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision e5c6383e93940c2722d3bf73beb1d13a6d3eae6e) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision a56db4650fe5652d633e0c51b29da32d5d708608) @@ -7,8 +7,8 @@ * * @file BloodFlow.c * -* @author (last) Dara Navaei -* @date (last) 08-May-2023 +* @author (last) Sean Nash +* @date (last) 10-Aug-2023 * * @author (original) Sean Nash * @date (original) 07-Nov-2019 @@ -19,9 +19,11 @@ #include "can.h" #include "etpwm.h" +#include "gio.h" +#include "reg_het.h" -#include "Battery.h" #include "BloodFlow.h" +#include "CPLD.h" #include "FPGA.h" #include "InternalADC.h" #include "NVDataMgmt.h" @@ -45,9 +47,11 @@ /// Interval (ms/task time) at which the blood flow data is published on the CAN bus. #define BLOOD_FLOW_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) +#define MAX_SETTABLE_BLOOD_FLOW_RATE 700 ///< Maximum settable blood flow rate (in mL/min). + #define MAX_BLOOD_PUMP_PWM_STEP_UP_CHANGE 0.008F ///< Max duty cycle change when ramping up ~ 100 mL/min/s. #define MAX_BLOOD_PUMP_PWM_STEP_DN_CHANGE 0.016F ///< Max duty cycle change when ramping down ~ 200 mL/min/s. -#define MAX_BLOOD_PUMP_PWM_DUTY_CYCLE 0.89F ///< Controller will error if PWM duty cycle > 90%, so set max to 89% +#define MAX_BLOOD_PUMP_PWM_DUTY_CYCLE 0.90F ///< Controller will error if PWM duty cycle > 90%, so set max to 89% #define MIN_BLOOD_PUMP_PWM_DUTY_CYCLE 0.10F ///< 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). @@ -73,7 +77,7 @@ #define BP_MAX_FLOW_RATE 1320.0F ///< Maximum measured BP flow rate allowed. #define BP_MIN_FLOW_RATE -1320.0F ///< Minimum measured BP flow rate allowed. #define BP_MAX_MOTOR_SPEED_WHILE_OFF_RPM 100.0F ///< Maximum motor speed (RPM) while motor is commanded off. -#define BP_MAX_ROTOR_VS_MOTOR_DIFF_RPM 2.0F ///< Maximum difference in speed between motor and rotor (in rotor RPM). +#define BP_MAX_ROTOR_VS_MOTOR_DIFF_RPM 5.0F ///< Maximum difference in speed between motor and rotor (in rotor RPM). #define BP_MAX_MOTOR_SPEED_ERROR_RPM 300.0F ///< Maximum difference in speed between measured and commanded RPM. #define BP_MAX_MOTOR_SPEED_VS_TRGT_DIFF_PCT 0.15F ///< Maximum motor speed vs target difference in percent. @@ -124,9 +128,9 @@ #define BP_COMMUTATION_ERROR_MAX_CNT 3 ///< Maximum number of commutation errors within time window before alarm triggered. #define BP_COMMUTATION_ERROR_TIME_WIN_MS (15 * MS_PER_SECOND) ///< Time window for BP commutation error. -#define BP_FLOW_ALPHA_Y_INTERCEPT 1.1970F ///< Y intercept used for alpha flow coefficient calculation. -#define BP_FLOW_WEAR_A_TERM 0.000000029F ///< A term used for wear portion of alpha flow coefficient. -#define BP_FLOW_WEAR_B_TERM 0.00055F ///< B term used for wear portion of alpha flow coefficient. +#define BP_FLOW_ALPHA_Y_INTERCEPT 1.11F ///< Y intercept used for alpha flow coefficient calculation. +#define BP_FLOW_WEAR_A_TERM 0.00000000896F ///< A term used for wear portion of alpha flow coefficient. +#define BP_FLOW_WEAR_B_TERM 0.000550F ///< B term used for wear portion of alpha flow coefficient. #define BP_MAX_ROTOR_COUNT_FOR_WEAR 25000 ///< Maximum rotor count for determining wear of the cartridge (negligible affect beyond this threshold). #define DATA_PUBLISH_COUNTER_START_COUNT 20 ///< Data publish counter start count. @@ -149,14 +153,15 @@ NUM_OF_BLOOD_FLOW_SELF_TEST_STATES ///< Number of blood pump self-test states } BLOOD_FLOW_SELF_TEST_STATE_T; -// Pin assignments for pump stop and direction outputs -#define STOP_CAN3_PORT_MASK 0x00000002 // (Tx - re-purposed as output GPIO for blood pump stop signal) -#define DIR_CAN3_PORT_MASK 0x00000002 // (Rx - re-purposed as output GPIO for blood pump direction signal) +// Pin assignments for pump stop and direction outputs and rotor hall sensor input +#define STOP_CAN3_PORT_MASK 0x00000002 ///< (Tx - re-purposed as output GPIO for blood pump stop signal) +#define DIR_CAN3_PORT_MASK 0x00000002 ///< (Rx - re-purposed as output GPIO for blood pump direction signal) +#define BP_ROTOR_HALL_SENSOR_NHET_ID 0x0000000C ///< NHET pin number associated with BP rotor hall sensor input // Blood pump stop and direction macros -#define SET_BP_DIR() {canREG3->RIOC |= DIR_CAN3_PORT_MASK;} // Macro to set blood pump direction signal high. -#define CLR_BP_DIR() {canREG3->RIOC &= ~DIR_CAN3_PORT_MASK;} // Macro to set blood pump direction signal low. -#define SET_BP_STOP() {canREG3->TIOC &= ~STOP_CAN3_PORT_MASK;} // Macro to set blood pump stop signal (active low). -#define CLR_BP_STOP() {canREG3->TIOC |= STOP_CAN3_PORT_MASK;} // Macro to clear blood pump stop signal (active low). +#define SET_BP_DIR() {canREG3->RIOC |= DIR_CAN3_PORT_MASK;} ///< Macro to set blood pump direction signal high. +#define CLR_BP_DIR() {canREG3->RIOC &= ~DIR_CAN3_PORT_MASK;} ///< Macro to set blood pump direction signal low. +#define SET_BP_STOP() {canREG3->TIOC &= ~STOP_CAN3_PORT_MASK;} ///< Macro to set blood pump stop signal (active low). +#define CLR_BP_STOP() {canREG3->TIOC |= STOP_CAN3_PORT_MASK;} ///< Macro to clear blood pump stop signal (active low). // ********** private data ********** @@ -286,7 +291,7 @@ // Don't interrupt pump control unless rate or mode is changing if ( ( dirFlowRate != targetBloodFlowRate ) || ( mode != bloodPumpControlMode ) ) { - BOOL isFlowInrange = ( flowRate <= MAX_SET_BLOOD_FLOW_RATE ? TRUE : FALSE ); + BOOL isFlowInrange = ( flowRate <= MAX_SETTABLE_BLOOD_FLOW_RATE ? TRUE : FALSE ); #ifndef _RELEASE_ if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_PUMPS_FLOW_LIMITS ) ) @@ -303,6 +308,7 @@ bloodPumpControlMode = 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 bloodPumpPWMDutyCyclePct = BP_PWM_FROM_ML_PER_MIN((F32)flowRate); // ~ 8% per 100 mL/min with a 10% zero offset added in (e.g. 100 mL/min = 8+10 = 18%) + bloodPumpPWMDutyCyclePct = RANGE( bloodPumpPWMDutyCyclePct, MIN_BLOOD_PUMP_PWM_DUTY_CYCLE, MAX_BLOOD_PUMP_PWM_DUTY_CYCLE ); switch ( bloodPumpState ) { @@ -960,6 +966,7 @@ { BLOOD_PUMP_STATUS_PAYLOAD_T payload; HD_OP_MODE_T opMode = getCurrentOperationMode(); + U32 hallSensor = gioGetBit( hetPORT1, BP_ROTOR_HALL_SENSOR_NHET_ID ); payload.setPoint = targetBloodFlowRate; payload.measFlow = getMeasuredBloodFlowRate(); @@ -977,6 +984,7 @@ { payload.presFlow = 0; } + payload.rotorHall = ( hallSensor > 0 ? 0 : 1 ); // 1=home, 0=not home broadcastData( MSG_ID_BLOOD_FLOW_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&payload, sizeof( BLOOD_PUMP_STATUS_PAYLOAD_T ) ); bloodFlowDataPublicationTimerCounter = 0; } @@ -1114,7 +1122,7 @@ BOOL isDirIncorrect; U08 dirErrorCnt = getFPGABloodPumpHallSensorStatus() & PUMP_DIR_ERROR_COUNT_MASK; F32 measMCSpeed = getMeasuredBloodPumpMCSpeed(); - BOOL minDirSpeed = ( measMCSpeed >= BP_MIN_DIR_CHECK_SPEED_RPM ? TRUE : FALSE ); + BOOL minDirSpeed = ( fabs( measMCSpeed ) >= BP_MIN_DIR_CHECK_SPEED_RPM ? TRUE : FALSE ); BOOL isHallSensorFailed = ( TRUE == minDirSpeed && lastBloodPumpDirectionCount != dirErrorCnt ? TRUE : FALSE ); // Check pump direction error count @@ -1253,7 +1261,7 @@ BOOL const isRunningMCCurrentBad = ( ( BLOOD_PUMP_OFF_STATE != bloodPumpState ) && ( bpCurr > BP_MAX_CURR_WHEN_RUNNING_MA ) ? TRUE : FALSE ); if ( ( TRUE == isPersistentAlarmTriggered( ALARM_ID_HD_BLOOD_PUMP_MC_CURRENT_CHECK, isOffMCCurrentBad || isRunningMCCurrentBad ) ) && - ( FALSE == isACPowerLost() ) ) + ( getCPLDACPowerLossDetected() != TRUE ) ) { #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_MOTOR_CURRNT_CHECKS ) != SW_CONFIG_ENABLE_VALUE )