I am running an infinte while loop. Inside the while loop i give a FOR loop which runs 3 times. each time i get a specific value of second from the real time clock. I need to store these 3 seconds value in an array and calculate the average at the end of 3 rd loop.
I tried like this:
int time_diff[3];// Initialization of array for 3 values double avg; SCU_APBPeriphClockConfig(__RTC,ENABLE); /*enable RTC clock*/ SCU_APBPeriphReset(__RTC,DISABLE); /*RTC out of RESET state*/ time.milliseconds = 0; // Initialization time sturcture while(1) { for(k=0;k<=2;k++) { if ( a condition) { RTC_GetTime(BINARY,&BEGIN_TIME); } if ( another conditon) { RTC_GetTime(BINARY,&END_TIME); time_diff[k] = %02dms; // THIS LINEDIDNT WORK. DONT KNOW how to save that current value to time_diff[k] array } if (k == 3) { avg = (time_diff[0]+ time_diff[1]+time_diff[2])/3; sprintf(text, "Average = %d",avg); lcd_print (text); } } }
How is it possible to save the millisecond value as an array element? This code below displays the millisecond. But what i need is to save this current value to an array and then do averaging.
sprintf(text, "TIME in milli: %02dms ",END_TIME.milliseconds); lcd_print (text);
thnx Westermark.
I used a if statement to break the whole program when the count is <=3. So it will count only for 3 times and then the whole is again reset. So i guess there will not be any overflow problem.