Clearly posting about the NTP Server v1.4 board being done was a mistake, as I ended up launching myself into a major overhaul of it anyway. Yep, 1.4c was forked into 1.4d and has many many changes.

Part of the problem is I'm not settled on what "done" looks like. I was originally planning on not migrating from a simple watch crystal RTC to the DS3234 RTC until after 1.4 was completed. But working with the XMega RTC has given me a lot of niggly issues around getting it to behave well with aligning the clock.

The problems with the XMega RTC are a mix of just the result of using a 20ppm crystal (ie, you get 20ppm accuracy, and that's not so cool) and some interesting choices about how it's built.

Some AVR Megas have an async clock timer, usually it's the single 8-bit timer. It's pretty basic, but 8-bit is actually a good choice since you can cover off the rest of the needed bits for a 32.768kHz crystal off interrupts, once every 256 ticks is not a heavy interrupt workload. The Xmega doesn't have an async clock timer, instead there's an explicit 16-bit RTC with a crystal input.

At first (mostly when reading the datasheet) this looks pretty good. But, there's a few annoyances. A number of Megas (and, more specifically, the ones I've been using like the 1284P) allow not only a 32.768kHz crystal but an external clock input. This allows you to use a variety of other clock options. The Xmega RTC has no such option, not in the A and D series anyway, and that's almost all of the ones actually shipping. (You can brute force an external clock into a crystal input but I'd prefer to stay within what the datasheet says the chip is expecting.)

The other issue with the RTC is the way you access it. Because it's running in it's own clock domain - specifically off whatever 32-ish-kHz source you chose - you have to jump through a lot of busywaiting to get configuration pushed into it. Busywait. Set something. Busywait. Set something else. And so on. The same problem plagues accessing the current count, if you want to change it yet more busywaiting.

You also don't get any capture options with the RTC, it has just compare and period registers, that's it.

This makes it quite difficult to align the RTC to a fine degree. Sure, it's great if you just need a simple timer to fire, say, a 1Hz interrupt to do something else in your code. It's actually very good at that. But if you actually care what "now" really is, then it doesn't cut it.

Falling out of that has been a large redesign, and involving the DS3234 RTC to replace the simple crystal. Thankfully while they did take away async clocking for a timer, they replaced it with a much more awesome system and the result is any of the normal 16-bit timers can provide a better replacement with finer control and more reliable capture. I'll probably post about that some other time.

I'll still be using the Xmega RTC, but it'll just be there as a system clock for trivial event timing that we don't really care about alignment for. Hell, 1% RC oscillators used as an RTC will be fine for many other timing needs in the code.