add ANPI to VARH
This commit is contained in:
@ -23,8 +23,6 @@
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
@ -33,10 +31,13 @@
|
||||
#include "../PDEF_ProjectDefinitions.h"
|
||||
#include "ANPI_AnalogPortsIn.h"
|
||||
|
||||
#include "PECO_PeltierController.h"
|
||||
|
||||
|
||||
//Application
|
||||
//#include "../Application/ELOG_ErrorLogger.h"
|
||||
#include "../Application/VARH_VariableHandler.h"
|
||||
|
||||
// Drivers
|
||||
#include "PECO_PeltierController.h"
|
||||
|
||||
// Toolbox
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
@ -64,8 +65,8 @@
|
||||
|
||||
#define ANPI_FLAGS_ALL ( ANPI_ADC_HALF_COMPLETE | ANPI_ADC_FULL_COMPLETE )
|
||||
|
||||
#define OVERSAMPLING_DIVISOR 16.0f // calculated with parameters from hardware oversampling
|
||||
// 6 bits(64x) - 2 bit shift = 4bit -> 16x
|
||||
#define OVERSAMPLING_DIVISOR 16.0f // calculated with parameters from hardware oversampling
|
||||
// 6 bits(64x) - 2 bit shift = 4bit -> 16x
|
||||
|
||||
//=================================================================================================
|
||||
// Section: MACROS
|
||||
@ -96,8 +97,6 @@ typedef struct
|
||||
// Description: Definition of local variables (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
LOCAL FLOAT m_aflValues[ANPI_eInNumberOfInputs]; // values
|
||||
|
||||
LOCAL U16 m_au16ADCDataBuffer[BUFFER_SIZE];
|
||||
|
||||
LOCAL osThreadId_t m_pstThreadID = NULL;
|
||||
@ -113,8 +112,7 @@ LOCAL osMutexId_t m_pstMutexID = NULL;
|
||||
// Order must fit enumeration "ANPI_EnAnalogInput"
|
||||
LOCAL CONST FLOAT m_aflConversionFactor[ANPI_eInNumberOfInputs] =
|
||||
{
|
||||
34.103f * 1.0f / ADC_RES * INT_ADC_REF, // 00 ANPI_eControlVoltage
|
||||
10, // 01 ANPI_eSupplyVoltage24V
|
||||
10, // 01 ANPI_eSupplyVoltage24V
|
||||
-5, // 02 ANPI_eSupplyCurrent24V
|
||||
10, // 03 ANPI_eOutputVoltage
|
||||
5, // 04 ANPI_eOutputCurrent
|
||||
@ -123,7 +121,6 @@ LOCAL CONST FLOAT m_aflConversionFactor[ANPI_eInNumberOfInputs] =
|
||||
// Order must fit enumeration "ANPI_EnAnalogInput"
|
||||
LOCAL CONST FLOAT m_aflOffset[ANPI_eInNumberOfInputs] =
|
||||
{
|
||||
20.088f, // 00 ANPI_eControlVoltage
|
||||
0.0f, // 01 ANPI_eSupplyVoltage24V
|
||||
2.5f, // 02 ANPI_eSupplyCurrent24V
|
||||
4.5f, // 03 ANPI_eOutputVoltage
|
||||
@ -133,7 +130,6 @@ LOCAL CONST FLOAT m_aflOffset[ANPI_eInNumberOfInputs] =
|
||||
// initial values. Order must fit enumeration "ANPI_EnAnalogInput"
|
||||
LOCAL CONST FLOAT m_afInitValues[ANPI_eInNumberOfInputs] =
|
||||
{
|
||||
0.0f, // 00 ANPI_eControlVoltage
|
||||
0.0f, // 01 ANPI_eSupplyVoltage24V
|
||||
0.0f, // 02 ANPI_eSupplyCurrent24V
|
||||
0.0f, // 03 ANPI_eOutputVoltage
|
||||
@ -147,7 +143,6 @@ LOCAL CONST StADCInit m_astADCInit[1] =
|
||||
{ADC1}, // 00 eADC1
|
||||
};
|
||||
// inputs are connected to the following ADCs
|
||||
// ANPI_eControlVoltage ADC1, Channel 8
|
||||
// ANPI_eSupplyVoltage24V ADC1, Channel 6
|
||||
// ANPI_eSupplyCurrent24V ADC1, Channel 16
|
||||
// ANPI_eOutputVoltage ADC1, Channel 7
|
||||
@ -203,7 +198,6 @@ PRIVATE VOID ANPI_vTask( PVOID arg );
|
||||
|
||||
extern ADC_HandleTypeDef hadc1;
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
@ -241,7 +235,8 @@ VOID ANPI_vTask( PVOID arg )
|
||||
U32 u32Flags;
|
||||
U16 u16Offset;
|
||||
FLOAT flUadc;
|
||||
U32 m_au32ADCRawData[ANPI_eInNumberOfInputs];
|
||||
U32 au32ADCRawData[ANPI_eInNumberOfInputs];
|
||||
FLOAT aflValues[ANPI_eInNumberOfInputs]; // values
|
||||
|
||||
osDelay( 1 ); // Wait 1ms to have a Valid Value
|
||||
|
||||
@ -260,15 +255,24 @@ VOID ANPI_vTask( PVOID arg )
|
||||
|
||||
// copy the values in the buffer...
|
||||
for(U16 u16Cnt = 0; u16Cnt < BUFFER_HALF_SIZE; u16Cnt++ )
|
||||
m_au32ADCRawData[ u16Cnt ] = m_au16ADCDataBuffer[u16Cnt + u16Offset];
|
||||
au32ADCRawData[ u16Cnt ] = m_au16ADCDataBuffer[u16Cnt + u16Offset];
|
||||
|
||||
// multiply conversion factor and add the offset
|
||||
for(U16 u16Cnt = 0; u16Cnt < ANPI_eInNumberOfInputs; u16Cnt++ )
|
||||
{
|
||||
flUadc = (FLOAT)m_au32ADCRawData[u16Cnt] / OVERSAMPLING_DIVISOR / ADC_RES * INT_ADC_REF;
|
||||
m_aflValues[u16Cnt] = flUadc * m_aflConversionFactor[u16Cnt] - m_aflOffset[u16Cnt];
|
||||
flUadc = (FLOAT)au32ADCRawData[u16Cnt] / OVERSAMPLING_DIVISOR / ADC_RES * INT_ADC_REF;
|
||||
aflValues[u16Cnt] = flUadc * m_aflConversionFactor[u16Cnt] - m_aflOffset[u16Cnt];
|
||||
}
|
||||
|
||||
|
||||
VARH_vSetVariableDataFromSystem(VARH_ePeltier_U, (VARH_UVariable)aflValues[ANPI_eOutputVoltage]);
|
||||
VARH_vSetVariableDataFromSystem(VARH_ePeltier_I, (VARH_UVariable)aflValues[ANPI_eOutputCurrent]);
|
||||
VARH_vSetVariableDataFromSystem(VARH_ePeltier_R, (VARH_UVariable)(aflValues[ANPI_eOutputVoltage] / aflValues[ANPI_eOutputCurrent]));
|
||||
VARH_vSetVariableDataFromSystem(VARH_ePeltier_R, (VARH_UVariable)(aflValues[ANPI_eOutputVoltage] * aflValues[ANPI_eOutputCurrent]));
|
||||
|
||||
VARH_vSetVariableDataFromSystem(VARH_eSupply_U, (VARH_UVariable)aflValues[ANPI_eSupplyVoltage24V]);
|
||||
VARH_vSetVariableDataFromSystem(VARH_eSupply_I, (VARH_UVariable)aflValues[ANPI_eSupplyCurrent24V]);
|
||||
VARH_vSetVariableDataFromSystem(VARH_eSupply_P, (VARH_UVariable)(aflValues[ANPI_eSupplyVoltage24V] * aflValues[ANPI_eSupplyCurrent24V]));
|
||||
|
||||
osMutexRelease( m_pstMutexID ); // release mutex
|
||||
}
|
||||
}
|
||||
@ -293,23 +297,6 @@ void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
|
||||
void HAL_ADC_ConvHalfCpltCallback(ADC_HandleTypeDef* hadc)
|
||||
{
|
||||
osEventFlagsSet( m_pstEventID, ANPI_ADC_HALF_COMPLETE );
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: ANPI_flGetInputValue
|
||||
// Description: Gets the value of the analog input
|
||||
// Parameters: ANPI_EnAnalogInput enInput Analog input to read
|
||||
// Returns: FLOAT flValue Value from ADC in V
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
FLOAT ANPI_flGetInputValue( ANPI_EnAnalogInput enInput )
|
||||
{
|
||||
|
||||
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
|
||||
FLOAT flValue = m_aflValues[enInput];
|
||||
osMutexRelease( m_pstMutexID ); // release mutex
|
||||
|
||||
return( flValue );
|
||||
}
|
||||
|
||||
//=================================================================================================
|
||||
@ -334,19 +321,20 @@ void HAL_ADC_ErrorCallback( ADC_HandleTypeDef* hadc )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if( hadc->ErrorCode == HAL_ADC_ERROR_OVR )
|
||||
{
|
||||
//ELOG_ADDLOG( ELOG_eADCOverrunError, NULL );
|
||||
}
|
||||
if( hadc->ErrorCode == HAL_ADC_ERROR_DMA )
|
||||
{
|
||||
// ELOG_ADDLOG( ELOG_eDMAHTransferError, NULL );
|
||||
|
||||
}
|
||||
|
||||
if( hadc->ErrorCode == HAL_ADC_ERROR_DMA )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// check rx dma transfer error
|
||||
if( hadc->DMA_Handle->ErrorCode & HAL_DMA_ERROR_TE )
|
||||
{
|
||||
// ELOG_ADDLOG( ELOG_eDMAHTransferError, NULL );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user