Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -rac05209d7b6c65b22359754eced5ad2672d3092a -r78c03fb021407eaf8d17dd0f74f6969443b397ce --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision ac05209d7b6c65b22359754eced5ad2672d3092a) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 78c03fb021407eaf8d17dd0f74f6969443b397ce) @@ -20,7 +20,7 @@ #include "can.h" #include "etpwm.h" -// TODO - test includes - remove later +// TODO - Test includes - remove later #include "DialInFlow.h" #include "PresOccl.h" @@ -44,53 +44,53 @@ // ********** private definitions ********** -/// interval (ms/task time) at which the blood flow data is published on the CAN bus. +/// 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_BLOOD_PUMP_PWM_STEP_UP_CHANGE 0.008 ///< max duty cycle change when ramping up ~ 100 mL/min/s. -#define MAX_BLOOD_PUMP_PWM_STEP_DN_CHANGE 0.016 ///< max duty cycle change when ramping down ~ 200 mL/min/s. -#define MAX_BLOOD_PUMP_PWM_DUTY_CYCLE 0.88 ///< controller will error if PWM duty cycle > 90%, so set max to 88% -#define MIN_BLOOD_PUMP_PWM_DUTY_CYCLE 0.12 ///< controller will error if PWM duty cycle < 10%, so set min to 12% +#define MAX_BLOOD_PUMP_PWM_STEP_UP_CHANGE 0.008 ///< Max duty cycle change when ramping up ~ 100 mL/min/s. +#define MAX_BLOOD_PUMP_PWM_STEP_DN_CHANGE 0.016 ///< Max duty cycle change when ramping down ~ 200 mL/min/s. +#define MAX_BLOOD_PUMP_PWM_DUTY_CYCLE 0.88 ///< Controller will error if PWM duty cycle > 90%, so set max to 88% +#define MIN_BLOOD_PUMP_PWM_DUTY_CYCLE 0.12 ///< Controller will error if PWM duty cycle < 10%, so set min to 12% -/// interval (ms/task time) at which the blood pump is controlled. +/// Interval (ms/task time) at which the blood pump is controlled. #define BP_CONTROL_INTERVAL ( 10000 / TASK_GENERAL_INTERVAL ) #define BP_P_COEFFICIENT 0.00035 ///< P term for blood pump control #define BP_I_COEFFICIENT 0.00035 ///< 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 allowed for homing to complete (in ms). -/// interval (ms/task time) at which the blood pump speed is calculated (every 40 ms). +#define BP_HOME_RATE 100 ///< Target pump speed (in estimate mL/min) for homing. +#define BP_HOME_TIMEOUT_MS 10000 ///< Maximum time allowed for homing to complete (in ms). +/// Interval (ms/task time) at which the blood pump speed is calculated (every 40 ms). #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. +/// Number of hall sensor counts kept in buffer to hold last 1 second of count data. #define BP_SPEED_CALC_BUFFER_LEN ( 1000 / BP_SPEED_CALC_INTERVAL / TASK_PRIORITY_INTERVAL ) -#define BP_HALL_EDGE_COUNTS_PER_REV 48 ///< number of hall sensor edge counts per motor revolution. -#define BP_MAX_ROTOR_SPEED_RPM 100.0 ///< maximum rotor speed allowed for blood pump. +#define BP_HALL_EDGE_COUNTS_PER_REV 48 ///< Number of hall sensor edge counts per motor revolution. +#define BP_MAX_ROTOR_SPEED_RPM 100.0 ///< Maximum rotor speed allowed for blood pump. -#define BP_MAX_FLOW_VS_SPEED_DIFF_RPM 200.0 ///< maximum difference between measured speed and speed implied by measured flow. -#define BP_MAX_MOTOR_SPEED_WHILE_OFF_RPM 100.0 ///< maximum motor speed (RPM) while motor is commanded off. -#define BP_MAX_ROTOR_VS_MOTOR_DIFF_RPM 5.0 ///< maximum difference in speed between motor and rotor (in rotor RPM). -#define BP_MAX_MOTOR_SPEED_ERROR_RPM 300.0 ///< maximum difference in speed between measured and commanded RPM. -#define BP_FLOW_VS_SPEED_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) for flow vs. motor speed error condition. -#define BP_OFF_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) for motor off error condition. -#define BP_MOTOR_SPEED_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) motor speed error condition. -#define BP_ROTOR_SPEED_ERROR_PERSIST ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) rotor speed error condition. -#define BP_DIRECTION_ERROR_PERSIST (250 / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) pump direction error condition. -#define BP_MAX_ROTOR_SPEED_ERROR_PERSIST ((1 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< persist time (task intervals) blood pump rotor speed too fast error condition. +#define BP_MAX_FLOW_VS_SPEED_DIFF_RPM 200.0 ///< Maximum difference between measured speed and speed implied by measured flow. +#define BP_MAX_MOTOR_SPEED_WHILE_OFF_RPM 100.0 ///< Maximum motor speed (RPM) while motor is commanded off. +#define BP_MAX_ROTOR_VS_MOTOR_DIFF_RPM 5.0 ///< Maximum difference in speed between motor and rotor (in rotor RPM). +#define BP_MAX_MOTOR_SPEED_ERROR_RPM 300.0 ///< Maximum difference in speed between measured and commanded RPM. +#define BP_FLOW_VS_SPEED_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) for flow vs. motor speed error condition. +#define BP_OFF_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) for motor off error condition. +#define BP_MOTOR_SPEED_ERROR_PERSIST ((5 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) motor speed error condition. +#define BP_ROTOR_SPEED_ERROR_PERSIST ((12 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) rotor speed error condition. +#define BP_DIRECTION_ERROR_PERSIST (250 / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) pump direction error condition. +#define BP_MAX_ROTOR_SPEED_ERROR_PERSIST ((1 * MS_PER_SECOND) / TASK_PRIORITY_INTERVAL) ///< Persist time (task intervals) blood pump rotor speed too fast error condition. -#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 -#define BP_MAX_CURR_WHEN_RUNNING_MA 2000.0 ///< motor controller current should not exceed this when pump should be running -#define BP_MAX_CURR_ERROR_DURATION_MS 2000 ///< motor controller current errors persisting beyond this duration will trigger an alarm +#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 +#define BP_MAX_CURR_WHEN_RUNNING_MA 2000.0 ///< Motor controller current should not exceed this when pump should be running +#define BP_MAX_CURR_ERROR_DURATION_MS 2000 ///< Motor controller current errors persisting beyond this duration will trigger an alarm -#define BP_SPEED_ADC_TO_RPM_FACTOR 1.280938 ///< conversion factor from ADC counts to RPM for blood pump motor -#define BP_CURRENT_ADC_TO_MA_FACTOR 3.002 ///< conversion factor from ADC counts to mA for blood pump motor +#define BP_SPEED_ADC_TO_RPM_FACTOR 1.280938 ///< Conversion factor from ADC counts to RPM for blood pump motor +#define BP_CURRENT_ADC_TO_MA_FACTOR 3.002 ///< Conversion factor from ADC counts to mA for blood pump motor -#define BP_REV_PER_LITER 150.0 ///< rotor revolutions per liter -#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_REV_PER_LITER 150.0 ///< Rotor revolutions per liter +#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_MOTOR_RPM_TO_PWM_DC_FACTOR 0.00028 ///< ~28 BP motor RPM = 1% PWM duty cycle #define BP_PWM_ZERO_OFFSET 0.1 ///< 10% PWM duty cycle = zero speed -/// conversion factor from mL/min to estimated PWM duty cycle %. +/// Conversion factor 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 ) #define BLOODPUMP_ADC_FULL_SCALE_V 3.0 ///< BP analog signals are 0-3V (while int. ADC ref may be different) @@ -127,63 +127,63 @@ #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) // 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 ********** -static BLOOD_PUMP_STATE_T bloodPumpState = BLOOD_PUMP_OFF_STATE; ///< current state of blood flow controller state machine -static U32 bloodFlowDataPublicationTimerCounter = 0; ///< used to schedule blood flow data publication to CAN bus -static BOOL isBloodPumpOn = FALSE; ///< blood pump is currently running -static F32 bloodPumpPWMDutyCyclePct = 0.0; ///< initial blood pump PWM duty cycle -static F32 bloodPumpPWMDutyCyclePctSet = 0.0; ///< currently set blood pump PWM duty cycle -static MOTOR_DIR_T bloodPumpDirection = MOTOR_DIR_FORWARD; ///< requested blood flow direction -static MOTOR_DIR_T bloodPumpDirectionSet = MOTOR_DIR_FORWARD; ///< currently set blood flow direction -static PUMP_CONTROL_MODE_T bloodPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< requested blood pump control mode. -static PUMP_CONTROL_MODE_T bloodPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< currently set blood pump control mode. -static F32 bloodFlowCalGain = 1.0; ///< blood flow calibration gain. -static F32 bloodFlowCalOffset = 0.0; ///< blood flow calibration offset. +static BLOOD_PUMP_STATE_T bloodPumpState = BLOOD_PUMP_OFF_STATE; ///< Current state of blood flow controller state machine +static U32 bloodFlowDataPublicationTimerCounter = 0; ///< Used to schedule blood flow data publication to CAN bus +static BOOL isBloodPumpOn = FALSE; ///< Blood pump is currently running +static F32 bloodPumpPWMDutyCyclePct = 0.0; ///< Initial blood pump PWM duty cycle +static F32 bloodPumpPWMDutyCyclePctSet = 0.0; ///< Currently set blood pump PWM duty cycle +static MOTOR_DIR_T bloodPumpDirection = MOTOR_DIR_FORWARD; ///< Requested blood flow direction +static MOTOR_DIR_T bloodPumpDirectionSet = MOTOR_DIR_FORWARD; ///< Currently set blood flow direction +static PUMP_CONTROL_MODE_T bloodPumpControlMode = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Requested blood pump control mode. +static PUMP_CONTROL_MODE_T bloodPumpControlModeSet = PUMP_CONTROL_MODE_CLOSED_LOOP; ///< Currently set blood pump control mode. +static F32 bloodFlowCalGain = 1.0; ///< Blood flow calibration gain. +static F32 bloodFlowCalOffset = 0.0; ///< Blood flow calibration offset. /// Interval (in task intervals) at which to publish blood flow data to CAN bus. static OVERRIDE_U32_T bloodFlowDataPublishInterval = { BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, BLOOD_FLOW_DATA_PUB_INTERVAL, 0 }; -static S32 targetBloodFlowRate = 0; ///< requested blood flow rate -static OVERRIDE_F32_T measuredBloodFlowRate = { 0.0, 0.0, 0.0, 0 }; ///< measured blood flow rate -static OVERRIDE_F32_T bloodPumpRotorSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump rotor speed -static OVERRIDE_F32_T bloodPumpSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump motor speed -static OVERRIDE_F32_T adcBloodPumpMCSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump motor controller speed -static OVERRIDE_F32_T adcBloodPumpMCCurrentmA = { 0.0, 0.0, 0.0, 0 }; ///< measured blood pump motor controller current -static OVERRIDE_F32_T bloodFlowSignalStrength = { 0.0, 0.0, 0.0, 0 }; ///< measured blood flow signal strength (%) +static S32 targetBloodFlowRate = 0; ///< Requested blood flow rate +static OVERRIDE_F32_T measuredBloodFlowRate = { 0.0, 0.0, 0.0, 0 }; ///< Measured blood flow rate +static OVERRIDE_F32_T bloodPumpRotorSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< Measured blood pump rotor speed +static OVERRIDE_F32_T bloodPumpSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< Measured blood pump motor speed +static OVERRIDE_F32_T adcBloodPumpMCSpeedRPM = { 0.0, 0.0, 0.0, 0 }; ///< Measured blood pump motor controller speed +static OVERRIDE_F32_T adcBloodPumpMCCurrentmA = { 0.0, 0.0, 0.0, 0 }; ///< Measured blood pump motor controller current +static OVERRIDE_F32_T bloodFlowSignalStrength = { 0.0, 0.0, 0.0, 0 }; ///< Measured blood flow signal strength (%) -static U32 bpControlTimerCounter = 0; ///< determines when to perform control on blood flow +static U32 bpControlTimerCounter = 0; ///< Determines when to perform control on blood flow -static U32 bpRotorRevStartTime = 0; ///< blood pump rotor rotation start time (in ms) -static U32 bloodPumpRotorCounter = 0; ///< running counter for blood pump rotor revolutions -static BOOL bpStopAtHomePosition = FALSE; ///< stop blood pump at next home position -static U32 bpHomeStartTime = 0; ///< when did blood pump home command begin? (in ms) +static U32 bpRotorRevStartTime = 0; ///< Blood pump rotor rotation start time (in ms) +static U32 bloodPumpRotorCounter = 0; ///< Running counter for blood pump rotor revolutions +static BOOL bpStopAtHomePosition = FALSE; ///< Stop blood pump at next home position +static U32 bpHomeStartTime = 0; ///< When did blood pump home command begin? (in ms) -static U32 bloodPumpMotorEdgeCount = 0; ///< running counter for blood pump motor revolutions -static U16 bpLastMotorHallSensorCounts[ BP_SPEED_CALC_BUFFER_LEN ]; ///< last hall sensor readings for the blood pump motor -static U32 bpMotorSpeedCalcIdx = 0; ///< index into 1 second buffer of motor speed hall sensor counts -static U32 bpMotorSpeedCalcTimerCtr = 0; ///< counter determines interval for calculating blood pump motor speed from hall sensor count. +static U32 bloodPumpMotorEdgeCount = 0; ///< Running counter for blood pump motor revolutions +static U16 bpLastMotorHallSensorCounts[ BP_SPEED_CALC_BUFFER_LEN ]; ///< Last hall sensor readings for the blood pump motor +static U32 bpMotorSpeedCalcIdx = 0; ///< Index into 1 second buffer of motor speed hall sensor counts +static U32 bpMotorSpeedCalcTimerCtr = 0; ///< Counter determines interval for calculating blood pump motor speed from hall sensor count. -static U32 errorBloodFlowVsMotorSpeedPersistTimerCtr = 0; ///< persistence timer counter for flow vs. motor speed error condition. -static U32 errorBloodMotorOffPersistTimerCtr = 0; ///< persistence timer counter for motor off check error condition. -static U32 errorBloodMotorSpeedPersistTimerCtr = 0; ///< persistence timer counter for motor speed error condition. -static U32 errorBloodRotorSpeedPersistTimerCtr = 0; ///< persistence timer counter for rotor speed error condition. -static U32 errorBloodPumpDirectionPersistTimerCtr = 0; ///< persistence timer counter for pump direction error condition. -static U32 errorBloodPumpRotorTooFastPersistTimerCtr = 0; ///< persistence timer counter for pump rotor too fast error condition. +static U32 errorBloodFlowVsMotorSpeedPersistTimerCtr = 0; ///< Persistence timer counter for flow vs. motor speed error condition. +static U32 errorBloodMotorOffPersistTimerCtr = 0; ///< Persistence timer counter for motor off check error condition. +static U32 errorBloodMotorSpeedPersistTimerCtr = 0; ///< Persistence timer counter for motor speed error condition. +static U32 errorBloodRotorSpeedPersistTimerCtr = 0; ///< Persistence timer counter for rotor speed error condition. +static U32 errorBloodPumpDirectionPersistTimerCtr = 0; ///< Persistence timer counter for pump direction error condition. +static U32 errorBloodPumpRotorTooFastPersistTimerCtr = 0; ///< Persistence timer counter for pump rotor too fast 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 -static F32 flowReadingsTotal = 0.0; ///< rolling total - used to calc average -static U32 flowReadingsCount = 0; ///< number of samples in flow rolling average buffer +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 +static F32 flowReadingsTotal = 0.0; ///< Rolling total - used to calc average +static U32 flowReadingsCount = 0; ///< Number of samples in flow rolling average buffer -static U32 bpCurrErrorDurationCtr = 0; ///< used for tracking persistence of bp current errors +static U32 bpCurrErrorDurationCtr = 0; ///< Used for tracking persistence of bp current errors -static BLOOD_FLOW_SELF_TEST_STATE_T bloodPumpSelfTestState = BLOOD_FLOW_SELF_TEST_STATE_START; ///< current blood pump self-test state -static U32 bloodPumpSelfTestTimerCount = 0; ///< timer counter for blood pump self-test +static BLOOD_FLOW_SELF_TEST_STATE_T bloodPumpSelfTestState = BLOOD_FLOW_SELF_TEST_STATE_START; ///< Current blood pump self-test state +static U32 bloodPumpSelfTestTimerCount = 0; ///< Timer counter for blood pump self-test // ********** private function prototypes ********** @@ -221,22 +221,22 @@ stopBloodPump(); setBloodPumpDirection( MOTOR_DIR_FORWARD ); - // zero rolling flow average buffer + // Zero rolling flow average buffer resetBloodFlowMovingAverage(); - // zero motor hall sensors counts buffer + // Zero motor hall sensors counts buffer bpMotorSpeedCalcIdx = 0; for ( i = 0; i < BP_SPEED_CALC_BUFFER_LEN; i++ ) { bpLastMotorHallSensorCounts[ i ] = 0; } - // initialize blood flow PI controller + // Initialize blood flow PI controller initializePIController( PI_CONTROLLER_ID_BLOOD_FLOW, MIN_BLOOD_PUMP_PWM_DUTY_CYCLE, BP_P_COEFFICIENT, BP_I_COEFFICIENT, MIN_BLOOD_PUMP_PWM_DUTY_CYCLE, MAX_BLOOD_PUMP_PWM_DUTY_CYCLE ); - // initialize persistent alarm for flow sensor signal strength too low + // Initialize persistent alarm for flow sensor signal strength too low initPersistentAlarm( PERSISTENT_ALARM_BLOOD_FLOW_SIGNAL_STRENGTH, ALARM_ID_BLOOD_FLOW_SIGNAL_STRENGTH_TOO_LOW, FALSE, FLOW_SIG_STRGTH_ALARM_PERSIST, FLOW_SIG_STRGTH_ALARM_PERSIST ); @@ -257,34 +257,34 @@ { BOOL result = FALSE; - // direction change while pump is running is not allowed + // Direction change while pump is running is not allowed if ( ( FALSE == isBloodPumpOn ) || ( 0 == flowRate ) || ( dir == bloodPumpDirectionSet ) ) { - // verify flow rate + // Verify flow rate if ( flowRate <= MAX_BLOOD_FLOW_RATE ) { resetBloodFlowMovingAverage(); targetBloodFlowRate = ( dir == MOTOR_DIR_FORWARD ? (S32)flowRate : (S32)flowRate * -1 ); bloodPumpDirection = dir; bloodPumpControlMode = 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 + // 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 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%) switch ( bloodPumpState ) { - case BLOOD_PUMP_RAMPING_UP_STATE: // see if we need to reverse direction of ramp + case BLOOD_PUMP_RAMPING_UP_STATE: // See if we need to reverse direction of ramp if ( bloodPumpPWMDutyCyclePct < bloodPumpPWMDutyCyclePctSet ) { bloodPumpState = BLOOD_PUMP_RAMPING_DOWN_STATE; } break; - case BLOOD_PUMP_RAMPING_DOWN_STATE: // see if we need to reverse direction of ramp + case BLOOD_PUMP_RAMPING_DOWN_STATE: // See if we need to reverse direction of ramp if ( bloodPumpPWMDutyCyclePct > bloodPumpPWMDutyCyclePctSet ) { bloodPumpState = BLOOD_PUMP_RAMPING_UP_STATE; } break; - case BLOOD_PUMP_CONTROL_TO_TARGET_STATE: // start ramp to new target in appropriate direction + case BLOOD_PUMP_CONTROL_TO_TARGET_STATE: // Start ramp to new target in appropriate direction if ( bloodPumpPWMDutyCyclePctSet > bloodPumpPWMDutyCyclePct ) { bloodPumpState = BLOOD_PUMP_RAMPING_DOWN_STATE; @@ -295,12 +295,12 @@ } break; default: - // ok - not all states need to be handled here + // Ok - not all states need to be handled here break; } result = TRUE; } - else // requested flow rate too high + else // Requested flow rate too high { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_BLOOD_FLOW_SET_TOO_HIGH, flowRate ) } @@ -340,14 +340,14 @@ U32 rotTime = getMSTimerCount(); U32 deltaTime = calcTimeBetween( bpRotorRevStartTime, rotTime ); - // increment rotor counter + // Increment rotor counter bloodPumpRotorCounter++; - // calculate rotor speed (in RPM) + // Calculate rotor speed (in RPM) bloodPumpRotorSpeedRPM.data = ( 1.0 / (F32)deltaTime ) * (F32)MS_PER_SECOND * (F32)SEC_PER_MIN; bpRotorRevStartTime = rotTime; - // if we're supposed to stop pump at home position, stop pump now. + // If we're supposed to stop pump at home position, stop pump now. if ( TRUE == bpStopAtHomePosition ) { signalBloodPumpHardStop(); @@ -427,34 +427,34 @@ HD_OP_MODE_T opMode = getCurrentOperationMode(); U16 bpRPM = getIntADCReading( INT_ADC_BLOOD_PUMP_SPEED ); U16 bpmA = getIntADCReading( INT_ADC_BLOOD_PUMP_MOTOR_CURRENT ); - F32 bpFlow = ( ( getFPGABloodFlow() * -1.0 ) * bloodFlowCalGain ) + bloodFlowCalOffset; // blood flow sensor installed backwards on HD + F32 bpFlow = ( ( getFPGABloodFlow() * -1.0 ) * bloodFlowCalGain ) + bloodFlowCalOffset; // Blood flow sensor installed backwards on HD adcBloodPumpMCSpeedRPM.data = (F32)(SIGN_FROM_12_BIT_VALUE(bpRPM)) * BP_SPEED_ADC_TO_RPM_FACTOR; adcBloodPumpMCCurrentmA.data = (F32)(SIGN_FROM_12_BIT_VALUE(bpmA)) * BP_CURRENT_ADC_TO_MA_FACTOR; bloodFlowSignalStrength.data = getFPGABloodFlowSignalStrength(); filterBloodFlowReadings( bpFlow ); - // calculate blood pump motor speed/direction from hall sensor count + // Calculate blood pump motor speed/direction from hall sensor count updateBloodPumpSpeedAndDirectionFromHallSensors(); - // don't start enforcing checks until out of init/POST mode + // Don't start enforcing checks until out of init/POST mode if ( opMode != MODE_INIT ) { - // check pump direction + // Check pump direction checkBloodPumpDirection(); - // check pump controller current + // Check pump controller current checkBloodPumpMCCurrent(); - // check pump speeds and flow + // Check pump speeds and flow checkBloodPumpSpeeds(); checkBloodPumpFlowAgainstSpeed(); - // check for home position, zero/low speed + // Check for home position, zero/low speed checkBloodPumpRotor(); - // check flow sensor signal strength + // Check flow sensor signal strength checkBloodFlowSensorSignalStrength(); } - // publish blood flow data on interval + // Publish blood flow data on interval publishBloodFlowData(); } @@ -503,13 +503,13 @@ { BLOOD_PUMP_STATE_T result = BLOOD_PUMP_OFF_STATE; - // if we've been given a flow rate, setup ramp up and transition to ramp up state + // If we've been given a flow rate, setup ramp up and transition to ramp up state if ( targetBloodFlowRate != 0 ) { - // set initial PWM duty cycle + // Set initial PWM duty cycle bloodPumpPWMDutyCyclePctSet = BP_PWM_ZERO_OFFSET + MAX_BLOOD_PUMP_PWM_STEP_UP_CHANGE; setBloodPumpControlSignalPWM( bloodPumpPWMDutyCyclePctSet ); - // allow blood pump to run in requested direction + // Allow blood pump to run in requested direction setBloodPumpDirection( bloodPumpDirection ); releaseBloodPumpStop(); isBloodPumpOn = TRUE; @@ -553,7 +553,7 @@ } result = BLOOD_PUMP_CONTROL_TO_TARGET_STATE; } - // continue ramp up + // Continue ramp up else { bloodPumpPWMDutyCyclePctSet += MAX_BLOOD_PUMP_PWM_STEP_UP_CHANGE; @@ -595,7 +595,7 @@ } result = BLOOD_PUMP_CONTROL_TO_TARGET_STATE; } - // continue ramp down + // Continue ramp down else { bloodPumpPWMDutyCyclePctSet -= MAX_BLOOD_PUMP_PWM_STEP_DN_CHANGE; @@ -617,7 +617,7 @@ { BLOOD_PUMP_STATE_T result = BLOOD_PUMP_CONTROL_TO_TARGET_STATE; - // control at set interval + // Control at set interval if ( ++bpControlTimerCounter >= BP_CONTROL_INTERVAL ) { if ( bloodPumpControlModeSet == PUMP_CONTROL_MODE_CLOSED_LOOP ) @@ -1015,7 +1015,7 @@ bpMCDir = ( getMeasuredBloodPumpMCSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); bpDir = ( getMeasuredBloodPumpSpeed() >= 0.0 ? MOTOR_DIR_FORWARD : MOTOR_DIR_REVERSE ); - // check set direction vs. direction from hall sensors + // Check set direction vs. direction from hall sensors if ( bloodPumpDirectionSet != bpDir ) { if ( ++errorBloodPumpDirectionPersistTimerCtr >= BP_DIRECTION_ERROR_PERSIST ) @@ -1025,7 +1025,7 @@ #endif } } - // check set direction vs. direction from sign of motor controller speed + // Check set direction vs. direction from sign of motor controller speed else if ( bloodPumpDirectionSet != bpMCDir ) { if ( ++errorBloodPumpDirectionPersistTimerCtr >= BP_DIRECTION_ERROR_PERSIST ) @@ -1063,7 +1063,7 @@ F32 measMotorSpeed = fabs( getMeasuredBloodPumpSpeed() ); S32 cmdRate = targetBloodFlowRate; - // check for pump running while commanded off + // Check for pump running while commanded off if ( 0 == cmdRate ) { if ( measMotorSpeed > BP_MAX_MOTOR_SPEED_WHILE_OFF_RPM ) @@ -1094,7 +1094,7 @@ F32 measMotorSpeedInRotorRPM = measMotorSpeed / BP_GEAR_RATIO; F32 deltaRotorSpeed = fabs( measRotorSpeed - measMotorSpeedInRotorRPM ); - // check measured motor speed vs. commanded motor speed while controlling to target + // Check measured motor speed vs. commanded motor speed while controlling to target if ( deltaMotorSpeed > BP_MAX_MOTOR_SPEED_ERROR_RPM ) { if ( ++errorBloodMotorSpeedPersistTimerCtr >= BP_MOTOR_SPEED_ERROR_PERSIST ) @@ -1109,7 +1109,7 @@ errorBloodMotorSpeedPersistTimerCtr = 0; } - // check measured rotor speed vs. measured motor speed while controlling to target + // Check measured rotor speed vs. measured motor speed while controlling to target if ( deltaRotorSpeed > BP_MAX_ROTOR_VS_MOTOR_DIFF_RPM ) { if ( ++errorBloodRotorSpeedPersistTimerCtr >= BP_ROTOR_SPEED_ERROR_PERSIST ) @@ -1143,7 +1143,7 @@ *************************************************************************/ static void checkBloodPumpFlowAgainstSpeed( void ) { - // check only performed while in treatment mode and while we're in control to target state + // Check only performed while in treatment mode and while we're in control to target state if ( ( MODE_TREA == getCurrentOperationMode() ) && ( BLOOD_PUMP_CONTROL_TO_TARGET_STATE == bloodPumpState ) ) { F32 flow = getMeasuredBloodFlowRate(); @@ -1236,7 +1236,7 @@ #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 + // 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 = getMeasuredBloodFlowSignalStrength(); @@ -1263,7 +1263,7 @@ switch ( bloodPumpSelfTestState ) { case BLOOD_FLOW_SELF_TEST_STATE_START: - // retrieve blood flow sensor calibration data + // Retrieve blood flow sensor calibration data if ( TRUE == getCalibrationData( &cal ) ) { bloodFlowCalGain = cal.bloodFlowGain;