TECware/Core/Drivers/ANPO_AnalogPortsOut.c
2021-11-17 11:35:41 +01:00

170 lines
6.6 KiB
C
Raw Blame History

//=================================================================================================
//
// Company: Paul Scherrer Institut
// 5232 Villigen PSI
// Switzerland
//
//-------------------------------------------------------------------------------------------------
//
// Project: Peltier Controller V2
// Author: Noah Piqu<71> (noah.pique@psi.ch)
//
//-------------------------------------------------------------------------------------------------
//
// Module: Analog Ports Output
// Filename: ANPO_AnalogPortsOut.c
// Date: Handled by Subversion (version control system)
// Revision: Handled by Subversion (version control system)
// History: Handled by Subversion (version control system)
//
//-------------------------------------------------------------------------------------------------
//
// Description: This source file contains all functions dealing with the analog outputs ports
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "../PDEF_ProjectDefinitions.h"
#include "ANPO_AnalogPortsOut.h"
//Application
//#include "../Application/ELOG_ErrorLogger.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: ENUMERATIONS
// Description: Definition of local enumerations (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: STRUCTURES
// Description: Definition of local Structures (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL VARIABLES
// Description: Definition of local variables (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
U32 u32ConvertVoltagetoRaw( FLOAT Voltage );
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
//=================================================================================================
extern DAC_HandleTypeDef hdac1;
//=================================================================================================
// Section: GLOBAL FUNCTIONS
// Description: Definition (implementation) of global functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: ANPO_boInitializeModule
// Description: Initializes the module. Function must be called once immediately after power-up.
// Parameters: None
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ANPO_boInitializeModule( VOID )
{
BOOL boOK = TRUE;
HAL_DAC_Start(&hdac1, DAC_CHANNEL_1);
return( boOK );
}
//-------------------------------------------------------------------------------------------------
// Function: ANPO_boSetVoltage
// Description: Sets the DAC Output to a specific Voltage
// Parameters: FLOAT Voltage
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ANPO_boSetVoltage( FLOAT Voltage ){
BOOL boOK = TRUE;
U32 RawData = u32ConvertVoltagetoRaw( Voltage );
boOK &= HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, RawData);
return( boOK );
}
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: u32ConvertVoltagetoRaw
// Description: Convert Voltage to Raw value for the DAC
// Parameters: FLOAT Voltage
// Returns: U32
//-------------------------------------------------------------------------------------------------
U32 u32ConvertVoltagetoRaw( FLOAT Voltage ){
U32 RawData;
RawData = Voltage * 4095 / 3.3;
return RawData;
}