Its been a while since I looked at the Xmega's Timer/Counter, but a thought or two:
On Mega and Tiny Timer/Counters one sets the Top to the "desired" Top - 1.
The minus one accounts for roll over from Top back to Zero.
Without re-reading the manual, I suspect you are actually dividing by 50001, not by 50000.
Next, on the mass produced Xplain boards one might expect a =/- 50 ppm Xtal, but perhaps they selected an even cheaper version.
Clearly any Xtal is accurate enough for reliable USART comm's.
That said, your value is still quite a bit off, more than one would expect based upon Xtal tolerances, and the TOP being off by one count.
I would output the buffered Clock signal on an I/O Pin, and measure the actual Xmega's clock frequency.
There is a Cout option for the Xmega, IIRC one can route it to either of two different pins.
I suspect the T/C is performing correctly, but the external Xtal based clock is off frequency.
The actual frequency is dependent upon both the Xtal, the two caps to ground, the power supply voltage, and the temperature, (as well as the internal oscillator circuitry).
If you are only building one unit, then you can compensate in code.
If you are building several devices, then one would typically use a trimmer cap in one leg of the oscillator, (the two caps to ground), to be able to "pull" the Xtal and the oscillator to the "exact" frequency.
If you really need an exact clock, to many decimal places, then switch to a temperature controlled External Oscillator and feed the "exact" clock signal into the Xmega. These modules are the size of a small DIP chip, have their own V+ and Ground connections, and their own external load impedance expectations, (e.g. 50 ohm output load, or whatever).
I think you first have to measure / verify the exact frequency the Xmega with the given (cheap) Xtal, the selected caps, the operating voltage, and the ambient temperature is running at; then decide on the accuracy of the T/C module.
JC
↧