Index: PressureCommon.c =================================================================== diff -u -rb5356a56158ddf8c2abcdf6bbe3680b4358ff594 -r16f118933184adf7f5362942d069fdc0f7b67f90 --- PressureCommon.c (.../PressureCommon.c) (revision b5356a56158ddf8c2abcdf6bbe3680b4358ff594) +++ PressureCommon.c (.../PressureCommon.c) (revision 16f118933184adf7f5362942d069fdc0f7b67f90) @@ -24,12 +24,9 @@ // ********** private definitions ********** -#define BAR_TO_MMHG ( 750.062F ) ///< Conversion factor for converting bar to mmHg. -#define CONV_FACTOR ( 1310.8F ) ///< Range conversion for 10 bar. - #define PRESSURE_FS ( 14746.0F ) ///< Pressure sensor full scale output. #define PRESSURE_ZERO ( 1638.0F ) ///< Pressure sensor zero value. -#define PRESSURE_FS_MINUS_ZERO ( 13108.0F ) ///< Pressure sensor fullscale and zero difference. +#define PRESSURE_FS_MINUS_ZERO ( PRESSURE_FS - PRESSURE_ZERO ) ///< Pressure sensor fullscale and zero difference. #define PRESSURE_TEMP_RESOLUTION ( 2047.0F ) ///< Pressure sensor temperature resoultion 2^11 bit equals to 2047. #define PRESSURE_TEMP_MULTIPLIER ( 200.0F ) ///< Pressure sensor multiplier @@ -43,22 +40,21 @@ /*********************************************************************//** * @brief - * The convertPressureReading2mmHg function converts a raw pressure ADC - * reading from a pressure sensor to mmHg. + * The convertPressureReading function converts a raw pressure ADC + * reading from a pressure sensor to desired units based on given min and + * max range of values. * @details \b Inputs: none * @details \b Outputs: none - * @return Pressure reading in mmHg + * @param counts Pressure sensor reading (in counts) read from FPGA. + * @param min Minimum pressure range in desired units + * @param max Maximum pressure range in desired units + * @return Pressure reading in desired units *************************************************************************/ -F32 convertPressureReading2mmHg( S16 counts ) -{ - F32 pressure_bar, mmHg; +F32 convertPressureReading( S16 counts, F32 min, F32 max ) +{ // Convert raw pressure counts to desired units + F32 pressure_bar = ( ( max - min ) * ( (F32)counts - PRESSURE_ZERO ) / PRESSURE_FS_MINUS_ZERO ) + min; - // Convert raw pressure counts to bar and then to mmHg - pressure_bar = PRESSURE_FS_MINUS_ZERO * ( ( (F32)counts - PRESSURE_ZERO ) / PRESSURE_FS_MINUS_ZERO ) + PRESSURE_ZERO; - mmHg = ( pressure_bar - PRESSURE_ZERO ) / CONV_FACTOR ; - - return mmHg; - //return pressure_bar; + return pressure_bar; } /*********************************************************************//**