Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -rbd37ce75271151436de0bb6de9f75123d8251396 -r18783d138aec872e3f5b73e60e14e3c53bf740ec --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision bd37ce75271151436de0bb6de9f75123d8251396) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 18783d138aec872e3f5b73e60e14e3c53bf740ec) @@ -118,6 +118,9 @@ static U16 bloodPumpRampToSpeedRPM; ///< Estimated target speed that we want to ramp to. static U16 bloodPumpSetSpeedRPM; ///< Current set speed for the blood pump. +/// Macro for determining the signed set speed for the blood pump based on currently set direction and unsigned set speed. +#define BP_SIGNED_SET_SPEED ( MOTOR_DIR_REVERSE == bloodPumpDirectionSet ? (S32)bloodPumpSetSpeedRPM * -1 : (S32)bloodPumpSetSpeedRPM ) + static OVERRIDE_U32_T bloodFlowDataPublishInterval; ///< Interval (in task intervals) at which to publish blood flow data to CAN bus. static S32 targetBloodFlowRate; ///< Requested blood flow rate. static OVERRIDE_F32_T measuredBloodFlowRate; ///< Measured (calculated now) blood flow rate. @@ -166,6 +169,8 @@ *************************************************************************/ void initBloodFlow( void ) { + U32 i; + // Initialize peristaltic pump driver initPeristalticPumpDriver(); @@ -207,7 +212,10 @@ bloodPumpRotorCounter.override = OVERRIDE_RESET; // Initialize pump speed filter - memset( &rpmReadings[ 0 ], 0, sizeof( rpmReadings ) ); + for ( i = 0; i < SIZE_OF_ROLLING_AVG; i++ ) + { + rpmReadings[ i ] = 0.0F; + } rpmReadingsIdx = 0; rpmReadingsTotal = 0.0; rpmReadingsCount = 0; @@ -492,8 +500,8 @@ * @brief * The execBloodFlowMonitor function executes the blood flow monitor. * @details \b Inputs: none - * @details \b Outputs: measuredBloodFlowRate, adcBloodPumpMCSpeedRPM, - * adcBloodPumpMCCurrentmA + * @details \b Outputs: BP sensor readings updated, filteredBloodPumpSpeed, + * bloodPumpSpeedRPM, bloodPumpDirection, measuredBloodFlowRate * @return none *************************************************************************/ void execBloodFlowMonitor( void ) @@ -584,9 +592,7 @@ { // Start ramp up to target flow rate bloodPumpSetSpeedRPM = BP_RAMP_STEP_SPEED_RPM; -// setPeristalticPumpSetSpeed( bloodPumpSetSpeedRPM ); // TODO - replace all FPGA set speed and direction calls with driver set speed calls - set speed s/b signed to indicate direction. - setBPDirection( bloodPumpDirectionSet ); - setBPSetSpeed( bloodPumpSetSpeedRPM ); + setPeristalticPumpSetSpeed( BP_SIGNED_SET_SPEED ); isBloodPumpOn = TRUE; result = BLOOD_PUMP_RAMPING_UP_STATE; } @@ -616,15 +622,15 @@ { // Start ramp down to stop bloodPumpSetSpeedRPM -= BP_RAMP_STEP_SPEED_RPM; - setBPSetSpeed( bloodPumpSetSpeedRPM ); + setPeristalticPumpSetSpeed( BP_SIGNED_SET_SPEED ); result = BLOOD_PUMP_RAMPING_DN_STATE; } // Have we reached end of ramp up? else if ( bloodPumpSetSpeedRPM >= bloodPumpRampToSpeedRPM ) { resetBloodPumpRPMMovingAverage(); bloodPumpSetSpeedRPM = bloodPumpRampToSpeedRPM; - setBPSetSpeed( bloodPumpSetSpeedRPM ); + setPeristalticPumpSetSpeed( BP_SIGNED_SET_SPEED ); // resetPIController( PI_CONTROLLER_ID_BLOOD_FLOW, bloodPumpSetSpeedRPM ); bpControlTimerCounter = 0; result = BLOOD_PUMP_CONTROL_TO_TARGET_STATE; @@ -634,7 +640,7 @@ { bloodPumpSetSpeedRPM += BP_RAMP_STEP_SPEED_RPM; bloodPumpSetSpeedRPM = MIN( bloodPumpSetSpeedRPM, bloodPumpRampToSpeedRPM ); - setBPSetSpeed( bloodPumpSetSpeedRPM ); + setPeristalticPumpSetSpeed( BP_SIGNED_SET_SPEED ); } return result; @@ -663,7 +669,7 @@ { resetBloodPumpRPMMovingAverage(); // resetPIController( PI_CONTROLLER_ID_BLOOD_FLOW, bloodPumpSetSpeedRPM ); - setBPSetSpeed( bloodPumpSetSpeedRPM ); + setPeristalticPumpSetSpeed( BP_SIGNED_SET_SPEED ); bpControlTimerCounter = 0; result = BLOOD_PUMP_CONTROL_TO_TARGET_STATE; } @@ -672,7 +678,7 @@ { bloodPumpSetSpeedRPM -= BP_RAMP_STEP_SPEED_RPM; bloodPumpSetSpeedRPM = MAX( bloodPumpSetSpeedRPM, bloodPumpRampToSpeedRPM ); - setBPSetSpeed( bloodPumpSetSpeedRPM ); + setPeristalticPumpSetSpeed( BP_SIGNED_SET_SPEED ); } return result; @@ -702,7 +708,7 @@ // newRPM = runPIController( PI_CONTROLLER_ID_BLOOD_FLOW, tgtFlow, actFlow ); // newRPM = ( newRPM < 0.0F ? 0.0F : newRPM ); bloodPumpSetSpeedRPM = (U32)((S32)(newRPM)); - setBPSetSpeed( bloodPumpSetSpeedRPM ); + setPeristalticPumpSetSpeed( BP_SIGNED_SET_SPEED ); } bpControlTimerCounter = 0; } @@ -805,7 +811,7 @@ payload.measFlow = getMeasuredBloodFlowRate(); payload.measRotorSpd = getMeasuredBloodPumpRotorSpeed(); payload.measPumpSpd = getMeasuredBloodPumpSpeed(); - payload.measCurr = 0.0; // TODO getMeasuredBloodPumpMCCurrent(); + payload.measCurr = 0.0F; // TODO getMeasuredBloodPumpMCCurrent(); payload.setRPM = bloodPumpSetSpeedRPM; payload.rotorCount = getBloodPumpRotorCount(); // if ( ( MODE_PRET == opMode ) || ( MODE_TREA == opMode ) || ( MODE_POST == opMode ) ) Index: firmware/App/Drivers/PeristalticPump.c =================================================================== diff -u -rab35376c6b8ff81a4aa4095eb6c9bd33e1bf46d4 -r18783d138aec872e3f5b73e60e14e3c53bf740ec --- firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision ab35376c6b8ff81a4aa4095eb6c9bd33e1bf46d4) +++ firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision 18783d138aec872e3f5b73e60e14e3c53bf740ec) @@ -27,19 +27,22 @@ // ********** private definitions ********** -#define MAX_PUMP_SPEED_RPM 5000U ///< Maximum speed (in RPM) that a peristaltic pump can be set to. +#define MAX_PUMP_SPEED_RPM 3080U ///< Maximum speed (in RPM) that a peristaltic pump can be set to. +#define BP_PUMP_CMD_GAIN 0.9F ///< Gain for blood pump commanded RPM that must be applied before sending to FPGA. +#define BP_PUMP_CMD_OFFSET 80.0F ///< Offset for blood pump commanded RPM that must be applied before sending to FPGA. +#define BP_PUMP_CMD_CAL(r) ((r) * BP_PUMP_CMD_GAIN + BP_PUMP_CMD_OFFSET ) ///< Macro to calibrate a commanded blood pump RPM before sending to FPGA. -#define BP_PERIOD_SEC 0.00001F ///< Blood pump feedback period in seconds. -#define BP_HZ_TO_RPM_SCALAR 10.0F ///< Blood pump Hz to RPM scalar. -#define BP_PERIOD_TO_HZ(p) ( 1.0F / (F32)((S32)(p) * BP_PERIOD_SEC) ) ///< Blood pump period to Hz conversion macro. -#define BP_HZ_TO_RPM(h) ((h) * BP_HZ_TO_RPM_SCALAR) ///< Blood pump Hz to RPM conversion macro. -#define BP_ZERO_SPEED_PERIOD 0xFFFF ///< Blood pump period reported when pump is stopped. +#define BP_PERIOD_SEC 0.00001F ///< Blood pump feedback period in seconds. +#define BP_HZ_TO_RPM_SCALAR 10.0F ///< Blood pump Hz to RPM scalar. +#define BP_PERIOD_TO_HZ(p) ( 1.0F / (F32)((S32)(p) * BP_PERIOD_SEC) ) ///< Blood pump period to Hz conversion macro. +#define BP_HZ_TO_RPM(h) ((h) * BP_HZ_TO_RPM_SCALAR) ///< Blood pump Hz to RPM conversion macro. +#define BP_ZERO_SPEED_PERIOD 0xFFFF ///< Blood pump period reported when pump is stopped. // ********** private data ********** -static S32 pumpSetSpeedRPM; ///< Current set speed for the pump (in RPM). Negative indicates reverse direction. -static OVERRIDE_F32_T pumpMeasSpeedRPM; ///< Latest measured pump speed (in RPM). -static BOOL pumpHomeRequested; ///< Flag indicates a pump home operation has been requested. +static S32 pumpSetSpeedRPM; ///< Current set speed for the pump (in RPM). Negative indicates reverse direction. +static OVERRIDE_F32_T pumpMeasSpeedRPM; ///< Latest measured pump speed (in RPM). +static BOOL pumpHomeRequested; ///< Flag indicates a pump home operation has been requested. // ********** private function prototypes ********** @@ -78,14 +81,14 @@ *************************************************************************/ void readPeristalticPumps( void ) { - S16 period = (S16)getBPPeriod(); + U16 period = getBPPeriod(); F32 Hz = BP_PERIOD_TO_HZ(period); F32 rpm = BP_HZ_TO_RPM(Hz); // update measured pump speed if ( period != BP_ZERO_SPEED_PERIOD ) { - if ( pumpSetSpeedRPM < 0 ) + if ( pumpSetSpeedRPM < 0 ) // TODO - can we get a real measured direction to base measured speed sign on? { pumpMeasSpeedRPM.data = rpm * -1.0F; } @@ -137,7 +140,8 @@ if ( abs( rpm ) < MAX_PUMP_SPEED_RPM ) { - U16 setRpm = (U16)( abs( rpm ) ); + F32 calRpm = BP_PUMP_CMD_CAL( (F32)rpm ); + U16 setRpm = (U16)( abs( (S32)calRpm ) ); MOTOR_DIR_T dir = MOTOR_DIR_FORWARD; if ( rpm < 0 ) @@ -192,41 +196,5 @@ return result; } - -/************************************************************************* - * TEST SUPPORT FUNCTIONS - *************************************************************************/ - - -/*********************************************************************//** - * @brief - * The testSetPeristalticPumpSetSpeed function sets the pump to a given speed - * (RPM). A negative speed indicates reverse (CCW) direction. - * @details \b Inputs: none - * @details \b Outputs: pumpSetSpeedRPM - * @param message set message from Dialin which includes the speed (RPM) to set - * the peristaltic pump to. - * @return TRUE if set request is successful, FALSE if not - *************************************************************************/ -BOOL testSetPeristalticPumpSetSpeed( MESSAGE_T *message ) -{ - BOOL result = FALSE; - - // Verify tester has logged in with TD and override type is valid - if ( TRUE == isTestingActivated() ) - { - // Verify payload length is valid - if ( sizeof( S32 ) == message->hdr.payloadLen ) - { - S32 speed; - - memcpy( &speed, message->payload, sizeof(S32) ); - result = setPeristalticPumpSetSpeed( (S16)speed ); - } - } - - return result; -} - /**@}*/ Index: firmware/App/Services/Messaging.c =================================================================== diff -u -re69e6a8293508b050a1e039a2182d6a044b5f7d5 -r18783d138aec872e3f5b73e60e14e3c53bf740ec --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision e69e6a8293508b050a1e039a2182d6a044b5f7d5) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 18783d138aec872e3f5b73e60e14e3c53bf740ec) @@ -124,8 +124,7 @@ MSG_ID_TD_BLOOD_PUMP_MEASURED_FLOW_RATE_OVERRIDE_REQUEST, MSG_ID_TD_BLOOD_PUMP_MEASURED_MOTOR_SPEED_OVERRIDE_REQUEST, MSG_ID_TD_BLOOD_PUMP_MEASURED_ROTOR_SPEED_OVERRIDE_REQUEST, - MSG_ID_TD_BLOOD_PUMP_ROTOR_COUNT_OVERRIDE_REQUEST, - MSG_ID_TD_PERISTALTIC_PUMP_SET_SPEED_REQUEST + MSG_ID_TD_BLOOD_PUMP_ROTOR_COUNT_OVERRIDE_REQUEST }; /// Message handling function table @@ -172,8 +171,7 @@ &testMeasuredBloodFlowRateOverride, &testMeasuredBloodPumpSpeedOverride, &testMeasuredBloodPumpRotorSpeedOverride, - &testBloodPumpRotorCountOverride, - &testSetPeristalticPumpSetSpeed + &testBloodPumpRotorCountOverride }; #define NUM_OF_FUNCTION_HANDLERS (sizeof(MSG_FUNCTION_HANDLERS) / sizeof(MsgFuncPtr)) Index: firmware/App/Tasks/TaskPriority.c =================================================================== diff -u -rd9b5f588d81e15ed3849222bed3362e15dbf4b0a -r18783d138aec872e3f5b73e60e14e3c53bf740ec --- firmware/App/Tasks/TaskPriority.c (.../TaskPriority.c) (revision d9b5f588d81e15ed3849222bed3362e15dbf4b0a) +++ firmware/App/Tasks/TaskPriority.c (.../TaskPriority.c) (revision 18783d138aec872e3f5b73e60e14e3c53bf740ec) @@ -62,9 +62,6 @@ // Monitor air trap level sensors execAirTrapMonitor(); - // Monitor blood pump and flow -// execBloodFlowMonitor(); - // Monitor air bubble detectors execBubbles();