/********************** Thermal PT1 System on Arduino ***********************************/
float gridtime = 20; // grid time in ms: in WOKWI >= 5, in Arduino >= 5
unsigned long oldMillis = 0; // counter for grid-generation
int ctr; // counter to slow down outputs
int ctrMax = int(40/20); // underlayed counter for slower output (1...10=every 10th value)
// e.g. 200/ gridtime gives a 200 ms output grid
float T_Mass; // temperature of thermal mass (state variable)
float T_MassOld; // previous temp. of mass
float dT; // delta temp C=>Amb
float hfToAmb; // heatFlow to Ambient
//********************** Define here the Parameter **************************************//
float T_Amb = 20; // ambient temperature [°C]
float hfToCircuit = 50; // heat flow to circuit [W]
float hceC = 50; // heat capacity [J/K]
float hresC = 0.4; // heat resistance [K/W]
//************************************************************************************************//
void setup() {
// put your setup code here, to run once: Calculate C and L
Serial.begin(115200); // initialize the serial output to the PC at 38400 Baud
T_Mass = T_Amb; // initialize temperatures
T_MassOld = T_Amb; // initialize temperatures
}
void loop() {
// put your main code here, to run repeatedly:
if (millis()-oldMillis >20) {
if (oldMillis > 2000) {
T_Mass = 1/hceC*(hfToCircuit+T_Amb/hresC)*hceC*hresC*exp(-1/(hceC*hresC));
}
if (ctr == ctrMax+1) {
Serial.print(50); Serial.print(" ");
Serial.print(0); Serial.print(" ");
Serial.print(T_Mass,4); Serial.print(" ");
Serial.println(hfToAmb,4);
ctr = 0;
}
ctr = ctr+1; //
oldMillis = oldMillis + 20; // Update "oldMillis" to new value
}
}