2009-05-26

Decoding WWVB Time Data -> Edge Triggered

Well, they say that by making mistakes, you learn what not to do.

The previous attempt at using pulseIn() to help decode WWVB time was successful if all you wanted was a string of bits, but we really do need loop() to function and not be blocked by the interrupt handler going out to a working lunch where it merrily does mostly what we want, but doesn't let us do anything else. Back to the Arduino IDE.

Let's work on getting a string of bits by a slightly different method. First, the detection needs to be edge triggered. This time we want attachInterrupt() to notify us of both the rising and falling edges of our input pulse.

At which point the interrupt handler readLevel() drops out of the picture until another edge is detected. Everything now gets handed off to loop() which checks to see if the previous wwvbInState is different from our current wwvbInState and if there has been a change, runs the pulseValue() function.

In pulseValue(), we come to the table with two facts. A change and a high wwvbInState is a leading edge to a pulse, a change and a low wwvbInState is its following edge. The leading edge saves the current time, the following edge subtracts saved time from the current time to find out how long the pulse lasted in milliseconds. From there a few conditional branches tell us if we have noise, a marker, a one or a zero bit. And now for the code:

As you can see, there was once again a bad patch with four minutes of data unreadable. If this is to drive a clock, we don't want the displayed time jumping erratically. Next time we'll see if we can get some simple frame rejection upon the more egregious receive errors.