Index: firmware/App/Drivers/PeristalticPump.c =================================================================== diff -u -r87d705fcf977af12b7b034735fa5867f2daea2b9 -rf3a26c402a2ec88f5ee7dbb8eb7127ab5b4692aa --- firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision 87d705fcf977af12b7b034735fa5867f2daea2b9) +++ firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision f3a26c402a2ec88f5ee7dbb8eb7127ab5b4692aa) @@ -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 H4_PUMP_CMD_GAIN 0.9F ///< Gain for blood pump commanded RPM that must be applied before sending to FPGA. +#define H4_PUMP_CMD_OFFSET 80.0F ///< Offset for blood pump commanded RPM that must be applied before sending to FPGA. +#define H4_PUMP_CMD_CAL(r) ((r) * H4_PUMP_CMD_GAIN + H4_PUMP_CMD_OFFSET ) ///< Macro to calibrate a commanded blood pump RPM before sending to FPGA. +#define H4_PERIOD_SEC 0.00001F ///< Blood pump feedback period in seconds. +#define H4_HZ_TO_RPM_SCALAR 10.0F ///< Blood pump Hz to RPM scalar. +#define H4_PERIOD_TO_HZ(p) ( 1.0F / (F32)((S32)(p) * H4_PERIOD_SEC) ) ///< Blood pump period to Hz conversion macro. +#define H4_HZ_TO_RPM(h) ((h) * H4_HZ_TO_RPM_SCALAR) ///< Blood pump Hz to RPM conversion macro. +#define H4_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,15 +58,15 @@ { 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 ); - resetBPHomeRequest(); - setBPSetSpeed( 0 ); - setBPEnabled( TRUE ); + setH4Direction( MOTOR_DIR_FORWARD ); + resetH4HomeRequest(); + setH4SetSpeed( 0 ); + setH4Enabled( TRUE ); } /*********************************************************************//** @@ -72,21 +81,32 @@ *************************************************************************/ void readPeristalticPumps( void ) { + U16 period = getH4Period(); + F32 Hz = H4_PERIOD_TO_HZ(period); + F32 rpm = H4_HZ_TO_RPM(Hz); + // update measured pump speed - if ( pumpSetSpeedRPM < 0 ) + if ( period != H4_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 if ( TRUE == pumpHomeRequested ) { pumpHomeRequested = FALSE; - resetBPHomeRequest(); + resetH4HomeRequest(); } } @@ -100,7 +120,7 @@ void cmdPeristalticPumpHome( void ) { pumpHomeRequested = TRUE; - homeBP(); + homeH4(); } /*********************************************************************//** @@ -120,16 +140,17 @@ if ( abs( rpm ) < MAX_PUMP_SPEED_RPM ) { - U16 setRpm = (U16)( abs( rpm ) ); + F32 calRpm = H4_PUMP_CMD_CAL( (F32)rpm ); + U16 setRpm = (U16)( abs( (S32)calRpm ) ); MOTOR_DIR_T dir = MOTOR_DIR_FORWARD; if ( rpm < 0 ) { dir = MOTOR_DIR_REVERSE; } pumpSetSpeedRPM = rpm; - setBPDirection( dir ); - setBPSetSpeed( setRpm ); + setH4Direction( dir ); + setH4SetSpeed( setRpm ); result = TRUE; } else @@ -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; -} - /**@}*/