getting the right frequency on XMEGA
Check the assembly code generated, when you enable changes to clock system, you have a total of 4 CPU cycles to make the necessary writes (check the user guide for your particular XMEGA device). In my personal experience, I have seen that the compiler without any optimizations will produce code that takes more than 4 CPU to make the write the clock system registers. Try enabling optimizations to the code or make the changes to the clock system using in-line assembly.