//sampling time 100 msec u8 speed_kmh; // input of car speed si8 outer_temp; //input temperature u8 k = 0; u8 l = 0; si16 temp_start = 0; si8 temp_old = 0; si16 temp_middle = 0; si16 temp_middle_5s = 0; si8 temp_array1[10]; // data for the first second si8 temp_array2[50]; // data for 5 seconds (50 * 100 msec loop) u8 temp_cnt1 = 0; u8 temp_cnt2 = 0; bool_T counter_valid = TRUE; si8 outer_temp_filt = 0; si8 temp_filter(si8 unfiltered); si8 temp_filter(outer_temp) //sampling time 100 msec { // filtering input data if(outer_temp < -10) { outer_temp = -10; } if(outer_temp > 40) { outer_temp = 40; } // Calculation of temperature middle value at start , just for the first second. if((temp_cnt1 < 11)&&(counter_valid)) { for(k=1; k<11; k++) { temp_array1[k] = outer_temp; temp_start = (temp_start + temp_array1[k])/k; } temp_cnt1++; } else { counter_valid = FALSE; } // Calculation of temperature middle value for every five second (continuously) if( temp_cnt2 < 50) { for( l=0; l<50; l++) { temp_array2[l] = aussen_temp; temp_array2[l + 1] = temp_array2[l]; temp_middle = temp_middle + temp_array2[l]; } temp_cnt2++; } else { temp_middle_5s = temp_middle/50; temp_cnt2 = 0; } //increasing - decreasing of the temperature ( filtered) if(temp_middle_5s >(temp_start + 1)) { if(speed_kmh > 20) { temp_start = temp_start + 1; } } else if (temp_middle_5s <(temp_start - 1)) { temp_start = temp_start + 1; } else { temp_start = temp_start; } outer_temp_filt = temp_start; return outer_temp_filt; }