add setRefVoltage

This commit is contained in:
2022-12-07 10:49:37 +01:00
parent 39704f6cc3
commit 0fe90f2ed0
4 changed files with 35 additions and 8 deletions

View File

@ -95,6 +95,8 @@ LOCAL osThreadId_t m_pstThreadID = NULL;
LOCAL osEventFlagsId_t m_pstEventID = NULL;
LOCAL osMutexId_t m_pstMutexID = NULL;
LOCAL FLOAT flRefVoltage = INT_ADC_REF;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
@ -198,6 +200,17 @@ BOOL ANPI_boInitializeModule( VOID )
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: ANPI_vSetRefVoltage
// Description: Sets the Reference Voltage for calculating the Voltage
// Parameters: FLOAT flVoltage -> The Ref Voltage measured with an DMM for example
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID ANPI_vSetRefVoltage( FLOAT flVoltage )
{
flRefVoltage = flVoltage;
}
//-------------------------------------------------------------------------------------------------
// Function: ANPI_vTask
// Description: ANPI_vTask
@ -234,7 +247,7 @@ VOID vTask( PVOID arg )
// multiply conversion factor and add the offset
for( U16 u16Cnt = 0; u16Cnt < ANPI_eInNumberOfInputs; u16Cnt++ )
{
flUadc = (FLOAT)au32ADCRawData[u16Cnt] / OVERSAMPLING_DIVISOR / ADC_RES * INT_ADC_REF;
flUadc = (FLOAT)au32ADCRawData[u16Cnt] / OVERSAMPLING_DIVISOR / ADC_RES * flRefVoltage;
aflValues[u16Cnt] = flUadc * m_aflConversionFactor[u16Cnt] - m_aflOffset[u16Cnt];
}

View File

@ -94,6 +94,7 @@ typedef enum
//=================================================================================================
BOOL ANPI_boInitializeModule( VOID );
VOID ANPI_vSetRefVoltage( FLOAT flVoltage );
#ifdef __cplusplus
}

View File

@ -45,7 +45,7 @@
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define INT_DAC_REF (3.3f)// int. reference voltage for conversion
//=================================================================================================
// Section: MACROS
@ -75,6 +75,7 @@
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
LOCAL FLOAT flRefVoltage = INT_DAC_REF;
//=================================================================================================
// Section: LOCAL CONSTANTS
@ -87,7 +88,7 @@
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
U32 u32ConvertVoltagetoRaw( FLOAT Voltage );
U32 u32ConvertVoltagetoRaw( FLOAT flVoltage );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
@ -124,6 +125,17 @@ BOOL ANPO_boInitializeModule( VOID )
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: ANPO_vSetRefVoltage
// Description: Sets the Reference Voltage for calculating the Voltage
// Parameters: FLOAT flVoltage -> The Ref Voltage measured with an DMM for example
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID ANPO_vSetRefVoltage( FLOAT flVoltage )
{
flRefVoltage = flVoltage;
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
@ -135,10 +147,10 @@ BOOL ANPO_boInitializeModule( VOID )
// Parameters: FLOAT Voltage
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ANPO_boSetVoltage( FLOAT Voltage ){
BOOL ANPO_boSetVoltage( FLOAT flVoltage ){
BOOL boOK = TRUE;
U32 u32RawData = u32ConvertVoltagetoRaw( Voltage );
U32 u32RawData = u32ConvertVoltagetoRaw( flVoltage );
boOK &= HAL_DAC_SetValue( &hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, u32RawData );
@ -151,10 +163,10 @@ BOOL ANPO_boSetVoltage( FLOAT Voltage ){
// Parameters: FLOAT Voltage
// Returns: U32
//-------------------------------------------------------------------------------------------------
U32 u32ConvertVoltagetoRaw( FLOAT Voltage ){
U32 u32ConvertVoltagetoRaw( FLOAT flVoltage ){
U32 RawData;
RawData = Voltage * 4095 / 3.3;
RawData = flVoltage * 4095 / flRefVoltage;
return RawData;
}

View File

@ -87,7 +87,8 @@ typedef enum
//=================================================================================================
BOOL ANPO_boInitializeModule( VOID );
BOOL ANPO_boSetVoltage( FLOAT Voltage );
BOOL ANPO_boSetVoltage( FLOAT flVoltage );
VOID ANPO_vSetRefVoltage( FLOAT flVoltage );
#ifdef __cplusplus
}