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