Index: PressureCommon.c =================================================================== diff -u -re17124f84bdd75e18007f27e0cb38471f119337e -r652b47f19535d47eeee5c3ec97d8f66a93fade63 --- PressureCommon.c (.../PressureCommon.c) (revision e17124f84bdd75e18007f27e0cb38471f119337e) +++ PressureCommon.c (.../PressureCommon.c) (revision 652b47f19535d47eeee5c3ec97d8f66a93fade63) @@ -7,61 +7,54 @@ * * @file PressureCommon.c * -* @author (last) Sean -* @date (last) 22-Aug-2024 +* @author (last) Vinayakam Mani +* @date (last) 13-Sep-2024 * * @author (original) Sean * @date (original) 22-Aug-2024 * ***************************************************************************/ -#include "PressureCommon.h" - +#include "PressureCommon.h" + /** * @addtogroup PressureCommon * @{ */ -// ********** private definitions ********** - -#define BAR_TO_MMHG ( 750.062F ) ///< Conversion factor for converting bar to mmHg. +// ********** private definitions ********** -#define PRESSURE_FS ( 80.0F ) ///< Pressure sensor full scale percentage. -#define PRESSURE_ZERO ( 0.0F ) ///< Pressure sensor zero value. -#define PRESSURE_FS_RATIO ( 0.9F ) ///< Pressure sensor full scale ratio. -#define PRESSURE_ZERO_RATIO ( 0.1F ) ///< Pressure sensor zero ratio. -#define PRESSURE_DIVIDER ( 8388608.0F ) ///< Pressure sensor divider. +#define PRESSURE_FS ( 14746.0F ) ///< Pressure sensor full scale output. +#define PRESSURE_ZERO ( 1638.0F ) ///< Pressure sensor zero value. +#define PRESSURE_FS_MINUS_ZERO ( PRESSURE_FS - PRESSURE_ZERO ) ///< Pressure sensor fullscale and zero difference. -/// Scaler value for converting pressure readings from kPa to bar (100th). -#define PRESSURE_SCALER ( ( PRESSURE_FS - PRESSURE_ZERO ) / \ - ( PRESSURE_FS_RATIO - PRESSURE_ZERO_RATIO ) ) +#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 +#define PRESSURE_TEMP_OFFSET ( 50.0F ) ///< Pressure sensor temperature offset. -#define PRESSURE_TEMP_DIVIDER ( 65536.0F ) ///< Pressure sensor temperature divider. -#define PRESSURE_TEMP_OFFSET ( 25.0F ) ///< Pressure sensor temperature offset. +// ********** private data ********** -// ********** private data ********** - - + // ********** private function prototypes ********** /*********************************************************************//** * @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( S32 counts ) -{ - F32 pressure_bar, mmHg; +F32 convertPressureReading( S16 counts, F32 min, F32 max ) +{ // Convert raw pressure counts to desired units + F32 pressure = ( ( max - min ) * ( (F32)counts - PRESSURE_ZERO ) / PRESSURE_FS_MINUS_ZERO ) + min; - // Convert raw pressure counts to bar and then to mmHg - pressure_bar = ( ( (F32)counts / PRESSURE_DIVIDER ) - PRESSURE_ZERO_RATIO ) * PRESSURE_SCALER; - mmHg = pressure_bar * BAR_TO_MMHG; - - return mmHg; + return pressure; } /*********************************************************************//** @@ -72,14 +65,14 @@ * @details \b Outputs: none * @return Temperature reading in Celsius *************************************************************************/ -F32 convertPressureTempReading2DegC( S32 counts ) +F32 convertPressureTempReading2DegC( S16 counts ) { F32 degC; // Convert raw pressure sensor temperatures to deg C - degC = ( (F32)counts / PRESSURE_TEMP_DIVIDER ) + PRESSURE_TEMP_OFFSET; + degC = ( ( (F32)counts / PRESSURE_TEMP_RESOLUTION ) * PRESSURE_TEMP_MULTIPLIER ) - PRESSURE_TEMP_OFFSET; return degC; } - + /**@}*/