191 lines
8.0 KiB
C
191 lines
8.0 KiB
C
//=================================================================================================
|
|
//
|
|
// Company: Paul Scherrer Institut
|
|
// 5232 Villigen PSI
|
|
// Switzerland
|
|
//
|
|
//-------------------------------------------------------------------------------------------------
|
|
//
|
|
// Project: Peltier Controller V2
|
|
// Author: Noah Piqué (noah.pique@psi.ch)
|
|
//
|
|
//-------------------------------------------------------------------------------------------------
|
|
//
|
|
// Module: Temp
|
|
// Filename: TEMP_Temperature.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 temperature readout
|
|
//
|
|
//=================================================================================================
|
|
|
|
//=================================================================================================
|
|
// Section: INCLUDES
|
|
// Description: List of required include files.
|
|
//=================================================================================================
|
|
|
|
#include "TEMP_Temperature.h"
|
|
|
|
// Application
|
|
#include "../Application/VARH_VariableHandler.h"
|
|
|
|
// Toolbox
|
|
#include "../Toolbox/UTIL_Utility.h"
|
|
|
|
// Drivers
|
|
#include "ADCD_AdcDriver.h"
|
|
|
|
// include STM32 drivers
|
|
#include "stm32l4xx_hal.h"
|
|
|
|
#include "cmsis_os2.h"
|
|
|
|
//=================================================================================================
|
|
// Section: DEFINITIONS
|
|
// Description: Definition of local constants (visible by this module only).
|
|
//=================================================================================================
|
|
|
|
#define REFRESH_MS 100
|
|
|
|
//=================================================================================================
|
|
// 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 FUNCTIONS (PROTOTYPES)
|
|
// Description: Definition of local functions (visible by this module only).
|
|
//=================================================================================================
|
|
|
|
PRIVATE FLOAT flConvertADCData( U16 dbRTemp );
|
|
PRIVATE VOID vTask( PVOID arg );
|
|
|
|
//=================================================================================================
|
|
// Section: LOCAL CONSTANTS
|
|
// Description: Definition of local constants (visible by this module only).
|
|
//=================================================================================================
|
|
|
|
LOCAL CONST osThreadAttr_t stTaskAttribute =
|
|
{
|
|
"TEMP_Thread", // name of the thread
|
|
osThreadDetached, // attribute bits
|
|
NULL, // memory for control block
|
|
0, // size of provided memory for control block
|
|
NULL, // memory for stack
|
|
1024, // size of stack
|
|
osPriorityNormal, // initial thread priority (default: osPriorityNormal)
|
|
0, // TrustZone module identifier
|
|
0, // reserved (must be 0)
|
|
};
|
|
|
|
//=================================================================================================
|
|
// Section: LOCAL VARIABLES
|
|
// Description: Definition of local variables (visible by this module only).
|
|
//=================================================================================================
|
|
|
|
LOCAL osThreadId_t m_pstThreadID = NULL;
|
|
|
|
//=================================================================================================
|
|
// Section: EXTERNAL FUNCTIONS
|
|
// Description: Definition of external (global) functions.
|
|
//=================================================================================================
|
|
|
|
//=================================================================================================
|
|
// Section: EXTERNAL VARIABLES
|
|
// Description: Definition of external (global) variables.
|
|
//=================================================================================================
|
|
|
|
//=================================================================================================
|
|
// Section: GLOBAL FUNCTIONS
|
|
// Description: Definition (implementation) of global functions.
|
|
//=================================================================================================
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
// Function: TEMP_boInitializeModule
|
|
// Description: Initializes the module. Function must be called once immediately after power-up.
|
|
// This function is thread save
|
|
// Parameters: None
|
|
// Returns: Boolean TRUE if successful
|
|
//-------------------------------------------------------------------------------------------------
|
|
BOOL TEMP_boInitializeModule( VOID )
|
|
{
|
|
BOOL boOK = TRUE;
|
|
|
|
boOK &= ((m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE;
|
|
|
|
return( boOK );
|
|
}
|
|
|
|
//=================================================================================================
|
|
// Section: LOCAL FUNCTIONS
|
|
// Descriptionn: Definition (implementation) of local functions.
|
|
//=================================================================================================
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
// Function: vTempTask
|
|
// Description: vTempTask
|
|
// Parameters: None
|
|
// Returns: None
|
|
//-------------------------------------------------------------------------------------------------
|
|
PRIVATE VOID vTask( PVOID arg )
|
|
{
|
|
UNUSED( arg );
|
|
|
|
BOOL boOK = TRUE;
|
|
U8 error;
|
|
U16 u16ADC_data[ADCD_eNumberOfTemps];
|
|
FLOAT flTempData[ADCD_eNumberOfTemps];
|
|
|
|
osDelay(10);
|
|
|
|
while( TRUE )
|
|
{
|
|
boOK &= ADCD_boReadData( ADCD_eHot, &error, &u16ADC_data[ADCD_eHot] );
|
|
boOK &= ADCD_boReadData( 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_vSetVariableDataFromSystemFloat( VARH_eTemp_H, flTempData[ADCD_eHot] );
|
|
VARH_vSetVariableDataFromSystemFloat( VARH_eTemp_C, flTempData[ADCD_eCold] );
|
|
VARH_vSetVariableDataFromSystemFloat( VARH_eTemp_Diff, flTempData[ADCD_eHot] - flTempData[ADCD_eCold] );
|
|
|
|
}
|
|
|
|
osDelay(REFRESH_MS);
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------------------------------------
|
|
// Function: flConvertADCData
|
|
// Description: Converts resistor value to temperature data
|
|
// Parameters: U16 u16RTemp
|
|
// Returns: U16, temperature in Celcius
|
|
//-------------------------------------------------------------------------------------------------
|
|
PRIVATE FLOAT flConvertADCData( U16 u16RTemp )
|
|
{
|
|
|
|
FLOAT u16R = u16RTemp / 8192.0f;
|
|
|
|
FLOAT flT = 9.9714f * u16R;
|
|
flT += 235.904f;
|
|
flT *= u16R;
|
|
flT += -245.876f;
|
|
|
|
return( flT );
|
|
}
|