Compare commits
1 Commits
ab53feccc5
...
f8451ba27c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8451ba27c |
@@ -9,41 +9,76 @@
|
|||||||
|
|
||||||
#define EULER_NUM 2.7182818284590452353602
|
#define EULER_NUM 2.7182818284590452353602
|
||||||
|
|
||||||
static float deltaTempElement(cm_heatsink_thermalElement_t *element, float temperature, float power){
|
static int isStructOk(cm_heatsinkEmul_t *inst){
|
||||||
|
if(inst == NULL)return 0;
|
||||||
|
if(inst->thermalElements == NULL)return 0;
|
||||||
|
if(inst->thermalElements_Counts == 0)return 0;
|
||||||
|
|
||||||
return temperature + (power * element->R_th);
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float cm_heatsinkEmul_getRespon(cm_heatsinkEmul_t *inst, float dtime){
|
static float deltaTempElement(cm_heatsink_thermalElement_t *element, float temperature, float power){
|
||||||
|
|
||||||
|
// Kelvin = Watt * K/W
|
||||||
|
return (power * element->R_th);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int cm_heatsinkEmul_iterate(cm_heatsinkEmul_t *inst, float dtime){
|
||||||
|
if(!isStructOk(inst)) return 1;
|
||||||
|
|
||||||
float dtemp = inst->ambientTemp;
|
float dtemp = inst->ambientTemp;
|
||||||
|
|
||||||
for(int i = inst->thermalElements_Counts; i > 0; i--){
|
// We begin from ambient temperature and move up towards heat source.
|
||||||
|
for(int i = (inst->thermalElements_Counts-1); i >= 0; i--){
|
||||||
|
|
||||||
dtemp+= deltaTempElement(&inst->thermalElements[i], dtemp, inst->power);
|
// Calculate temperature until we reach requested element!
|
||||||
|
dtemp += deltaTempElement(&inst->thermalElements[i], dtemp, inst->power);
|
||||||
|
|
||||||
|
|
||||||
|
// Do so the temperature has the responsetime as the heatsink.
|
||||||
|
inst->thermalElements[i].temperature = inst->thermalElements[i].temperature + (1.0 / inst->C_th) * (dtemp - inst->thermalElements[i].temperature) * dtime;
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
printf("dTemp: %f", dtemp);
|
|
||||||
|
|
||||||
//inst->heatsinkTemperature = inst->heatsinkTemperature + (1.0 / inst->C_th) * (Heatsink_RespVal(inst) - inst->heatsinkTemperature) * dt;
|
|
||||||
|
|
||||||
return inst->heatsinkTemperature;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float cm_heatsinkEmul_getElementTemp(cm_heatsinkEmul_t *inst, int element_idx){
|
||||||
|
if(!isStructOk(inst)) return 0.0;
|
||||||
|
if(element_idx > (inst->thermalElements_Counts-1)) return 0.0;
|
||||||
|
return inst->thermalElements[element_idx].temperature;
|
||||||
|
|
||||||
int cm_heatsinkEmul_init(cm_heatsinkEmul_t *inst, cm_heatsink_thermalElement_t *elements, int elements_Count, float power, float ambientTemp){
|
}
|
||||||
|
|
||||||
if(inst == NULL)return 0;
|
int cm_heatsinkEmul_setFan(cm_heatsinkEmul_t *inst, float fan_speed){
|
||||||
if(elements == NULL)return 0;
|
if(!isStructOk(inst)) return 1;
|
||||||
if(elements_Count == 0)return 0;
|
inst->fan_speed = fan_speed;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int cm_heatsinkEmul_init(cm_heatsinkEmul_t *inst, cm_heatsink_thermalElement_t *elements, int elements_Count, float C_th, float power, float ambientTemp){
|
||||||
|
|
||||||
|
if(inst == NULL)return 1;
|
||||||
|
if(elements == NULL)return 1;
|
||||||
|
if(elements_Count == 0)return 1;
|
||||||
|
|
||||||
inst->thermalElements = elements;
|
inst->thermalElements = elements;
|
||||||
inst->thermalElements_Counts = elements_Count;
|
inst->thermalElements_Counts = elements_Count;
|
||||||
|
|
||||||
inst->power = power;
|
inst->power = power;
|
||||||
inst->ambientTemp = ambientTemp;
|
inst->ambientTemp = ambientTemp;
|
||||||
|
inst->C_th = C_th;
|
||||||
|
|
||||||
|
// Dynamic values
|
||||||
|
inst->fan_speed = 0;
|
||||||
|
|
||||||
|
// Assume all elements is equal to ambient before we start!
|
||||||
|
for(int i = (inst->thermalElements_Counts-1); i >= 0; i--){
|
||||||
|
inst->thermalElements[i].temperature = inst->ambientTemp;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,14 @@
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char label[32];
|
char label[32];
|
||||||
float R_th; // In Kelvin/Watt or Celsius/Watt (you can mix!)
|
union{
|
||||||
|
float R_th; // In Kelvin/Watt or Celsius/Watt (you can mix!)
|
||||||
|
float R_th_MinFan; // In case you need to emulate a fan
|
||||||
|
};
|
||||||
|
float R_th_MaxFan; // In case you need to emulate a fan
|
||||||
|
|
||||||
|
// Dynamic
|
||||||
|
float temperature;
|
||||||
|
|
||||||
}cm_heatsink_thermalElement_t;
|
}cm_heatsink_thermalElement_t;
|
||||||
|
|
||||||
@@ -26,12 +33,13 @@ typedef struct {
|
|||||||
float C_th; // Thermal capacity
|
float C_th; // Thermal capacity
|
||||||
|
|
||||||
// Dynamic
|
// Dynamic
|
||||||
float heatsinkTemperature;
|
float prev_time;
|
||||||
|
float fan_speed;
|
||||||
|
|
||||||
}cm_heatsinkEmul_t;
|
}cm_heatsinkEmul_t;
|
||||||
|
|
||||||
float cm_heatsinkEmul_getRespon(cm_heatsinkEmul_t *inst, float dt);
|
int cm_heatsinkEmul_iterate(cm_heatsinkEmul_t *inst, float dtime);
|
||||||
int cm_heatsinkEmul_init(cm_heatsinkEmul_t *inst, cm_heatsink_thermalElement_t *elements, int elements_Count, float power, float ambientTemp);
|
float cm_heatsinkEmul_getElementTemp(cm_heatsinkEmul_t *inst, int element_idx);
|
||||||
|
int cm_heatsinkEmul_init(cm_heatsinkEmul_t *inst, cm_heatsink_thermalElement_t *elements, int elements_Count, float C_th, float power, float ambientTemp);
|
||||||
|
|
||||||
#endif /* CM_HEATSINK_EMULATOR_H_ */
|
#endif /* CM_HEATSINK_EMULATOR_H_ */
|
||||||
|
|||||||
Reference in New Issue
Block a user