I'm currently writing a program for an atmel 89C51ED2. A part of the program calls for a 30 second average. In this loop data is constantly being taken and then averaged with the previous value and then displayed on an LCD. When new data is being taken, it gets averaged with the prevous averaged value.
Is there any easier way to take averages without taking all 30 seconds of data and averaging all of them at one time? Any comment or advice will be greatly appreciated.
2 replies to this topic
#1
Posted 16 April 2010 - 11:59 AM
|
|
|
#2
Posted 27 April 2010 - 06:52 AM
Not quite sure what you're asking here, but I think you're saying that you're running a divide on the data every time through the loop. If that's the case, just stick a counter in one register, and a total in the other, then divide the total by the counter at the end of the loop. However, this will only work if the data is small enough to not cause overflow in the register containing the total during the loop. If you're getting poor performance, run a short wait on each execution of the loop. That will cause the average to be more granular, but it will save processor usage, and with enough granularity, eliminate any possible overflow that I was mentioning earlier.
#3
Posted 27 April 2010 - 09:51 AM
Thanks for the reply. This is how i ended up writing the code. At first their was overflow problems due to large numbers but i solved by writing a routine which was able to do 24 bit division.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









