Seems to calculate correctly now, but i need to plot to verify operation!
This commit is contained in:
@@ -9,41 +9,76 @@
|
||||
|
||||
#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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
printf("dTemp: %f", dtemp);
|
||||
|
||||
//inst->heatsinkTemperature = inst->heatsinkTemperature + (1.0 / inst->C_th) * (Heatsink_RespVal(inst) - inst->heatsinkTemperature) * dt;
|
||||
|
||||
return inst->heatsinkTemperature;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
if(elements == NULL)return 0;
|
||||
if(elements_Count == 0)return 0;
|
||||
int cm_heatsinkEmul_setFan(cm_heatsinkEmul_t *inst, float fan_speed){
|
||||
if(!isStructOk(inst)) return 1;
|
||||
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_Counts = elements_Count;
|
||||
|
||||
inst->power = power;
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user