small bugfixes
This commit is contained in:
2024-02-23 11:25:48 +01:00
parent 53a44a4075
commit 213ee88c7a
23 changed files with 2122 additions and 263 deletions

View File

@ -157,6 +157,7 @@ PRIVATE VOID vTask( PVOID arg )
BOOL boOK = TRUE;
boOK &= ERRH_boInitializeModule();
boOK &= USFL_boInitializeModule();
boOK &= VARH_boInitializeModule();

View File

@ -263,7 +263,7 @@ PRIVATE VOID vTask( PVOID arg )
CAND_boSendMessage( au8Buffer, 5, stMessage.boIsPrivate, stMessage.u8Type );
}
} else if( u8Type == MESSAGE_TYPE_WRITE ){ // Message type writeset
} else if( u8Type == MESSAGE_TYPE_WRITE ){ // Message type write
VARH_UVariable uData;
UTIL_vMemCopy(&stMessage.au8Data[1], &uData, 4);
@ -294,9 +294,8 @@ PRIVATE VOID vTask( PVOID arg )
CAND_boSendMessage( au8Buffer, 2, stMessage.boIsPrivate, stMessage.u8Type );
break;
case COMMAND_SAVE_VARIABLES:
au8Buffer[0] = COMMAND_SAVE_VARIABLES;
au8Buffer[1] = VARH_vSaveVariablestoFlash() ? 0xFF : 0x00;
CAND_boSendMessage( au8Buffer, 2, stMessage.boIsPrivate, stMessage.u8Type );
VARH_vSaveVariablestoFlash();
// @TODO Error handling Flash Save
break;
case COMMAND_LOAD_VARIABLES:
VARH_vLoadVariablesfromFlash();

View File

@ -23,8 +23,6 @@
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
@ -32,7 +30,7 @@
#include "PECO_PeltierController.h"
//Application
// Application
#include "../Application/VARH_VariableHandler.h"
// Driver
@ -45,50 +43,42 @@
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define REFRESH 100 // Refresh rate in ms
#define REFRESH 200 // Refresh rate in ms
#define EVENT_TIMER_UPDATE ((U32)(1<<0))
#define EVENT_TIMER_UPDATE ((U32)(1 << 0))
#define EVENT_FLAGS_ALL ( EVENT_TIMER_UPDATE )
#define EVENT_FLAGS_ALL (EVENT_TIMER_UPDATE)
//=================================================================================================
// 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;
LOCAL osTimerId_t m_pstUpdateTimer = NULL;
LOCAL osEventFlagsId_t m_pstEventID = NULL;
LOCAL osThreadId_t m_pstThreadID = NULL;
LOCAL osTimerId_t m_pstUpdateTimer = NULL;
LOCAL osEventFlagsId_t m_pstEventID = NULL;
//=================================================================================================
// Section: LOCAL CONSTANTS
@ -96,50 +86,48 @@ LOCAL osEventFlagsId_t m_pstEventID = NULL;
//=================================================================================================
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
osPriorityHigh, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
{
"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
osPriorityHigh, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier
0, // reserved (must be 0)
};
LOCAL CONST osTimerAttr_t stTimerAttribute =
{
"PECO_UpdateTimer", // name of the timer
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
{
"PECO_UpdateTimer", // name of the timer
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
{
"PECO_Event_Flags", // name of the event flags
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
{
"PECO_Event_Flags", // name of the event flags
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
PRIVATE VOID vTask( PVOID arg );
BOOL boSetPeltierVoltage( FLOAT Voltage );
PRIVATE VOID vEventCallback( PVOID pvData );
PRIVATE VOID vTask(PVOID arg);
BOOL boSetPeltierVoltage(FLOAT Voltage);
PRIVATE VOID vEventCallback(PVOID pvData);
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
@ -159,19 +147,19 @@ extern IWDG_HandleTypeDef hiwdg;
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL PECO_boInitializeModule( VOID )
BOOL PECO_boInitializeModule(VOID)
{
BOOL boOK = TRUE;
boOK &= ( ( m_pstThreadID = osThreadNew( vTask, NULL, &stTaskAttribute ) ) == NULL ) ? FALSE : TRUE;
boOK &= ( ( m_pstEventID = osEventFlagsNew( &stEventAttribute ) ) == NULL) ? FALSE : TRUE;
boOK &= ( m_pstUpdateTimer = osTimerNew( vEventCallback, osTimerPeriodic, (PVOID)EVENT_TIMER_UPDATE, &stTimerAttribute ) ) == NULL ? FALSE : TRUE;
boSetPeltierVoltage(0);
BOOL boOK = TRUE;
boOK &= (osTimerStart( m_pstUpdateTimer, REFRESH ) == osOK ) ? TRUE : FALSE;
boOK &= ((m_pstThreadID = osThreadNew(vTask, NULL, &stTaskAttribute)) == NULL) ? FALSE : TRUE;
boOK &= ((m_pstEventID = osEventFlagsNew(&stEventAttribute)) == NULL) ? FALSE : TRUE;
boOK &= (m_pstUpdateTimer = osTimerNew(vEventCallback, osTimerPeriodic, (PVOID)EVENT_TIMER_UPDATE, &stTimerAttribute)) == NULL ? FALSE : TRUE;
return( boOK );
boSetPeltierVoltage(0);
boOK &= (osTimerStart(m_pstUpdateTimer, REFRESH) == osOK) ? TRUE : FALSE;
return (boOK);
}
//-------------------------------------------------------------------------------------------------
@ -180,9 +168,10 @@ BOOL PECO_boInitializeModule( VOID )
// Parameters: BOOL boEnable
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID PECO_Enable( BOOL boEnable ){
DIPO_vSetState(DIPO_eEN, boEnable);
VARH_vSetVariableDataFromSystemU32( VARH_ePowerState, (U32)boEnable );
VOID PECO_Enable(BOOL boEnable)
{
DIPO_vSetState(DIPO_eEN, boEnable);
VARH_vSetVariableDataFromSystemU32(VARH_ePowerState, (U32)boEnable);
}
//-------------------------------------------------------------------------------------------------
@ -191,8 +180,9 @@ VOID PECO_Enable( BOOL boEnable ){
// Parameters: None
// Returns: BOOL boEnableOutput
//-------------------------------------------------------------------------------------------------
BOOL PECO_isEnabled( VOID ){
return (BOOL)VARH_u32GetVariableData( VARH_ePowerState );
BOOL PECO_isEnabled(VOID)
{
return (BOOL)VARH_u32GetVariableData(VARH_ePowerState);
}
//=================================================================================================
@ -206,88 +196,90 @@ BOOL PECO_isEnabled( VOID ){
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID vTask( PVOID arg )
VOID vTask(PVOID arg)
{
UNUSED( arg );
UNUSED(arg);
U32 u32Flags;
FLOAT last_error = 0;
FLOAT integral = 0;
FLOAT dT = REFRESH / 1000.0f; // 0.1s
while ( TRUE )
FLOAT dT = REFRESH / 1000.0f; // 0.2s
while (TRUE)
{
u32Flags = osEventFlagsWait( m_pstEventID, EVENT_FLAGS_ALL, osFlagsWaitAny, osWaitForever );
u32Flags = osEventFlagsWait(m_pstEventID, EVENT_FLAGS_ALL, osFlagsWaitAny, osWaitForever);
if( u32Flags & EVENT_TIMER_UPDATE )
if (u32Flags & EVENT_TIMER_UPDATE)
{
HAL_IWDG_Refresh(&hiwdg);
if ( PECO_isEnabled() )
if (PECO_isEnabled())
{
if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConstTemp )
if (VARH_u32GetVariableData(VARH_eMode) == PECO_eConstTemp)
{
// TODO: check the measurements, everything ok?
/** @todo check power good pin */
// PID Regelung
// TODO: check the measurements, everything ok?
FLOAT kp = VARH_flGetVariableData( VARH_ePID_kp );
FLOAT ki = VARH_flGetVariableData( VARH_ePID_ki );
FLOAT kd = VARH_flGetVariableData( VARH_ePID_kd );
FLOAT max = VARH_flGetVariableData( VARH_ePID_Max );
FLOAT min = VARH_flGetVariableData( VARH_ePID_Min );
FLOAT Tnow = VARH_flGetVariableData( VARH_eTemp_Module );
FLOAT Tset = VARH_flGetVariableData( VARH_ePID_Temp );
// -error
FLOAT error = Tnow - Tset;
// PID Regelung
// proportional term
FLOAT P = kp * error;
// integral term
integral += error * dT;
FLOAT I = ki * integral;
// derivative term
FLOAT D = kd * ( error - last_error ) / dT;
last_error = error;
// total
FLOAT output = P + I + D;
// limitter
if ( output > max ){
output = max;
integral = 0;
} else if ( output < min ){
output = min;
integral = 0;
FLOAT kp = VARH_flGetVariableData(VARH_ePID_kp);
FLOAT ki = VARH_flGetVariableData(VARH_ePID_ki);
FLOAT kd = VARH_flGetVariableData(VARH_ePID_kd);
FLOAT max = VARH_flGetVariableData(VARH_ePID_Max);
FLOAT min = VARH_flGetVariableData(VARH_ePID_Min);
FLOAT Tnow = VARH_flGetVariableData(VARH_eTemp_Module);
FLOAT Tset = VARH_flGetVariableData(VARH_ePID_Temp);
// -error
FLOAT error = Tnow - Tset;
// proportional term
FLOAT P = kp * error;
// integral term
integral += error * dT;
FLOAT I = ki * integral;
// derivative term
FLOAT D = kd * (error - last_error) / dT;
last_error = error;
// total
FLOAT output = P + I + D;
// limitter
if (output > max)
{
output = max;
integral = 0;
}
else if (output < min)
{
output = min;
integral = 0;
}
boSetPeltierVoltage(output); // set the output
}
boSetPeltierVoltage( output ); // set the output
} else if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConst_Voltage )
else if (VARH_u32GetVariableData(VARH_eMode) == PECO_eConst_Voltage)
{
boSetPeltierVoltage( VARH_flGetVariableData( VARH_eControlVoltage ) ); // set the output
boSetPeltierVoltage(VARH_flGetVariableData(VARH_eControlVoltage)); // set the output
last_error = 0;
integral = 0;
}
} else {
}
else
{
last_error = 0;
integral = 0;
}
}
}
}
}
}
//-------------------------------------------------------------------------------------------------
@ -296,15 +288,18 @@ VOID vTask( PVOID arg )
// Parameters: S8 Voltage (12V - -3V)
// Returns: Boolean TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL boSetPeltierVoltage( FLOAT Voltage ){
BOOL boOK = TRUE;
BOOL boSetPeltierVoltage(FLOAT Voltage)
{
BOOL boOK = TRUE;
if( Voltage > 12 ) Voltage = 12;
if( Voltage < -3 ) Voltage = -3;
boOK &= ANPO_boSetVoltage( ( ( (FLOAT)Voltage ) + 20.088) / 34.103 );
if (Voltage > 12)
Voltage = 12;
if (Voltage < -3)
Voltage = -3;
return( boOK );
boOK &= ANPO_boSetVoltage(Voltage);
return (boOK);
}
//-------------------------------------------------------------------------------------------------
@ -313,9 +308,7 @@ BOOL boSetPeltierVoltage( FLOAT Voltage ){
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vEventCallback( PVOID pvData )
PRIVATE VOID vEventCallback(PVOID pvData)
{
osEventFlagsSet( m_pstEventID, (U32)pvData );
osEventFlagsSet(m_pstEventID, (U32)pvData);
}

View File

@ -195,12 +195,12 @@ BOOL ADCD_boInitializeModule( VOID )
osMutexAcquire( m_pstMutexID, osWaitForever );
// Conifg ADC Cold
// Conifg ADC Module
DIPO_vSetOutput( DIPO_eCS_Module );
boOK &= boWriteReg( REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE );
DIPO_vResetOutput( DIPO_eCS_Module );
// Config ADC Hot
// Config ADC Water
DIPO_vSetOutput( DIPO_eCS_Water );
boOK &= boWriteReg( REG_CONFIG, (U16) CONFIG | CONFIG_FAULTSTATCLEAR, FALSE );
DIPO_vResetOutput( DIPO_eCS_Water );
@ -250,7 +250,7 @@ BOOL ADCD_boReadData( ADCD_EnTemps eChannel, PU8 pu8Error, PU16 pu16Data )
return FALSE;
}
if( ( u16Data & 0x0001 ) == 0x0001 )
if( ( u16Data & 0x0001 ) == 0x0001 ) // error
{
osMutexAcquire( m_pstMutexID, osWaitForever );

View File

@ -63,6 +63,8 @@
#define OVERSAMPLING_DIVISOR 16.0f // calculated with parameters from hardware oversampling
// 6 bits(64x) - 2 bit shift = 4bit -> 16x
#define ALMOST_ZERO 0.05
//=================================================================================================
// Section: MACROS
// Description: Definition of local macros (visible by this module only).
@ -93,6 +95,8 @@ LOCAL osThreadId_t m_pstThreadID = NULL;
LOCAL osEventFlagsId_t m_pstEventID = NULL;
LOCAL osMutexId_t m_pstMutexID = NULL;
LOCAL FLOAT aflValues[ANPI_eInNumberOfInputs]; // values
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
@ -208,7 +212,6 @@ VOID vTask( PVOID arg )
U16 u16Offset;
FLOAT flUadc;
U32 au32ADCRawData[ANPI_eInNumberOfInputs];
FLOAT aflValues[ANPI_eInNumberOfInputs]; // values
osDelay( 1 ); // Wait 1ms to have a Valid Value
@ -238,9 +241,21 @@ VOID vTask( PVOID arg )
aflValues[u16Cnt] = flUadc * m_aflConversionFactor[u16Cnt] - m_aflOffset[u16Cnt];
}
// Filter
for( U16 u16Cnt = 0; u16Cnt < ANPI_eInNumberOfInputs; u16Cnt++ )
{
if ( -ALMOST_ZERO <= aflValues[u16Cnt] && aflValues[u16Cnt] < ALMOST_ZERO)
aflValues[u16Cnt] = 0.0f;
}
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_U, aflValues[ANPI_eOutputVoltage] );
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_I, aflValues[ANPI_eOutputCurrent] );
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_R, aflValues[ANPI_eOutputVoltage] / aflValues[ANPI_eOutputCurrent] );
if ( aflValues[ANPI_eOutputCurrent] == 0.0f ){
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_R, 0.0f );
} else {
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_R, aflValues[ANPI_eOutputVoltage] / aflValues[ANPI_eOutputCurrent] );
}
VARH_vSetVariableDataFromSystemFloat( VARH_ePeltier_P, aflValues[ANPI_eOutputVoltage] * aflValues[ANPI_eOutputCurrent] );
VARH_vSetVariableDataFromSystemFloat( VARH_eSupply_U, aflValues[ANPI_eSupplyVoltage24V] );
@ -262,6 +277,21 @@ void HAL_ADC_ConvCpltCallback( ADC_HandleTypeDef* hadc )
osEventFlagsSet( m_pstEventID, ANPI_ADC_FULL_COMPLETE );
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_ADC_ConvCpltCallback
// Description: Handles the ADC interrupts
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
FLOAT ANPI_GetVoltage( ANPI_EnAnalogInput enVoltage )
{
osMutexAcquire( m_pstMutexID, osWaitForever ); // aquire mutex
FLOAT flVoltage = aflValues[enVoltage];
osMutexRelease( m_pstMutexID ); // release mutex
return flVoltage;
}
//-------------------------------------------------------------------------------------------------
// Function: HAL_ADC_ConvHalfCpltCallback
// Description: Handles the ADC interrupts

View File

@ -94,6 +94,7 @@ typedef enum
//=================================================================================================
BOOL ANPI_boInitializeModule( VOID );
FLOAT ANPI_GetVoltage( ANPI_EnAnalogInput enVoltage );
#ifdef __cplusplus
}

View File

@ -23,16 +23,16 @@
//
//=================================================================================================
//=================================================================================================
// Section: INCLUDES
// Description: List of required include files.
//=================================================================================================
#include "ANPO_AnalogPortsOut.h"
#include "ANPI_AnalogPortsIn.h"
#include "VARH_VariableHandler.h"
#include "DIPO_DigitalPorts.h"
// Toolbox
#include "../Toolbox/UTIL_Utility.h"
@ -40,63 +40,99 @@
// include STM32 drivers
#include "stm32l4xx_hal.h"
#include "cmsis_os2.h"
#include "cmsis_os2.h"
//=================================================================================================
// Section: DEFINITIONS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
#define REFRESH 50 // Refresh rate in ms
#define EVENT_TIMER_UPDATE ((U32)(1 << 0))
#define EVENT_FLAGS_ALL (EVENT_TIMER_UPDATE)
#define OFFSET 20.088
#define FACTOR 34.103448
//=================================================================================================
// 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;
LOCAL osTimerId_t m_pstUpdateTimer = NULL;
LOCAL osEventFlagsId_t m_pstEventID = NULL;
LOCAL FLOAT flVoltageActual = 0.0f;
LOCAL FLOAT flVoltageSet = 0.0f;
//=================================================================================================
// Section: LOCAL CONSTANTS
// Description: Definition of local constants (visible by this module only).
//=================================================================================================
LOCAL CONST osThreadAttr_t stTaskAttribute =
{
"ANPO_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)
};
LOCAL CONST osTimerAttr_t stTimerAttribute =
{
"ANPO_UpdateTimer", // name of the timer
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
LOCAL CONST osEventFlagsAttr_t stEventAttribute =
{
"ANPO_Event_Flags", // name of the event flags
0, // attribute bits
NULL, // memory for control block
0, // size of provided memory for control block
};
//=================================================================================================
// Section: LOCAL FUNCTIONS (PROTOTYPES)
// Description: Definition of local functions (visible by this module only).
//=================================================================================================
U32 u32ConvertVoltagetoRaw( FLOAT flVoltage );
U32 u32ConvertVoltagetoRaw(FLOAT flVoltage);
BOOL boUpdateVoltage(VOID);
PRIVATE VOID vTask(PVOID arg);
PRIVATE VOID vEventCallback(PVOID pvData);
//=================================================================================================
// Section: EXTERNAL FUNCTIONS
// Description: Definition of external (global) functions.
//=================================================================================================
//=================================================================================================
// Section: EXTERNAL VARIABLES
// Description: Definition of external (global) variables.
@ -116,13 +152,19 @@ extern DAC_HandleTypeDef hdac1;
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ANPO_boInitializeModule( VOID )
BOOL ANPO_boInitializeModule(VOID)
{
BOOL boOK = TRUE;
BOOL boOK = TRUE;
boOK &= HAL_DAC_Start( &hdac1, DAC_CHANNEL_1 ) == HAL_OK ? TRUE : FALSE;
boOK &= ((m_pstThreadID = osThreadNew(vTask, NULL, &stTaskAttribute)) == NULL) ? FALSE : TRUE;
boOK &= ((m_pstEventID = osEventFlagsNew(&stEventAttribute)) == NULL) ? FALSE : TRUE;
boOK &= (m_pstUpdateTimer = osTimerNew(vEventCallback, osTimerPeriodic, (PVOID)EVENT_TIMER_UPDATE, &stTimerAttribute)) == NULL ? FALSE : TRUE;
return( boOK );
boOK &= HAL_DAC_Start(&hdac1, DAC_CHANNEL_1) == HAL_OK ? TRUE : FALSE;
boOK &= (osTimerStart(m_pstUpdateTimer, REFRESH) == osOK) ? TRUE : FALSE;
return (boOK);
}
//=================================================================================================
@ -130,20 +172,82 @@ BOOL ANPO_boInitializeModule( VOID )
// Descriptionn: Definition (implementation) of local functions.
//=================================================================================================
//-------------------------------------------------------------------------------------------------
// Function: vTask
// Description: Task
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
VOID vTask(PVOID arg)
{
UNUSED(arg);
U32 u32EventFlags = 0;
while (TRUE)
{
u32EventFlags = osEventFlagsWait(m_pstEventID, EVENT_FLAGS_ALL, osFlagsWaitAny, osWaitForever);
if (u32EventFlags & EVENT_TIMER_UPDATE)
{
boUpdateVoltage();
BOOL boPowerGood = DIPO_boGetInput(DIPO_ePG);
/** @todo check power good pin */
}
}
}
//-------------------------------------------------------------------------------------------------
// Function: ANPO_boSetVoltage
// Description: Sets the DAC Output to a specific Voltage
// Description: Sets the Variable to a specific Voltage
// Parameters: FLOAT Voltage
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL ANPO_boSetVoltage( FLOAT flVoltage ){
BOOL boOK = TRUE;
U32 u32RawData = u32ConvertVoltagetoRaw( flVoltage );
boOK &= HAL_DAC_SetValue( &hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, u32RawData );
return( boOK );
BOOL ANPO_boSetVoltage(FLOAT flVoltage)
{
BOOL boOK = TRUE;
flVoltageSet = flVoltage;
boOK &= osEventFlagsSet(m_pstEventID, EVENT_TIMER_UPDATE) == osOK ? TRUE : FALSE;
return (boOK);
}
//-------------------------------------------------------------------------------------------------
// Function: boUpdateVoltage
// Description: Updates the Voltage of the DAC Output with a ramp
// Parameters: FLOAT Voltage
// Returns: Boolean, TRUE if successful
//-------------------------------------------------------------------------------------------------
BOOL boUpdateVoltage(VOID)
{
BOOL boOK = TRUE;
if (flVoltageActual < flVoltageSet)
{
flVoltageActual += 0.1;
if (flVoltageActual > flVoltageSet)
{
flVoltageActual = flVoltageSet;
}
}
else if (flVoltageActual > flVoltageSet)
{
flVoltageActual -= 0.1;
if (flVoltageActual < flVoltageSet)
{
flVoltageActual = flVoltageSet;
}
}
U32 u32RawData = u32ConvertVoltagetoRaw(flVoltageActual);
boOK &= HAL_DAC_SetValue(&hdac1, DAC_CHANNEL_1, DAC_ALIGN_12B_R, u32RawData) == HAL_OK ? TRUE : FALSE;
return (boOK);
}
//-------------------------------------------------------------------------------------------------
@ -152,14 +256,24 @@ BOOL ANPO_boSetVoltage( FLOAT flVoltage ){
// Parameters: FLOAT Voltage
// Returns: U32
//-------------------------------------------------------------------------------------------------
U32 u32ConvertVoltagetoRaw( FLOAT flVoltage ){
U32 RawData;
RawData = flVoltage * 4095 / VARH_flGetVariableData(VARH_eRef_U);
return RawData;
U32 u32ConvertVoltagetoRaw(FLOAT flVoltage)
{
U32 RawData;
FLOAT flTempVoltage = (((FLOAT)flVoltage) + OFFSET) / FACTOR;
RawData = flTempVoltage * 4095 / VARH_flGetVariableData(VARH_eRef_U);
return RawData;
}
//-------------------------------------------------------------------------------------------------
// Function: vEventCallback
// Description: Callback for events
// Parameters: None
// Returns: None
//-------------------------------------------------------------------------------------------------
PRIVATE VOID vEventCallback(PVOID pvData)
{
osEventFlagsSet(m_pstEventID, (U32)pvData);
}

View File

@ -113,6 +113,8 @@ BOOL ERRH_boInitializeModule( VOID )
//=================================================================================================
// Section: LOCAL FUNCTIONS
// Descriptionn: Definition (implementation) of local functions.

View File

@ -42,7 +42,35 @@ extern "C" {
// Description: Definition of global constants (visible by all modules).
//=================================================================================================
// Error Definition
#define NO_ERROR 0x00000000
// CAN Errors
// SPI Errors
// ADC Errors
// Analog In Errors
// Temperature Errors
// Userflash Errors
// Peltier Controller Errors
// Main Application Errors
// HardFault Errors
//=================================================================================================
// Section: MACROS

View File

@ -210,7 +210,7 @@ PRIVATE VOID vTask( PVOID arg )
//-------------------------------------------------------------------------------------------------
// Function: flConvertADCData
// Description: Converts resistor value to temperature data
// Description: Converts resistor value(PT1000) to temperature data
// Parameters: U16 u16RTemp
// Returns: U16, temperature in Celcius
//-------------------------------------------------------------------------------------------------

View File

@ -40,6 +40,7 @@
/*#define HAL_CRYP_MODULE_ENABLED */
#define HAL_CAN_MODULE_ENABLED
/*#define HAL_COMP_MODULE_ENABLED */
#define HAL_I2C_MODULE_ENABLED
#define HAL_CRC_MODULE_ENABLED
/*#define HAL_CRYP_MODULE_ENABLED */
#define HAL_DAC_MODULE_ENABLED
@ -85,7 +86,6 @@
/*#define HAL_PSSI_MODULE_ENABLED */
#define HAL_GPIO_MODULE_ENABLED
#define HAL_EXTI_MODULE_ENABLED
#define HAL_I2C_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED

View File

@ -604,6 +604,8 @@ static void MX_DMA_Init(void)
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
@ -658,6 +660,8 @@ static void MX_GPIO_Init(void)
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* USER CODE BEGIN MX_GPIO_Init_2 */
/* USER CODE END MX_GPIO_Init_2 */
}
/* USER CODE BEGIN 4 */

View File

@ -21,6 +21,7 @@
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */