--- Quote Start ---
1- I ran your code for 12000 samples, output signal got distorted, why?
2- You are changing the frequency rather than shifting phase. Is it what you intend to do? My code controls phase not frequency.
--- Quote End ---
when you run nco you control the tuning word (phi_inc). That is what I am doing.
phase and frequency are related. In design the nco will keep running nonstop from phase 1 and after some clocks (latency) its tuning word is updated.
In the code the index i is the phase and it is incremented steadily.
If you can run modelsim it gets much easier to check long sims and do any tweaks.
The important thing initial is to watch the phi_in value tending towards the rf centre frequency. once it settles the signal will settle at a constant (dc).
/2^16 is the tweek that turned out to control the loop better for our setup. you may require modifying it in final sign off of your radio !
output may look sinusoidal but check dynamic range (is it around zero or just osscilation around a constant level)