76 lines
2.6 KiB
C
76 lines
2.6 KiB
C
/**
|
|
* @file pressureSensor.c
|
|
*
|
|
* @copyright Nehemis SARL reserves all rights even in the event of industrial
|
|
* property rights. We reserve all rights of disposal such as
|
|
* copying and passing on to third parties.
|
|
*
|
|
* @brief
|
|
*
|
|
*/
|
|
|
|
/******************************************************************************
|
|
* Include Header Files
|
|
******************************************************************************/
|
|
#include "pressureSensor.h"
|
|
#include "analogMeasurement.h"
|
|
|
|
/******************************************************************************
|
|
* Type declarations
|
|
******************************************************************************/
|
|
#define PRESSURE_SENSOR_GAIN 0.64f
|
|
/******************************************************************************
|
|
* Macro Constant Declarations
|
|
******************************************************************************/
|
|
|
|
/******************************************************************************
|
|
* Private function Declarations
|
|
******************************************************************************/
|
|
static float PressureSensorReadVoltage(uint32 channel_u32);
|
|
|
|
/******************************************************************************
|
|
* Extern Function Definitions
|
|
******************************************************************************/
|
|
void PressureSensorInit(PressureSensorMain_st *pressureSensor_pst)
|
|
{
|
|
pressureSensor_pst->rawT_f32 = 0.0f;
|
|
if (pressureSensor_pst == NULL)
|
|
{
|
|
/* ERROR */
|
|
}
|
|
}
|
|
|
|
|
|
void PressureSensorGetVal(PressureSensorMain_st *pressureSensor_pst)
|
|
{
|
|
if (pressureSensor_pst == NULL)
|
|
{
|
|
/* ERROR */
|
|
}
|
|
|
|
pressureSensor_pst->rawT_f32 = (PressureSensorReadVoltage(pressureSensor_pst->channel_u32) - 0.5f) / 0.2f;
|
|
pressureSensor_pst->voltage_f32 = PressureSensorReadVoltage(pressureSensor_pst->channel_u32);
|
|
}
|
|
|
|
|
|
/******************************************************************************
|
|
* Private function Definitions
|
|
******************************************************************************/
|
|
/**
|
|
* @brief Function to read ADC voltage data which is directly coming from the sensor.
|
|
*
|
|
* @param pressureSensor_pst : Pointer to main strucutre of the module.
|
|
*
|
|
* @return ADC output voltage based on sensor reading.
|
|
*
|
|
*/
|
|
static float32 PressureSensorReadVoltage(uint32 channel_u32)
|
|
{
|
|
/* Convert ADC value to voltage (assuming 12-bit resolution and 3.3V reference) */
|
|
uint32 adcVal_u32 = 0uL;
|
|
AnalogMeasurementReadData(channel_u32, &adcVal_u32);
|
|
float32 voltage_f32 = (float32)adcVal_u32 * (ANALOG_MEAS_ADC_REF_VOLTAGE / ANALOG_MEAS_ADC_RESOLUTION) / PRESSURE_SENSOR_GAIN;
|
|
|
|
return voltage_f32;
|
|
}
|