I have an XMEGA A3BU xplained development board. I want to use this chip because it can do hardware quadrature decoding and I'm using a motor with very high encoder tick frequency (250KHz).
For my PID loop I want to have a fixed controller frequency of 500Hz so I am using software interrupts on TC0.
I can't seem to get my ISR to fire at the right frequency. I expect a period of 2ms but I'm getting 1.93ms. The default clock is the on-chip 2MHz RC. I've also tried using the on-chip 32MHz RC. Both RC clocks give me this same weird ~4% discrepancy in frequency.
I'd expect the RC clock to not be perfect, but better than 4%. I'd also expect the two RC clock's not to have the exact same discrepancy.
The dev board only has a 32768Hz external crystal, which isn't fast enough to use with PLL to get a good system clock.
Am I missing something? Does anyone have advice?
I'm using a modified form of the ASF quickstart code from "TC Example 1 - XMEGA-A3BU Xplained" in Atmel Studio 6. I can post my code if necessary.