DT. Thanks for taking time to look into the code.
First, I wrote it specifically to average 16 samples - it won't work with any other number because of the counter:
J/2 + 16
This counter takes the average (or average+128 if the two sample are more that 128 apart - and checks for a 'roll-over' above 255) and stores them:
Samples 0 and 1 average stored in address 16
Samples 2 and 3 average stored in address 17
Samples 4 and 5 average stored in address 18
Samples 6 and 7 average stored in address 19
Samples 8 and 9 average stored in address 20
Samples 10 and 11 average stored in address 21
Samples 12 and 13 average stored in address 22
Samples 14 and 15 average stored in address 23
Then, the same J/2 + 16 deals with the next round of averages:
Averages of 16 and 17 stored in address 24
Averages of 18 and 19 stored in address 25
Averages of 20 and 21 stored in address 26
Avergaes of 22 and 23 stored in address 27
And again
Averages of 24 and 25 stored in address 28
Averages of 26 and 27 stored in address 29
And finally
Averages of 28 and 29 stored in address 30
I guess the same could be done for other numbers of samples but 16 seems a reasonable number for wind direction and the code is short and simple. I have spent a laborious few hours with a pocket calculator checking the results - and so far it is Ok. If you, or anyone else spots an error please let me know.
Regards Bill Legge
Bookmarks