Index: firmware/App/Drivers/PeristalticPump.c =================================================================== diff -u -r87d705fcf977af12b7b034735fa5867f2daea2b9 -r56100135135bb715d316b5fd002a4a4951b9334a --- firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision 87d705fcf977af12b7b034735fa5867f2daea2b9) +++ firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision 56100135135bb715d316b5fd002a4a4951b9334a) @@ -27,13 +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. + // ********** private data ********** -static S32 pumpSetSpeedRPM; ///< Current set speed for the pump (in RPM). Negative indicates reverse direction. -static OVERRIDE_S32_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 ********** @@ -49,9 +58,9 @@ { pumpHomeRequested = FALSE; pumpSetSpeedRPM = 0; - pumpMeasSpeedRPM.data = 0; - pumpMeasSpeedRPM.ovData = 0; - pumpMeasSpeedRPM.ovInitData = 0; + pumpMeasSpeedRPM.data = 0.0F; + pumpMeasSpeedRPM.ovData = 0.0F; + pumpMeasSpeedRPM.ovInitData = 0.0F; pumpMeasSpeedRPM.override = OVERRIDE_RESET; setBPDirection( MOTOR_DIR_FORWARD ); @@ -72,14 +81,25 @@ *************************************************************************/ void readPeristalticPumps( void ) { + U16 period = getBPPeriod(); + F32 Hz = BP_PERIOD_TO_HZ(period); + F32 rpm = BP_HZ_TO_RPM(Hz); + // update measured pump speed - if ( pumpSetSpeedRPM < 0 ) + if ( period != BP_ZERO_SPEED_PERIOD ) { - pumpMeasSpeedRPM.data = (S32)( (S16)getBPSpeed() * -1 ); + if ( pumpSetSpeedRPM < 0 ) // TODO - can we get a real measured direction to base measured speed sign on? + { + pumpMeasSpeedRPM.data = rpm * -1.0F; + } + else + { + pumpMeasSpeedRPM.data = rpm; + } } else { - pumpMeasSpeedRPM.data = (S32)( (S16)getBPSpeed() ); + pumpMeasSpeedRPM.data = 0.0F; } // clear home command if previously requested @@ -120,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 ) @@ -163,9 +184,9 @@ * @details \b Outputs: none * @return Latest measured pump speed in RPM. *************************************************************************/ -S32 getPeristalticPumpMeasSpeed( void ) +F32 getPeristalticPumpMeasSpeed( void ) { - S32 result = pumpMeasSpeedRPM.data; + F32 result = pumpMeasSpeedRPM.data; if ( OVERRIDE_KEY == pumpMeasSpeedRPM.override ) { @@ -175,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; -} - /**@}*/