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?

  • \$\begingroup\$ Why do you need a resolution of 1 nanosecond? \$\endgroup\$ – Nick Johnson Jul 15 '15 at 16:31
  • 1
    \$\begingroup\$ 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. \$\endgroup\$ – Doctorslo Jul 15 '15 at 16:34
  • \$\begingroup\$ @NickJohnson The time difference between 999kHz and 1MHz for a single cycle is aprox 1ns \$\endgroup\$ – brhans Jul 15 '15 at 16:35
  • 1
    \$\begingroup\$ 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... \$\endgroup\$ – user16324 Jul 15 '15 at 16:40
  • \$\begingroup\$ 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. \$\endgroup\$ – Eugene Sh. Jul 15 '15 at 16:45

Direct Digital Synthesis may be over the top for what you want but it can certainly deliver the goods: -

enter image description here

Click on the picture to take you to the data sheet. It produces a sinewave but this can easily give you a square wave (on board comparator). With a 28 bit control register on frequency a 16MHz clock can be divided down to 0.0596 Hz if I read the data correctly and this is also the resolution.

The big disadvantage to the 555 brigade (yes, I have used one recently) is that you need to control it with SPI so a small micro interface to a keypad might be a good idea. Hey you can even use the micro for telling you what frequency it's generating (via an LCD).

Maybe the arduino can do SPI?

  • \$\begingroup\$ This will give you what is called 'discrete jitter' of +/- 1/2 the sample clock period. This may or may not be acceptable. If this jitter is acceptable, then this is definitely the best solution as it has extremely high resolution and the frequency accuracy is tied to the crystal and not an RC circuit (as is the case for a 555). \$\endgroup\$ – alex.forencich Jul 15 '15 at 18:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.