Index: firmware/App/Controllers/BloodFlow.c =================================================================== diff -u -r5dea4d2934a06e63b87c74732d5d5d7756bdc62a -rbd37ce75271151436de0bb6de9f75123d8251396 --- firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision 5dea4d2934a06e63b87c74732d5d5d7756bdc62a) +++ firmware/App/Controllers/BloodFlow.c (.../BloodFlow.c) (revision bd37ce75271151436de0bb6de9f75123d8251396) @@ -76,7 +76,7 @@ #define BP_RATE_FROM_RPM( rpm ) ( rpm / 5 ) ///< Macro to estimate a flow rate (mL/min) from a given speed (RPM). #define BP_RPM_FROM_RATE( rate ) ( rate * 5 ) ///< Macro to estimate a pump speed (RPM) from a given flow rate (mL/min). -#define BP_RAMP_STEP_SPEED_RPM 5 ///< Blood pump ramp step size (in RPM). +#define BP_RAMP_STEP_SPEED_RPM 10 ///< Blood pump ramp step size (in RPM). #define BP_FLOW_ALPHA_Y_INTERCEPT 1.11F ///< Y intercept used for alpha flow coefficient calculation. #define BP_FLOW_WEAR_A_TERM 0.00000000896F ///< A term used for wear portion of alpha flow coefficient. @@ -508,7 +508,7 @@ // 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; - filterBloodPumpRPMReadings( (F32)getPeristalticPumpMeasSpeed() ); + filterBloodPumpRPMReadings( getPeristalticPumpMeasSpeed() ); bloodPumpSpeedRPM.data = filteredBloodPumpSpeed; bloodPumpDirection = ( getMeasuredBloodPumpSpeed() < 0.0F ? MOTOR_DIR_REVERSE : MOTOR_DIR_FORWARD ); //measuredBloodFlowRate.data = calcBloodFlow(); // TODO-restore when flow estimation function is implemented @@ -584,6 +584,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 ); isBloodPumpOn = TRUE; @@ -661,7 +662,6 @@ else if ( bloodPumpSetSpeedRPM <= bloodPumpRampToSpeedRPM ) { resetBloodPumpRPMMovingAverage(); - bloodPumpSetSpeedRPM = 0; // resetPIController( PI_CONTROLLER_ID_BLOOD_FLOW, bloodPumpSetSpeedRPM ); setBPSetSpeed( bloodPumpSetSpeedRPM ); bpControlTimerCounter = 0; @@ -805,15 +805,15 @@ payload.measFlow = getMeasuredBloodFlowRate(); payload.measRotorSpd = getMeasuredBloodPumpRotorSpeed(); payload.measPumpSpd = getMeasuredBloodPumpSpeed(); -// payload.measCurr = getMeasuredBloodPumpMCCurrent(); + payload.measCurr = 0.0; // TODO getMeasuredBloodPumpMCCurrent(); payload.setRPM = bloodPumpSetSpeedRPM; payload.rotorCount = getBloodPumpRotorCount(); - if ( ( MODE_PRET == opMode ) || ( MODE_TREA == opMode ) || ( MODE_POST == opMode ) ) - { // prescribed flow only available in treatment modes +// if ( ( MODE_PRET == opMode ) || ( MODE_TREA == opMode ) || ( MODE_POST == opMode ) ) +// { // prescribed flow only available in treatment modes // payload.presFlow = getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ); // TODO - restore when Tx Param Mode implemented // } // else -// { + { payload.presFlow = 0; } payload.rotorHall = ( hallSensor > 0 ? 0 : 1 ); // 1=home, 0=not home Index: firmware/App/Drivers/PeristalticPump.c =================================================================== diff -u -r87d705fcf977af12b7b034735fa5867f2daea2b9 -rbd37ce75271151436de0bb6de9f75123d8251396 --- firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision 87d705fcf977af12b7b034735fa5867f2daea2b9) +++ firmware/App/Drivers/PeristalticPump.c (.../PeristalticPump.c) (revision bd37ce75271151436de0bb6de9f75123d8251396) @@ -27,13 +27,18 @@ // ********** 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 5000U ///< Maximum speed (in RPM) that a peristaltic pump can be set to. +#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. + // ********** 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 +54,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 +77,18 @@ *************************************************************************/ void readPeristalticPumps( void ) { + S16 period = (S16)getBPPeriod(); + F32 Hz = BP_PERIOD_TO_HZ(period); + F32 rpm = BP_HZ_TO_RPM(Hz); + // update measured pump speed if ( pumpSetSpeedRPM < 0 ) { - pumpMeasSpeedRPM.data = (S32)( (S16)getBPSpeed() * -1 ); + pumpMeasSpeedRPM.data = rpm * -1.0F; } else { - pumpMeasSpeedRPM.data = (S32)( (S16)getBPSpeed() ); + pumpMeasSpeedRPM.data = rpm; } // clear home command if previously requested @@ -163,9 +172,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 ) { Index: firmware/App/Drivers/PeristalticPump.h =================================================================== diff -u -rd9b5f588d81e15ed3849222bed3362e15dbf4b0a -rbd37ce75271151436de0bb6de9f75123d8251396 --- firmware/App/Drivers/PeristalticPump.h (.../PeristalticPump.h) (revision d9b5f588d81e15ed3849222bed3362e15dbf4b0a) +++ firmware/App/Drivers/PeristalticPump.h (.../PeristalticPump.h) (revision bd37ce75271151436de0bb6de9f75123d8251396) @@ -41,7 +41,7 @@ BOOL setPeristalticPumpSetSpeed( S32 rpm ); S32 getPeristalticPumpSetSpeed( void ); -S32 getPeristalticPumpMeasSpeed( void ); +F32 getPeristalticPumpMeasSpeed( void ); void cmdPeristalticPumpHome( void ); Index: firmware/App/Drivers/PressureSensor.c =================================================================== diff -u -ra9c88c428c6ab7e9bdaa273826c1fde1b0a8a1f5 -rbd37ce75271151436de0bb6de9f75123d8251396 --- firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision a9c88c428c6ab7e9bdaa273826c1fde1b0a8a1f5) +++ firmware/App/Drivers/PressureSensor.c (.../PressureSensor.c) (revision bd37ce75271151436de0bb6de9f75123d8251396) @@ -29,11 +29,11 @@ // ********** private definitions ********** -#define BAR_TO_MMHG ( 750.062F ) ///< Conversion factor for converting bar to mmHg. - #define PRES_SENSORS_ZERO_OFFSET ( 1638.0F ) ///< Zero offset for pressure sensor readings. #define PRES_SENSORS_DIVISOR ( 14745.0F - PRES_SENSORS_ZERO_OFFSET ) ///< Divisor for pressure sensor conversion from counts to bars. -#define PRES_SENSORS_RANGE_IN_BARS ( 1.6F - 0.0F ) ///< Range (in bars) of the pressure sensors (0..1.6). +#define PRESSURE_MIN_PSI ( -30.0F ) ///< Minimum of scale for pressure sensor reading (in PSI). +#define PRESSURE_MAX_PSI ( 30.0F ) ///< Maximum of scale for pressure sensor reading (in PSI). +#define PSI_TO_MMHG ( 51.7149F ) ///< Conversion factor for converting PSI to mmHg. #define PRES_SENSORS_COUNT_ERROR_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Pressure sensors read and error count timeout in milliseconds. @@ -57,8 +57,7 @@ // ********** private function prototypes ********** static void checkPressureSensors( void ); -static F32 convertPressureRdg2mmHg( S16 counts ); -static F32 getPresureReadingFromFPGARegReading( U16 fpgaReg ); +static F32 convertPressureRdg2mmHg( U16 counts ); static U32 getPressureStatusFromFPGARegReading( U16 fpgaReg ); /*********************************************************************//** @@ -153,36 +152,21 @@ * @param counts the raw pressure reading in counts from the FPGA * @return the pressure in mmHg *************************************************************************/ -static F32 convertPressureRdg2mmHg( S16 counts ) +static F32 convertPressureRdg2mmHg( U16 counts ) { - F32 rdg = getPresureReadingFromFPGARegReading( counts ); - F32 bar = ( ( rdg - PRES_SENSORS_ZERO_OFFSET ) * ( PRES_SENSORS_RANGE_IN_BARS ) / ( PRES_SENSORS_DIVISOR ) ); - F32 mmHg = bar * BAR_TO_MMHG; + S16 rdg = (S16)( counts & FPGA_PRESSURE_READING_BITS_MASK ); + F32 presPSI; + F32 mmHg; + // If the arterial pressure status is normal, convert the counts to pressure in mmHg + presPSI = ( ( (F32)rdg - PRES_SENSORS_ZERO_OFFSET ) *( PRESSURE_MAX_PSI - PRESSURE_MIN_PSI ) / PRES_SENSORS_DIVISOR ) + PRESSURE_MIN_PSI; + mmHg = presPSI * PSI_TO_MMHG; + return mmHg; } /*********************************************************************//** * @brief - * The getPresureReadingFromFPGARegReading function extracts the signed - * pressure reading (in counts) from the FPGA register reading. - * @details \b Inputs: none - * @details \b Outputs: none - * @param fpgaReg the value read from the FPGA register - * @return the pressure portion of the FPGA register value, sign extended - *************************************************************************/ -static F32 getPresureReadingFromFPGARegReading( U16 fpgaReg ) -{ -// U16 rdg = fpgaReg & FPGA_PRESSURE_READING_BITS_MASK; // mask off status bits -// S16 ext = signExtend16( rdg, FPGA_PRESSURE_READING_BIT_COUNT - 1 ); // sign extend reading in case it's negative -// -// return (F32)ext; - // TODO - fix sign extension - return (F32)((S16)fpgaReg); -} - -/*********************************************************************//** - * @brief * The getPressureStatusFromFPGARegReading function extracts the status * from the FPGA register reading. * @details \b Inputs: none Index: firmware/App/Services/FpgaTD.c =================================================================== diff -u -ra9c88c428c6ab7e9bdaa273826c1fde1b0a8a1f5 -rbd37ce75271151436de0bb6de9f75123d8251396 --- firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision a9c88c428c6ab7e9bdaa273826c1fde1b0a8a1f5) +++ firmware/App/Services/FpgaTD.c (.../FpgaTD.c) (revision bd37ce75271151436de0bb6de9f75123d8251396) @@ -105,7 +105,7 @@ U08 BEMStatus; ///< Reg 284. BEM status. U08 BEMEncStatus; ///< Reg 285. BEM encoder status. S32 BEMEncPosition; ///< Reg 286. BEM encoder position. - S16 BPSpeed; ///< Reg 290. BP measured speed (RPM). + S16 BPPeriod; ///< Reg 290. BP measured period (10 uSec). S16 BPTorque; ///< Reg 292. BP measured torque. S16 BPSpeedFromHall; ///< Reg 294. BP measured speed from hall sensor(s). S16 VBVCmdPosition; ///< Reg 296. VBV commanded position (200 steps/rev). @@ -491,18 +491,15 @@ /*********************************************************************//** * @brief - * The getBPSpeed function gets the latest blood pump speed (in RPM) + * The getBPPeriod function gets the latest blood pump period (in 10uSec) * from the FPGA. * @details \b Inputs: fpgaSensorReadings * @details \b Outputs: none - * @return Latest blood pump speed. + * @return Latest blood pump period. *************************************************************************/ -U16 getBPSpeed( void ) +U16 getBPPeriod( void ) { - // TODO - remove this test code - fpgaActuatorSetPoints.fpgaGenWrRd = 0x1234; - - return fpgaSensorReadings.BPSpeed; + return fpgaSensorReadings.BPPeriod; } /*********************************************************************//** Index: firmware/App/Services/FpgaTD.h =================================================================== diff -u -r87d705fcf977af12b7b034735fa5867f2daea2b9 -rbd37ce75271151436de0bb6de9f75123d8251396 --- firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision 87d705fcf977af12b7b034735fa5867f2daea2b9) +++ firmware/App/Services/FpgaTD.h (.../FpgaTD.h) (revision bd37ce75271151436de0bb6de9f75123d8251396) @@ -59,7 +59,7 @@ void homeBP( void ); void resetBPHomeRequest( void ); void setBPSetSpeed( U16 rpm ); -U16 getBPSpeed( void ); +U16 getBPPeriod( void ); U16 getBloodPumpHallSensorCount( void ); U08 getBloodPumpHallSensorStatus( void );