PECO update

This commit is contained in:
2022-10-19 14:12:32 +02:00
parent ded2dc6ef9
commit 39607106d2
3 changed files with 54 additions and 60 deletions

View File

@ -52,7 +52,7 @@
// Description: Definition of local constants (visible by this module only). // Description: Definition of local constants (visible by this module only).
//================================================================================================= //=================================================================================================
#define REFRESH 1000 // Refresh rate in ms #define REFRESH 100 // Refresh rate in ms
#define EVENT_TIMER_UPDATE ((U32)(1<<0)) #define EVENT_TIMER_UPDATE ((U32)(1<<0))
@ -105,7 +105,7 @@ LOCAL CONST osThreadAttr_t stTaskAttribute =
0, // size of provided memory for control block 0, // size of provided memory for control block
NULL, // memory for stack NULL, // memory for stack
1024, // size of stack 1024, // size of stack
osPriorityNormal, // initial thread priority (default: osPriorityNormal) osPriorityHigh, // initial thread priority (default: osPriorityNormal)
0, // TrustZone module identifier 0, // TrustZone module identifier
0, // reserved (must be 0) 0, // reserved (must be 0)
}; };
@ -176,21 +176,6 @@ BOOL PECO_boInitializeModule( VOID )
return( boOK ); 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 // Function: PECO_Enable
// Description: Enables the Peltier Controller Output // Description: Enables the Peltier Controller Output
@ -231,7 +216,7 @@ VOID vTask( PVOID arg )
FLOAT last_error = 0; FLOAT last_error = 0;
FLOAT integral = 0; FLOAT integral = 0;
FLOAT dT = REFRESH; // 1s FLOAT dT = REFRESH / 1000.0f; // 1s
while ( TRUE ) while ( TRUE )
{ {
@ -243,53 +228,63 @@ VOID vTask( PVOID arg )
HAL_IWDG_Refresh(&hiwdg); HAL_IWDG_Refresh(&hiwdg);
if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConstTemp ) if ( PECO_isEnabled() )
{ {
// TODO: check the measurements, everything ok?
if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConstTemp )
{
// TODO: check the measurements, everything ok?
// PID Regelung // PID Regelung
FLOAT kp = VARH_flGetVariableData( VARH_ePID_kp ); FLOAT kp = VARH_flGetVariableData( VARH_ePID_kp );
FLOAT ki = VARH_flGetVariableData( VARH_ePID_ki ); FLOAT ki = VARH_flGetVariableData( VARH_ePID_ki );
FLOAT kd = VARH_flGetVariableData( VARH_ePID_kd ); FLOAT kd = VARH_flGetVariableData( VARH_ePID_kd );
FLOAT max = VARH_flGetVariableData( VARH_ePID_Max ); FLOAT max = VARH_flGetVariableData( VARH_ePID_Max );
FLOAT min = VARH_flGetVariableData( VARH_ePID_Min ); FLOAT min = VARH_flGetVariableData( VARH_ePID_Min );
FLOAT Tnow = VARH_flGetVariableData( VARH_eTemp_C ); FLOAT Tnow = VARH_flGetVariableData( VARH_eTemp_C );
FLOAT Tset = VARH_flGetVariableData( VARH_ePID_Temp ); FLOAT Tset = VARH_flGetVariableData( VARH_ePID_Temp );
// -error // -error
FLOAT error = Tnow - Tset; FLOAT error = Tnow - Tset;
// proportional term // proportional term
FLOAT P = kp * error; FLOAT P = kp * error;
// integral term // integral term
integral += error * dT; integral += error * dT;
FLOAT I = ki * integral; FLOAT I = ki * integral;
// derivative term // derivative term
FLOAT D = kd * ( error - last_error ) / dT; FLOAT D = kd * ( error - last_error ) / dT;
last_error = error; last_error = error;
// total // total
FLOAT output = P + I + D; FLOAT output = P + I + D;
// limitter // limitter
if ( output > max ){ if ( output > max ){
output = max; output = max;
} else if ( output < min ){ integral = 0;
output = min; } else if ( output < min ){
output = min;
integral = 0;
}
boSetPeltierVoltage( output ); // set the output
} else if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConst_Voltage )
{
boSetPeltierVoltage( VARH_flGetVariableData( VARH_eControlVoltage ) ); // set the output
last_error = 0;
integral = 0;
}
} else {
last_error = 0;
integral = 0;
} }
boSetPeltierVoltage( output ); // set the output
} else if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConst_Voltage )
{
boSetPeltierVoltage( VARH_flGetVariableData( VARH_eControlVoltage ) ); // set the output
}
} }

View File

@ -88,7 +88,6 @@ typedef enum {
//================================================================================================= //=================================================================================================
BOOL PECO_boInitializeModule( VOID ); BOOL PECO_boInitializeModule( VOID );
BOOL PECO_boSetTemperature( S16 Temperature );
VOID PECO_Enable( BOOL Enable ); VOID PECO_Enable( BOOL Enable );
BOOL PECO_isEnabled( VOID ); BOOL PECO_isEnabled( VOID );

View File

@ -1,5 +1,5 @@
########################################################################################################################## ##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [3.15.2] date: [Thu Jul 07 18:17:37 CEST 2022] # File automatically-generated by tool: [projectgenerator] version: [3.15.2] date: [Tue Sep 06 08:17:33 CEST 2022]
########################################################################################################################## ##########################################################################################################################
# ------------------------------------------------ # ------------------------------------------------