Square generator 1KHz to 1MHz with 1KHz precision

I would like to make a square wave generator which will output a signal with amplitude X voltages and frequency between 1KHz to 1MHz, with the precision of 1KHz (for example: 785kHz, 926kHz, 999kHz, etc ...). I have tried to do that with Arduino Uno, but I realized that I would need a precision of 1ns to be able to do that. 1ns equals to 1GHz. So, what hardware do I need to be able to do that?

• Why do you need a resolution of 1 nanosecond? – Nick Johnson Jul 15 '15 at 16:31
• Let's say you have 1us, that will give you 1MHz. If you have 2us you get 500 kHz. You see, a micro second is not enough. – Doctorslo Jul 15 '15 at 16:34
• @NickJohnson The time difference between 999kHz and 1MHz for a single cycle is aprox 1ns – brhans Jul 15 '15 at 16:35
• 1/1 ns = 1 GHz not 1 THz. Which is only about twice the toggle rate of simple logic in a fast FPGA. However not all the required periods are a whole number of nanoseconds... – Brian Drummond Jul 15 '15 at 16:40
• BTW, seemingly trivial, this question is not that easy..The problem, that is for a linear frequency range you will need a totally non-linear (1/F) period times. – Eugene Sh. Jul 15 '15 at 16:45