add ANPI to VARH
This commit is contained in:
@ -228,18 +228,9 @@ PRIVATE VOID vMainTask( PVOID arg )
|
||||
if( u32Flags & EVENT_NEW_MESSAGE ) {
|
||||
|
||||
CAND_Message stMessage;
|
||||
osMessageQueueGet( m_pstCANRxMsgQueueID, &stMessage, NULL, 0 );
|
||||
osMessageQueueGet( m_pstCANRxMsgQueueID, &stMessage, NULL, 0 );
|
||||
|
||||
if(stMessage.u8Id == 0x10){
|
||||
|
||||
S16 ControlVoltage = ((S16)(ANPI_flGetInputValue(ANPI_eControlVoltage)*1000));
|
||||
|
||||
au8Buffer[0] = (ControlVoltage & 0xFF00) >> 8;
|
||||
au8Buffer[1] = ControlVoltage & 0xFF;
|
||||
|
||||
CAND_boSendMessage(0x11, 2, au8Buffer);
|
||||
|
||||
} else if(stMessage.u8Id == 0x12){
|
||||
if(stMessage.u8Id == 0x12){
|
||||
|
||||
S16 s16Voltage = stMessage.au8Data[0] << 8;
|
||||
s16Voltage |= stMessage.au8Data[1];
|
||||
@ -247,15 +238,10 @@ PRIVATE VOID vMainTask( PVOID arg )
|
||||
|
||||
} else if(stMessage.u8Id == 0x13){
|
||||
|
||||
S16 SupplyVoltage24V = ((S16)(ANPI_flGetInputValue(ANPI_eSupplyVoltage24V)*1000));
|
||||
S16 SupplyCurrent24V = ((S16)(ANPI_flGetInputValue(ANPI_eSupplyCurrent24V)*1000));
|
||||
S16 OutputVoltage = ((S16)(ANPI_flGetInputValue(ANPI_eOutputVoltage)*1000));
|
||||
S16 OutputCurrent = ((S16)(ANPI_flGetInputValue(ANPI_eOutputCurrent)*1000));
|
||||
|
||||
/*U16 SupplyVoltage24V = ANPI_flGetInputValue(ANPI_eSupplyVoltage24V);
|
||||
U16 SupplyCurrent24V = ANPI_flGetInputValue(ANPI_eSupplyCurrent24V);
|
||||
U16 OutputVoltage = ANPI_flGetInputValue(ANPI_eOutputVoltage);
|
||||
U16 OutputCurrent = ANPI_flGetInputValue(ANPI_eOutputCurrent);*/
|
||||
S16 SupplyVoltage24V = ((S16)(VARH_uGetVariableData(VARH_eSupply_U).flVal*1000));
|
||||
S16 SupplyCurrent24V = ((S16)(VARH_uGetVariableData(VARH_eSupply_I).flVal*1000));
|
||||
S16 OutputVoltage = ((S16)(VARH_uGetVariableData(VARH_ePeltier_U).flVal*1000));
|
||||
S16 OutputCurrent = ((S16)(VARH_uGetVariableData(VARH_ePeltier_I).flVal*1000));
|
||||
|
||||
au8Buffer[0] = (SupplyVoltage24V & 0xFF00) >> 8;
|
||||
au8Buffer[1] = SupplyVoltage24V & 0xFF;
|
||||
@ -270,7 +256,7 @@ PRIVATE VOID vMainTask( PVOID arg )
|
||||
|
||||
} else if(stMessage.u8Id == 0x15){
|
||||
|
||||
S16 Cold = (S16)(VARH_uGetVariableData(VARH_eTemp_C).flVal*100);
|
||||
S16 Cold = (S16)(VARH_uGetVariableData(VARH_eTemp_C).flVal*100);
|
||||
S16 Hot = (S16)(VARH_uGetVariableData(VARH_eTemp_H).flVal*100);
|
||||
|
||||
au8Buffer[0] = (Cold & 0xFF00) >> 8;
|
||||
|
@ -164,6 +164,7 @@ VOID VARH_vSetVariableData( U8 u8Variable, VARH_UVariable uData )
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
// Function: VARH_vSetVariableDataFromSystem
|
||||
// Description: Sets the Variable Data from System
|
||||
// Use only internal, not for User!
|
||||
// Parameters: U8 u8Variable
|
||||
// VARH_UVariable uData
|
||||
// Returns: None
|
||||
|
@ -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 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,11 +58,10 @@ extern "C" {
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ANPI_eControlVoltage = 0, // 00 control Voltage
|
||||
ANPI_eSupplyVoltage24V = 1, // 01 voltage of 24V power supply
|
||||
ANPI_eSupplyCurrent24V = 2, // 02 current of 24V power supply
|
||||
ANPI_eOutputVoltage = 3, // 03 output voltage peltier element
|
||||
ANPI_eOutputCurrent = 4, // 04 output current peltier element
|
||||
ANPI_eSupplyVoltage24V = 0, // voltage of 24V power supply
|
||||
ANPI_eSupplyCurrent24V = 1, // current of 24V power supply
|
||||
ANPI_eOutputVoltage = 2, // output voltage peltier element
|
||||
ANPI_eOutputCurrent = 3, // output current peltier element
|
||||
|
||||
ANPI_eInNumberOfInputs, // Must be last entry
|
||||
} ANPI_EnAnalogInput;
|
||||
@ -95,7 +94,6 @@ typedef enum
|
||||
//=================================================================================================
|
||||
|
||||
BOOL ANPI_boInitializeModule( VOID );
|
||||
FLOAT ANPI_flGetInputValue( ANPI_EnAnalogInput enInput );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -23,36 +23,26 @@
|
||||
//
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: INCLUDES
|
||||
// Description: List of required include files.
|
||||
//=================================================================================================
|
||||
|
||||
#include "../Application/VARH_VariableHandler.h"
|
||||
#include "../PDEF_ProjectDefinitions.h"
|
||||
#include "TEMP_Temperature.h"
|
||||
|
||||
// Application
|
||||
//#include "../Application/ELOG_ErrorLogger.h"
|
||||
//#include "../Application/RTOS_RealTimeOs.h"
|
||||
#include "../Application/VARH_VariableHandler.h"
|
||||
|
||||
// Toolbox
|
||||
//#include "../Toolbox/ASRT_Assert.h"
|
||||
#include "../Toolbox/UTIL_Utility.h"
|
||||
|
||||
// Drivers
|
||||
|
||||
#include "DIPO_DigitalPorts.h"
|
||||
#include "SPID_SpiDriver.h"
|
||||
#include "ADCD_ADCDriver.h"
|
||||
|
||||
// include STM32 drivers
|
||||
#include "stm32l4xx_hal.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
//=================================================================================================
|
||||
@ -90,7 +80,6 @@ PRIVATE VOID vTempTask( PVOID arg );
|
||||
// Description: Definition of local constants (visible by this module only).
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
LOCAL CONST osThreadAttr_t stTaskAttribute =
|
||||
{
|
||||
"TEMP_Thread", // name of the thread
|
||||
@ -116,15 +105,11 @@ LOCAL osThreadId_t m_pstThreadID = NULL;
|
||||
// Description: Definition of external (global) functions.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: EXTERNAL VARIABLES
|
||||
// Description: Definition of external (global) variables.
|
||||
//=================================================================================================
|
||||
|
||||
|
||||
|
||||
//=================================================================================================
|
||||
// Section: GLOBAL FUNCTIONS
|
||||
// Description: Definition (implementation) of global functions.
|
||||
@ -171,70 +156,19 @@ PRIVATE VOID vTempTask( PVOID arg )
|
||||
|
||||
while( TRUE )
|
||||
{
|
||||
boOK &= ADCD_dReadData(ADCD_eHot, &error, &u16ADC_data[ADCD_eHot]);
|
||||
boOK &= ADCD_dReadData(ADCD_eCold, &error, &u16ADC_data[ADCD_eCold]);
|
||||
if( boOK )
|
||||
{
|
||||
flTempData[ADCD_eHot] = flConvertADCData( u16ADC_data[ADCD_eHot] );
|
||||
flTempData[ADCD_eCold] = flConvertADCData( u16ADC_data[ADCD_eCold] );
|
||||
VARH_vSetVariableDataFromSystem( VARH_eTemp_H, (VARH_UVariable)flTempData[ADCD_eHot] );
|
||||
VARH_vSetVariableDataFromSystem( VARH_eTemp_C, (VARH_UVariable)flTempData[ADCD_eCold] );
|
||||
VARH_vSetVariableDataFromSystem( VARH_eTemp_Diff, (VARH_UVariable)(flTempData[ADCD_eHot] - flTempData[ADCD_eCold]) );
|
||||
|
||||
|
||||
//u32Flags = osEventFlagsWait( m_pstEventID, EVENT_REFRESH, osFlagsWaitAny, osWaitForever );
|
||||
|
||||
//if( u32Flags & EVENT_REFRESH )
|
||||
//{
|
||||
boOK &= ADCD_dReadData(ADCD_eHot, &error, &u16ADC_data[ADCD_eHot]);
|
||||
boOK &= ADCD_dReadData(ADCD_eCold, &error, &u16ADC_data[ADCD_eCold]);
|
||||
if( boOK )
|
||||
{
|
||||
flTempData[ADCD_eHot] = flConvertADCData( u16ADC_data[ADCD_eHot] );
|
||||
flTempData[ADCD_eCold] = flConvertADCData( u16ADC_data[ADCD_eCold] );
|
||||
VARH_vSetVariableData( VARH_eTemp_H, (VARH_UVariable)flTempData[ADCD_eHot] );
|
||||
VARH_vSetVariableData( VARH_eTemp_C, (VARH_UVariable)flTempData[ADCD_eCold] );
|
||||
VARH_vSetVariableData( VARH_eTemp_Diff, (VARH_UVariable)(flTempData[ADCD_eHot] - flTempData[ADCD_eCold]) );
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
osDelay(REFRESH_MS);
|
||||
|
||||
|
||||
|
||||
|
||||
// wait for ADC conversions completed
|
||||
// u32Flags = osEventFlagsWait( m_pstEventID, OS_EVENT_ADC_COMPLETED_FLAG, osFlagsWaitAll , ADC_TIMEOUT_MS );
|
||||
// boTimeout = (u32Flags == osFlagsErrorTimeout) ? TRUE : FALSE;
|
||||
// boError = FALSE;
|
||||
//
|
||||
// // check if we have a timeout
|
||||
// if( boTimeout )
|
||||
// {
|
||||
// //ELOG_ADD_LOG( ELOG_eADCTimeout );
|
||||
// }
|
||||
//
|
||||
// // read ADC data
|
||||
// if( !(boSuccess = boReadADCData() ) )
|
||||
// {
|
||||
// //ELOG_ADD_LOG( ELOG_eADCReadingDataFailed );
|
||||
// }
|
||||
//// vIncrementChannel();
|
||||
//
|
||||
// // reinit ADC on error, on spi failure or when timeout reached
|
||||
// if( boTimeout || !boSuccess )
|
||||
// {
|
||||
// boError = TRUE;
|
||||
//// vADCInit();
|
||||
// }
|
||||
|
||||
// // send event to worker task, if all channels completed and no error
|
||||
// if( m_stADCData.u8Cannel == 0 && !boError )
|
||||
// {
|
||||
// // send event to tasks
|
||||
// for( U16 u16Cnt = 0; u16Cnt < NUMBER_OF_EVENT_CALLBACKS; u16Cnt++ )
|
||||
// {
|
||||
// if( m_apfnEventCallback[u16Cnt] != NULL )
|
||||
// {
|
||||
// m_apfnEventCallback[u16Cnt]( m_apvCallbackArgument[u16Cnt] );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user