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

@ -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;
}