PECO update
This commit is contained in:
parent
ded2dc6ef9
commit
39607106d2
@ -52,7 +52,7 @@
|
||||
// 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))
|
||||
|
||||
@ -105,7 +105,7 @@ LOCAL CONST osThreadAttr_t stTaskAttribute =
|
||||
0, // size of provided memory for control block
|
||||
NULL, // memory for stack
|
||||
1024, // size of stack
|
||||
osPriorityNormal, // initial thread priority (default: osPriorityNormal)
|
||||
osPriorityHigh, // initial thread priority (default: osPriorityNormal)
|
||||
0, // TrustZone module identifier
|
||||
0, // reserved (must be 0)
|
||||
};
|
||||
@ -176,21 +176,6 @@ BOOL PECO_boInitializeModule( VOID )
|
||||
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
|
||||
@ -231,7 +216,7 @@ VOID vTask( PVOID arg )
|
||||
|
||||
FLOAT last_error = 0;
|
||||
FLOAT integral = 0;
|
||||
FLOAT dT = REFRESH; // 1s
|
||||
FLOAT dT = REFRESH / 1000.0f; // 1s
|
||||
|
||||
while ( TRUE )
|
||||
{
|
||||
@ -243,53 +228,63 @@ VOID vTask( PVOID arg )
|
||||
|
||||
HAL_IWDG_Refresh(&hiwdg);
|
||||
|
||||
if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConstTemp )
|
||||
if ( PECO_isEnabled() )
|
||||
{
|
||||
// TODO: check the measurements, everything ok?
|
||||
|
||||
|
||||
// PID Regelung
|
||||
|
||||
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_C );
|
||||
FLOAT Tset = VARH_flGetVariableData( VARH_ePID_Temp );
|
||||
if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConstTemp )
|
||||
{
|
||||
// TODO: check the measurements, everything ok?
|
||||
|
||||
|
||||
// PID Regelung
|
||||
|
||||
// -error
|
||||
FLOAT error = Tnow - Tset;
|
||||
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_C );
|
||||
FLOAT Tset = VARH_flGetVariableData( VARH_ePID_Temp );
|
||||
|
||||
// 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;
|
||||
} else if ( output < min ){
|
||||
output = min;
|
||||
}
|
||||
// -error
|
||||
FLOAT error = Tnow - Tset;
|
||||
|
||||
boSetPeltierVoltage( output ); // set the output
|
||||
// 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;
|
||||
}
|
||||
|
||||
} else if ( VARH_u32GetVariableData( VARH_eMode ) == PECO_eConst_Voltage )
|
||||
{
|
||||
boSetPeltierVoltage( VARH_flGetVariableData( VARH_eControlVoltage ) ); // set the output
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,7 +88,6 @@ typedef enum {
|
||||
//=================================================================================================
|
||||
|
||||
BOOL PECO_boInitializeModule( VOID );
|
||||
BOOL PECO_boSetTemperature( S16 Temperature );
|
||||
VOID PECO_Enable( BOOL Enable );
|
||||
BOOL PECO_isEnabled( VOID );
|
||||
|
||||
|
2
Makefile
2
Makefile
@ -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]
|
||||
##########################################################################################################################
|
||||
|
||||
# ------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user