Index: firmware/App/Controllers/AirTrap.c =================================================================== diff -u -rb89d157b56dce2daf63f4a9e9df9ef6636f2bf44 -rbe1f6ba8f58abfe098865c85ebca070eb0dde6ce --- firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision b89d157b56dce2daf63f4a9e9df9ef6636f2bf44) +++ firmware/App/Controllers/AirTrap.c (.../AirTrap.c) (revision be1f6ba8f58abfe098865c85ebca070eb0dde6ce) @@ -362,8 +362,10 @@ // Lower air trap level if fluid reaches upper level. else if ( AIR_TRAP_LEVEL_FLUID == getLevelSensorState( H16_LEVL ) ) { - if ( ( AIR_PUMP_STATE_OFF == getAirPumpState() ) && - ( TRUE == didTimeout( airTrapLowerDelayStartTime, AIR_PUMP_ON_DELAY_TIME_MS ) ) ) + // TODO un-comment + //if ( ( AIR_PUMP_STATE_OFF == getAirPumpState() ) && + // ( TRUE == didTimeout( airTrapLowerDelayStartTime, AIR_PUMP_ON_DELAY_TIME_MS ) ) ) + if ( AIR_PUMP_STATE_OFF == getAirPumpState() ) { set3WayValveState( H13_VALV, VALVE_3WAY_COMMON_TO_OPEN_STATE ); // open valve H13 to allow air to be pumped into air trap from atmosphere setAirPumpState( AIR_PUMP_STATE_ON, getAirPumpLowerPowerLevel() ); Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r7d9d8a4b338123b844cf68497a14df6a091add7a -rbe1f6ba8f58abfe098865c85ebca070eb0dde6ce --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 7d9d8a4b338123b844cf68497a14df6a091add7a) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision be1f6ba8f58abfe098865c85ebca070eb0dde6ce) @@ -92,7 +92,7 @@ #define SIZE_OF_ROLLING_AVG 20 ///< Number of pump speed samples in rolling average. -#define BP_TORQUE_PERIOD_RESOLUTION_US 10.0F ///< Blood pump torque period resolution in microseconds (10 us). +#define BP_TORQUE_PERIOD_RESOLUTION_US 1.0F ///< Blood pump torque period resolution in microseconds (1 us). #define BP_1KHZ_TO_TORQUE_CONVERSION_MNM 10.0F ///< Blood pump 1kHz to torque conversion in milli-newtonmeter /// Enumeration of blood pump controller states. @@ -813,6 +813,21 @@ /*********************************************************************//** * @brief + * The getMeasuredBloodPumpTorque function gets the measured blood pump + * torque in mN.m. + * @details \b Inputs: bloodPumpTorquemNm + * @details \b Outputs: none + * @return the current blood pump torque (in mN.m). + *************************************************************************/ +F32 getMeasuredBloodPumpTorque( void ) +{ + F32 result = getF32OverrideValue( &bloodPumpTorquemNm ); + + return result; +} + +/*********************************************************************//** + * @brief * The getBPFlowAlphaYIntercept function gets the blood pump flow alpha * intercept for blood flow estimation. * @details \b Inputs: bpFlowAlphaYIntercept @@ -875,13 +890,13 @@ TD_OP_MODE_T opMode = getCurrentOperationMode(); U32 hallSensor = 0; // TODO gioGetBit( hetPORT1, BP_ROTOR_HALL_SENSOR_NHET_ID ); - payload.h4SetFlowRate = targetBloodFlowRate; - payload.h4MeasFlow = getMeasuredBloodFlowRate(); - payload.h4MeasRotorSpd = getMeasuredBloodPumpRotorSpeed(); - payload.h4MeasPumpSpd = getMeasuredBloodPumpSpeed(); - payload.h4MeasCurr = 0.0F; // TODO getMeasuredBloodPumpMCCurrent(); - payload.h4SetRPM = bloodPumpSetSpeedRPM; - payload.h4RotorCount = getBloodPumpRotorCount(); + payload.h4SetFlowRate = targetBloodFlowRate; + payload.h4MeasFlow = getMeasuredBloodFlowRate(); + payload.h4MeasRotorSpd = getMeasuredBloodPumpRotorSpeed(); + payload.h4MeasPumpSpd = getMeasuredBloodPumpSpeed(); + payload.h4MeasTorquemNm = getMeasuredBloodPumpTorque(); + payload.h4SetRPM = bloodPumpSetSpeedRPM; + payload.h4RotorCount = getBloodPumpRotorCount(); if ( ( MODE_PRET == opMode ) || ( MODE_TREA == opMode ) || ( MODE_POST == opMode ) ) { // prescribed flow only available in treatment modes payload.h4PresFlow = getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ); @@ -891,7 +906,6 @@ payload.h4PresFlow = 0; } payload.h6RotorHallState = ( hallSensor > 0 ? 0 : 1 ); // 1=home, 0=not home - payload.h4MeasTorquemNm = getF32OverrideValue( &bloodPumpTorquemNm ); //payload.bPstate = bloodPumpState; //payload.bpRotorStatus = (U32)getH6RotorStatus(); broadcastData( MSG_ID_TD_BLOOD_PUMP_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&payload, sizeof( BLOOD_PUMP_STATUS_PAYLOAD_T ) ); @@ -948,8 +962,9 @@ static F32 calcBloodPumpTorque( void ) { F32 torqueResolutionUS = (F32)getH4TorqueCount() * BP_TORQUE_PERIOD_RESOLUTION_US; - F32 frequencyHz = 1.0F / ( (F32)US_PER_SECOND / torqueResolutionUS ); - F32 frequencyKHz = (F32)HZ_PER_KHZ / frequencyHz; + F32 torqueResolutionS = torqueResolutionUS / (F32)US_PER_SECOND; + F32 frequencyHz = 1.0F / torqueResolutionS; + F32 frequencyKHz = frequencyHz / (F32)HZ_PER_KHZ; F32 torquemNm = frequencyKHz * BP_1KHZ_TO_TORQUE_CONVERSION_MNM; return torquemNm; Index: firmware/App/Controllers/BloodFlow.h =================================================================== diff -u -r22a8500467c47070dff55824e2ec567c007434ce -rbe1f6ba8f58abfe098865c85ebca070eb0dde6ce --- firmware/App/Controllers/BloodFlow.h (.../BloodFlow.h) (revision 22a8500467c47070dff55824e2ec567c007434ce) +++ firmware/App/Controllers/BloodFlow.h (.../BloodFlow.h) (revision be1f6ba8f58abfe098865c85ebca070eb0dde6ce) @@ -43,12 +43,11 @@ F32 h4MeasFlow; ///< Measured flow rate in mL/min. F32 h4MeasRotorSpd; ///< Measured rotor speed in RPM. F32 h4MeasPumpSpd; ///< Measured pump speed in RPM. - F32 h4MeasCurr; ///< Measure motor current in Amps. + F32 h4MeasTorquemNm; ///< Measured torque in mN.m. F32 h4SetRPM; ///< Set motor speed in RPM. U32 h4RotorCount; ///< Rotor count. U32 h4PresFlow; ///< Prescribed blood flow in mL/min. U32 h6RotorHallState; ///< Rotor hall state (1=home, 0=not home). - F32 h4MeasTorquemNm; ///< Measured torque in mN.m. //U32 bPstate; //U32 bpRotorStatus; } BLOOD_PUMP_STATUS_PAYLOAD_T; @@ -74,6 +73,7 @@ F32 getMeasuredBloodFlowRate( void ); F32 getMeasuredBloodPumpRotorSpeed( void ); F32 getMeasuredBloodPumpSpeed( void ); +F32 getMeasuredBloodPumpTorque( void ); BOOL testBloodFlowDataPublishIntervalOverride( MESSAGE_T *message ); BOOL testSetTargetBloodFlowRateOverride( MESSAGE_T *message ); Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r5aa897d2ca22435bf7ec90dfdf656facb740276a -rbe1f6ba8f58abfe098865c85ebca070eb0dde6ce --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 5aa897d2ca22435bf7ec90dfdf656facb740276a) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision be1f6ba8f58abfe098865c85ebca070eb0dde6ce) @@ -273,56 +273,49 @@ for ( valve = FIRST_VALVE; valve < NUM_OF_VALVES; valve++ ) { - if ( valve < NUM_OF_VALVES ) + // update valve encoder positions + currentValveStates[ valve ].priorEncPosition = currentValveStates[ valve ].currentEncPosition; + currentValveStates[ valve ].currentEncPosition = getValveEncoderPosition( valve ); + + // execute valve state machine + switch ( currentValveStates[ valve ].controlState ) { - // update valve encoder positions - currentValveStates[ valve ].priorEncPosition = currentValveStates[ valve ].currentEncPosition; - currentValveStates[ valve ].currentEncPosition = getValveEncoderPosition( valve ); + case VALVE_STATE_WAIT_FOR_POST: + currentValveStates[ valve ].controlState = handleValvesWait4PostState( valve ); + break; - // execute valve state machine - switch ( currentValveStates[ valve ].controlState ) - { - case VALVE_STATE_WAIT_FOR_POST: - currentValveStates[ valve ].controlState = handleValvesWait4PostState( valve ); - break; + case VALVE_STATE_RESET_VALVE: + currentValveStates[ valve ].controlState = handleValvesResetValve( valve ); + break; - case VALVE_STATE_RESET_VALVE: - currentValveStates[ valve ].controlState = handleValvesResetValve( valve ); - break; + case VALVE_STATE_RESET_ENCODER: + currentValveStates[ valve ].controlState = handleValvesResetEncoder( valve ); + break; - case VALVE_STATE_RESET_ENCODER: - currentValveStates[ valve ].controlState = handleValvesResetEncoder( valve ); - break; + case VALVE_STATE_ENABLE_VALVE: + currentValveStates[ valve ].controlState = handleValvesEnableValve( valve ); + break; - case VALVE_STATE_ENABLE_VALVE: - currentValveStates[ valve ].controlState = handleValvesEnableValve( valve ); - break; + case VALVE_STATE_HOMING_NOT_STARTED: + currentValveStates[ valve ].controlState = handleValvesNotHomedState( valve ); + break; - case VALVE_STATE_HOMING_NOT_STARTED: - currentValveStates[ valve ].controlState = handleValvesNotHomedState( valve ); - break; + case VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE: + currentValveStates[ valve ].controlState = handleValvesFindEnergizedEdgeState( valve ); + break; - case VALVE_STATE_HOMING_FIND_ENERGIZED_EDGE: - currentValveStates[ valve ].controlState = handleValvesFindEnergizedEdgeState( valve ); - break; + case VALVE_STATE_IDLE: + currentValveStates[ valve ].controlState = handleValvesIdleState( valve ); + break; - case VALVE_STATE_IDLE: - currentValveStates[ valve ].controlState = handleValvesIdleState( valve ); - break; + case VALVE_STATE_IN_TRANSITION: + currentValveStates[ valve ].controlState = handleValvesTransitionState( valve ); + break; - case VALVE_STATE_IN_TRANSITION: - currentValveStates[ valve ].controlState = handleValvesTransitionState( valve ); - break; - - default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_VALVES_INVALID_STATE, (U32)currentValveStates[ valve ].controlState ) - break; - } + default: + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_VALVES_INVALID_STATE, (U32)currentValveStates[ valve ].controlState ) + break; } - else - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_TD_SOFTWARE_FAULT, SW_FAULT_ID_TD_VALVES_INVALID_VALVE2, (U32)valve ) - } } publishValvesData(); @@ -487,7 +480,7 @@ // Position C is hard coded as count 8. // Position D is hard coded as an offset form 0. currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ] = ROTARY_VALVE_MICROSTEP_FRACTION; - currentValveStates[ valve ].positionsABC[ VALVE_POSITION_D_VENOUS ] = POS_D_VENOUS_OFFSET_FROM_ZERO_CNT; + currentValveStates[ valve ].positionsABC[ VALVE_POSITION_D_PARTIAL_CLOSE ] = POS_D_VENOUS_OFFSET_FROM_ZERO_CNT; nextState = VALVE_STATE_HOMING_NOT_STARTED; #endif @@ -611,7 +604,7 @@ else { S16 posC = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ]; - S16 posA = posC + ( curPos / 2 ); + S16 posA = posC + ( ( curPos - posC ) / 2 ); // If position A was calculated to not be a division of 8 it is rounded down to be a division of 8 posA = ( posA % ROTARY_VALVE_MICROSTEP_FRACTION ) < 4 ? ( posA >> 3 ) << 3 : posA; @@ -802,6 +795,7 @@ data.posA = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_A_INSERT_EJECT ]; data.posB = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_B_OPEN ]; data.posC = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_C_CLOSE ]; + data.posD = currentValveStates[ valve ].positionsABC[ VALVE_POSITION_D_PARTIAL_CLOSE ]; broadcastData( MSG_ID_TD_VALVES_DATA, COMM_BUFFER_OUT_CAN_TD_BROADCAST, (U08*)&data, sizeof( TD_VALVE_DATA_T ) ); } Index: firmware/App/Controllers/Valves.h =================================================================== diff -u -r8de3c971a08a5e2d822a6a1d1d1c477b6d4cbd5b -rbe1f6ba8f58abfe098865c85ebca070eb0dde6ce --- firmware/App/Controllers/Valves.h (.../Valves.h) (revision 8de3c971a08a5e2d822a6a1d1d1c477b6d4cbd5b) +++ firmware/App/Controllers/Valves.h (.../Valves.h) (revision be1f6ba8f58abfe098865c85ebca070eb0dde6ce) @@ -40,7 +40,7 @@ VALVE_POSITION_A_INSERT_EJECT, ///< Position A, Insert/Eject VALVE_POSITION_B_OPEN, ///< Position B, Open VALVE_POSITION_C_CLOSE, ///< Position C, Close - VALVE_POSITION_D_VENOUS, ///< Position D, Venous + VALVE_POSITION_D_PARTIAL_CLOSE, ///< Position D, partial close NUM_OF_VALVE_POSITIONS, ///< Number of valve positions } VALVE_POSITION_T; @@ -56,6 +56,7 @@ S16 posA; ///< Position A (count) S16 posB; ///< Position B (count) S16 posC; ///< Position C (count) + S16 posD; ///< Position D (count) } TD_VALVE_DATA_T; #pragma pack(pop) Index: firmware/App/Modes/ModePreTreat.c =================================================================== diff -u -r22a8500467c47070dff55824e2ec567c007434ce -rbe1f6ba8f58abfe098865c85ebca070eb0dde6ce --- firmware/App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision 22a8500467c47070dff55824e2ec567c007434ce) +++ firmware/App/Modes/ModePreTreat.c (.../ModePreTreat.c) (revision be1f6ba8f58abfe098865c85ebca070eb0dde6ce) @@ -8,32 +8,62 @@ * @{ */ +// ********** private definitions ********** + +// ********** private data ********** + static U32 testTimeRemove = 0; +// ********** private function prototypes ********** + +/*********************************************************************//** + * @brief + * The initPreTreatmentMode function initializes the Pre Treatment Mode unit. + * @details \b Inputs: none + * @details \b Outputs: Pre Treatment Mode unit initialized. + * @return none + *************************************************************************/ void initPreTreatmentMode( void ) { testTimeRemove = 0; } +/*********************************************************************//** + * @brief + * The transitionToPreTreatmentMode function prepares for transition to pre-treatment + * mode. + * @details \b Inputs: none + * @details \b Outputs: none + * @return initial state + *************************************************************************/ U32 transitionToPreTreatmentMode( void ) { initPreTreatmentMode(); testTimeRemove = getMSTimerCount(); + return 0; } +/*********************************************************************//** + * @brief + * The execPreTreatmentMode function executes the Pre Treatment Mode state machine. + * @details \b Alarm: TODO fill up once the exec function is complete + * the stop button + * @details \b Inputs: TODO fill up once the exec function is complete + * @details \b Outputs: TODO fill up once the exec function is complete + * @return current state (sub-mode) + *************************************************************************/ U32 execPreTreatmentMode( void ) { - if ( TRUE == didTimeout( testTimeRemove, 10000 ) ) // TODO temporary remove + if ( TRUE == didTimeout( testTimeRemove, 10000 ) ) // TODO temporary test code to just transition to treatment mode { requestNewOperationMode( MODE_TREA ); } return 0; } - /**@}*/ Index: firmware/App/Modes/ModePreTreat.h =================================================================== diff -u -r927c47388ab6bd716b857f76e2026c116dd52e69 -rbe1f6ba8f58abfe098865c85ebca070eb0dde6ce --- firmware/App/Modes/ModePreTreat.h (.../ModePreTreat.h) (revision 927c47388ab6bd716b857f76e2026c116dd52e69) +++ firmware/App/Modes/ModePreTreat.h (.../ModePreTreat.h) (revision be1f6ba8f58abfe098865c85ebca070eb0dde6ce) @@ -7,7 +7,7 @@ #include "TDDefs.h" /** - * @defgroup TDPreTreatmentMode HDPreTreatmentMode + * @defgroup TDPreTreatmentMode TDPreTreatmentMode * @brief Pre-TreatmentMode module. * * @addtogroup TDPreTreatmentMode @@ -20,8 +20,6 @@ U32 transitionToPreTreatmentMode( void ); // Prepares for transition to pre-treatment mode U32 execPreTreatmentMode( void ); // Execute the pre-treatment mode state machine (call from OperationModes) - - /**@}*/ #endif Index: firmware/App/TDCommon.h =================================================================== diff -u -rb89d157b56dce2daf63f4a9e9df9ef6636f2bf44 -rbe1f6ba8f58abfe098865c85ebca070eb0dde6ce --- firmware/App/TDCommon.h (.../TDCommon.h) (revision b89d157b56dce2daf63f4a9e9df9ef6636f2bf44) +++ firmware/App/TDCommon.h (.../TDCommon.h) (revision be1f6ba8f58abfe098865c85ebca070eb0dde6ce) @@ -37,7 +37,6 @@ // #define TEST_DEBUGGER 1 // Testing with debugger - prevents FPGA comm alarms caused by breakpoints // #define TEST_PROCESS_TASKS_WO_UI 1 // Allow task processing even when UI not connected #define TEST_UI_ONLY 1 // Alpha test with TD and UI only - no DD -// #define TEST_NO_PINCH_VALVES 1 // Alpha test with no pinch valve functionality // #define TEST_USE_OFF_AS_STOP_BUTTON 1 // Alpha test re-purposing off button as a stop button #define TEST_NO_PRESSURE_CHECKS 1 // Alpha test with no pressure sensor checks // #define TEST_NO_STOP_CONSUME_CHECK 1 // Alpha test with no check for stop button timeout