Or, here's another possibility...Which treats anything in the range of 0-90 as if it's 360-450. But only if the other value is on the other side of the zero point.Code:Direction VAR WORD ; Holds the Averaged wind direction Sample VAR WORD AvgCount CON 3 ; Number of samples to average ; Get New Sample here 0-359 If (Direction > 270) AND (Sample < 90) then Sample = Sample + 360 else if (Direction < 90) AND (Sample > 270) then Direction = Direction + 360 endif endif Direction = ((Direction * (AvgCount-1) + Sample) / AvgCount) // 360
Then after averaging, it gets the Modulus of the result, which brings it back into the 0-359 range.




Bookmarks