//================================================================================================= // // Company: Paul Scherrer Institut // 5232 Villigen PSI // Switzerland // //------------------------------------------------------------------------------------------------- // // Project: Peltier Controller V2 // Author: Noah Piqu� (noah.pique@psi.ch) // //------------------------------------------------------------------------------------------------- // // Module: Peltier Controller // Filename: PECO_PeltierController.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 Peltier Controller Output // //================================================================================================= //================================================================================================= // Section: INCLUDES // Description: List of required include files. //================================================================================================= #include "../PDEF_ProjectDefinitions.h" #include "PECO_PeltierController.h" // Driver #include "../Drivers/ANPO_AnalogPortsOut.h" #include "../Drivers/DIPO_DigitalPorts.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). //================================================================================================= LOCAL osThreadId_t m_pstThreadID = NULL; //================================================================================================= // Section: LOCAL CONSTANTS // Description: Definition of local constants (visible by this module only). //================================================================================================= LOCAL CONST osThreadAttr_t stTaskAttribute = { "PECO_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 FUNCTIONS (PROTOTYPES) // Description: Definition of local functions (visible by this module only). //================================================================================================= PRIVATE VOID PECO_vTask( PVOID arg ); BOOL boSetPeltierVoltage( S16 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: PECO_boInitializeModule // Description: Initializes the module. Function must be called once immediately after power-up. // Parameters: None // Returns: Boolean TRUE if successful //------------------------------------------------------------------------------------------------- BOOL PECO_boInitializeModule( VOID ) { BOOL boOK = TRUE; //boOK &= ((m_pstThreadID = osThreadNew( PECO_vTask, NULL, &stTaskAttribute )) == NULL ) ? FALSE : TRUE; boSetPeltierVoltage(0); return( boOK ); } //------------------------------------------------------------------------------------------------- // Function: PECO_boSetTemperature // Description: Sets the Peltier Controller to a Specific Temperature // Parameters: None // Returns: Boolean TRUE if successful //------------------------------------------------------------------------------------------------- BOOL PECO_boSetTemperature( S16 Temperature ){ BOOL boOK = TRUE; boOK &= boSetPeltierVoltage( Temperature ); return( boOK ); } //------------------------------------------------------------------------------------------------- // Function: PECO_Enable // Description: Enables the Peltier Controller Output // Parameters: BOOL Enable // Returns: None //------------------------------------------------------------------------------------------------- VOID PECO_Enable( BOOL Enable ){ DIPO_vSetState(DIPO_eEN, Enable); } //================================================================================================= // Section: LOCAL FUNCTIONS // Descriptionn: Definition (implementation) of local functions. //================================================================================================= //------------------------------------------------------------------------------------------------- // Function: PECO_vTask // Description: PECO_vTask // Parameters: None // Returns: None //------------------------------------------------------------------------------------------------- VOID PECO_vTask( PVOID arg ) { /*PECO_Enable(TRUE); while ( TRUE ) { boSetPeltierVoltage(1); osDelay(5000); boSetPeltierVoltage(0); osDelay(5000); boSetPeltierVoltage(-1); osDelay(5000); boSetPeltierVoltage(0); osDelay(5000); }*/ } //------------------------------------------------------------------------------------------------- // Function: boSetPeltierVoltage // Description: Sets the Peltier elements to a specific Voltage // Parameters: S8 Voltage (14V - -8V) // Returns: Boolean TRUE if successful //------------------------------------------------------------------------------------------------- BOOL boSetPeltierVoltage( S16 Voltage ){ BOOL boOK = TRUE; if( Voltage > 14000 ) Voltage = 14000; if( Voltage < -8000 ) Voltage = -8000; //Voltage -= 0.6; // Offset (hoffentlich nicht mehr) boOK &= ANPO_boSetVoltage( ((((FLOAT)Voltage)/1000) + 20.088) / 34.103 ); return( boOK ); }