The challenge is that when detecting frequency using the internal PIC comparators......the resulkting count appears to be jittery. By that I mean for say 1Khz, you get 'counts' arriving like thus...
5000, 4999, 5000,4999, 5001, 5000, 4999,5001,3479, 5000,4999,5001
now for the life of me I can't get to the bottom of why the spurious count arrives! (which would be the preferred option), so I'm faced with getting rid of it in software. What Melanie's number sort routine does, is sort an array of samples into numerical order (which will put the spurious count at the beginning), and then averages only the middle of the array. It gets rid of the spurious count completely.
If the frequency changes, then the middle of the array (after sorting) should reflect the count.
So my challenge if you like, is to get rid of spurious counts (ie not 'average' with them at all) ...and also to do this as quickly as possible.
As I say Melanie's routine works....but I'm always open to other methods to rid spurious readings from the equation.
Bookmarks