Hi Members,

I need some advice on how to create a rolling 3 second average of wind direction.

So far: a sample is taken each second (AD count) and added/averaged until an interrupt causes the value to be sent serially at which time the values are reset and the cycle continues.

Basic enough but the problem arises where prevailing conditions see the wind coming from a Northerly aspect where one sample may be less than 359 degrees while the next (or previous) is greater than 0. Normal averaging would see two consecutive samples (say 350 and 10 degrees) as 180 but this is obviously incorrect, it should be 0 (360) degrees.

I've pulled a great deal of hair out trying to nail this but have hit a brick wall - any suggestions or advice would be most welcome. PIC of choice is F88 so codespace isn't an issue at this stage.

Regards,
Bill