Hello, I came on a strange problem with variable in TM4C129 TI-RTOS project.
Consider this function:
Void FanRegFxn(UArg arg0, UArg arg1) //Vstupna velicina z Main je Power v % - vykon menica 0 - 100%
{
PWM_Handle pwm7;
PWM_Params params;
extern volatile float Temp_MainTX, Temp_AuxTX, Temp_MainHB, Temp_AuxHB, TempPower;
extern volatile float Power, I_Bat, I_Bat_avg;
extern volatile float Temp; //zmerana teplota
//float TempPower1 = 0;
//float argExp = 0;
float FanPwmPeriod = 72; // Period and duty in microseconds
float duty = 0;
extern volatile float dutypct;
float TempPower1 = 0;
PWM_Params_init(¶ms);
params.period = FanPwmPeriod;
params.polarity = PWM_POL_ACTIVE_LOW;
pwm7 = PWM_open(PWM7, ¶ms);
if (pwm7 == NULL) {
System_abort("PWM7 did not open");
}
/* Loop forever adjusting the PWM duty */
while (1) {
AMeasTempFxn(); // meranie teploty
Temp = fmaxf(fabsf(Temp_MainTX),fabsf(Temp_MainHB)); // zistenie najvyssej teploty zo vsetkych senzorov. Rozopnuta poistka dava -100°C preto fabsf.
Temp = fmaxf(Temp,fabsf(Temp_AuxHB));
//Temp = fmaxf(Temp,fabsf(Temp_AuxTX));
TempPower1 = TempPower;
TempPower = (0.9*TempPower1+0.1*Temp);
if (TempPower > 110)
{
SystemMode = 0; ErrorCode = 5;
} //overtemperature shutdown - vypnute na testovanie
//ZAPINANIE/VYPINANIE:
//PWM_setDuty(pwm6, duty) // toto sa tyka PWM6 (Speaker_PWM)
if (TempPower < 30.0) {
GPIOPinWrite(GPIO_PORTK_BASE,GPIO_PIN_6,0);// Turn off fans
dutypct = 0; // Set zero duty
}
else if (TempPower > 35.0)
{
GPIOPinWrite(GPIO_PORTK_BASE,GPIO_PIN_6,GPIO_PIN_6);// Turn on fans
dutypct = 1.0; // <40°C = 1% aby sme videli ze idu
};
//REGULACIA:
if (TempPower > 40.0) {
if (TempPower < (60.0))
{
dutypct = (TempPower - 40.0) * 5;
}
else
{
dutypct = 100.0; // >45°C = 100%
};
}
else if (TempPower > 35.0) dutypct = 1.0;
duty = ((dutypct/100.0)*FanPwmPeriod);
if (pwm7) {
PWM_setDuty(pwm7, duty);
}
System_printf("TempPower °C= %f\n",TempPower1);
System_flush();
Task_sleep((UInt) arg1);
}
}
The function is to measure four temperatures, get the highest of them, smooth it out and set up fan speed accordingly. If temperature is too high, turn off the system and set error code.
Everything works, except the smoothing of the values. This is an inverter project and at higher powers, I get some noise at the thermistor lines that needs to be removed. The simplest way I thought of was to take 9/10th of the old maximum temperature (TempPower variable) and one tenth of new maximum temperature (Temp variable):
TempPower = (0.9*TempPower+0.1*Temp);
But when I do that, or anything similar, I get an (error) instead of the expected value. Also, when I debug and break before that point, I can not Step Into that. It just skips over that row. I tried to modify it in a way that I do not read and overwrite TempPower on the same row:
float TempPower1 = 0;
...
TempPower1 = TempPower;
TempPower = (TempPower1+Temp);
But still the same problem persists. And on the Variables view, there are these red warnings about invalid register indexes. What is causing them?
I do similar averaging with voltages and other variables in other function and it works as expected.
What could be the problem here?
Thanks in advance for help.
