Can't find old topic on clock compensation

expecting the Atmel code to work perfectly.

It will work perfectly, on its intended target.

All you need to do is to understand what the code is doing, read the datasheet of your own target and replicate the same on your target: aka what an application note is designed to do.