you should use HPWM to produce the frequency, it's working smooth when your program jump here and there.