Index: PressureCommon.c =================================================================== diff -u --- PressureCommon.c (revision 0) +++ PressureCommon.c (revision a6e50d961f79536e62469297ce39f3fb258a25e1) @@ -0,0 +1,85 @@ +/************************************************************************** +* +* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file PressureCommon.c +* +* @author (last) Sean +* @date (last) 22-Aug-2024 +* +* @author (original) Sean +* @date (original) 22-Aug-2024 +* +***************************************************************************/ + +#include "PressureCommon.h" + +/** + * @addtogroup PressureCommon + * @{ + */ + +// ********** private definitions ********** + +#define KPA_TO_MMHG ( 7.50062F ) ///< Conversion factor for converting kPa to mmHg. + +#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. + +/// Scaler value for converting pressure readings to kPa. +#define PRESSURE_SCALER ( ( PRESSURE_FS - PRESSURE_ZERO ) / \ + ( PRESSURE_FS_RATIO - PRESSURE_ZERO_RATIO ) ) + +#define PRESSURE_TEMP_DIVIDER ( 65536.0F ) ///< Pressure sensor temperature divider. +#define PRESSURE_TEMP_OFFSET ( 25.0F ) ///< Pressure sensor temperature offset. + +// ********** private data ********** + + +// ********** private function prototypes ********** + + +/*********************************************************************//** + * @brief + * The convertPressureReading2mmHg function converts a raw pressure ADC + * reading from a pressure sensor to mmHg. + * @details \b Inputs: none + * @details \b Outputs: none + * @return Pressure reading in mmHg + *************************************************************************/ +F32 convertPressureReading2mmHg( S32 counts ) +{ + F32 pressure_kPa, mmHg; + + // Convert raw pressure counts to kPa and then to mmHg + pressure_kPa = ( ( (F32)counts / PRESSURE_DIVIDER ) - PRESSURE_ZERO_RATIO ) * PRESSURE_SCALER; + mmHg = pressure_kPa * KPA_TO_MMHG; + + return mmHg; +} + +/*********************************************************************//** + * @brief + * The convertPressureTempReading2DegC function converts a raw temperature + * ADC reading from a pressure sensor to Celsius. + * @details \b Inputs: none + * @details \b Outputs: none + * @return Temperature reading in Celsius + *************************************************************************/ +F32 convertPressureTempReading2DegC( S32 counts ) +{ + F32 degC; + + // Convert raw pressure sensor temperatures to deg C + degC = ( (F32)counts / PRESSURE_TEMP_DIVIDER ) + PRESSURE_TEMP_OFFSET; + + return degC; +} + +/**@}*/ Index: PressureCommon.h =================================================================== diff -u --- PressureCommon.h (revision 0) +++ PressureCommon.h (revision a6e50d961f79536e62469297ce39f3fb258a25e1) @@ -0,0 +1,42 @@ +/************************************************************************** +* +* Copyright (c) 2024-2024 Diality Inc. - All Rights Reserved. +* +* THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN +* WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. +* +* @file PressureCommon.h +* +* @author (last) Sean +* @date (last) 22-Aug-2024 +* +* @author (original) Sean +* @date (original) 22-Aug-2024 +* +***************************************************************************/ + +#ifndef __PRESSURE_COMMON_H__ +#define __PRESSURE_COMMON_H__ + +#include "TDCommon.h" + +/** + * @defgroup PressureCommon PressureCommon + * @brief The Pressure Sensor unit provides common conversion functions for + * MicroSensor (MPM258) pressure sensors. + * + * @addtogroup PressureCommon + * @{ + */ + +// ********** public definitions ********** + + +// ********** public function prototypes ********** + +F32 convertPressureReading2mmHg( S32 counts ); +F32 convertPressureTempReading2DegC( S32 counts ); + +/**@}*/ + +#endif