From 5dc13acb5c8ffb23cd99c5c8e5848362534f5853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Noah=20Piqu=C3=A9?= Date: Fri, 17 Dec 2021 17:30:41 +0100 Subject: [PATCH] add ANPI to VARH --- Core/Application/MAIN_MainApplication.c | 28 ++------ Core/Application/VARH_VariableHandler.c | 1 + Core/Drivers/ANPI_AnalogPortsIn.c | 74 +++++++++------------ Core/Drivers/ANPI_AnalogPortsIn.h | 10 ++- Core/Drivers/TEMP_Temperature.c | 88 ++++--------------------- 5 files changed, 54 insertions(+), 147 deletions(-) diff --git a/Core/Application/MAIN_MainApplication.c b/Core/Application/MAIN_MainApplication.c index a54bad2..f8b0bad 100644 --- a/Core/Application/MAIN_MainApplication.c +++ b/Core/Application/MAIN_MainApplication.c @@ -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; diff --git a/Core/Application/VARH_VariableHandler.c b/Core/Application/VARH_VariableHandler.c index 9fdc968..64a3b12 100644 --- a/Core/Application/VARH_VariableHandler.c +++ b/Core/Application/VARH_VariableHandler.c @@ -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 diff --git a/Core/Drivers/ANPI_AnalogPortsIn.c b/Core/Drivers/ANPI_AnalogPortsIn.c index 92296af..d4f5bef 100644 --- a/Core/Drivers/ANPI_AnalogPortsIn.c +++ b/Core/Drivers/ANPI_AnalogPortsIn.c @@ -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 ); + } } diff --git a/Core/Drivers/ANPI_AnalogPortsIn.h b/Core/Drivers/ANPI_AnalogPortsIn.h index fbe4f7f..a122085 100644 --- a/Core/Drivers/ANPI_AnalogPortsIn.h +++ b/Core/Drivers/ANPI_AnalogPortsIn.h @@ -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 } diff --git a/Core/Drivers/TEMP_Temperature.c b/Core/Drivers/TEMP_Temperature.c index 1613216..45f7fd3 100644 --- a/Core/Drivers/TEMP_Temperature.c +++ b/Core/Drivers/TEMP_Temperature.c @@ -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 - #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 ) { - - - //u32Flags = osEventFlagsWait( m_pstEventID, EVENT_REFRESH, osFlagsWaitAny, osWaitForever ); + 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]) ); - //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] ); -// } -// } -// } - } }