I've made a few tests, this code starts working good from 5Mhz. At lower frequencies readout unstable or impossible.
BUT I find a way how to run this algorithm with DCO on 1 MHz. All you need is to rewrite the arduino-like part using defines instread of using functions. This is my code: