Author Options:

Arduino High Frequency? Answered

I have an Arduino Duemilanove and was wanting to know how and/or what I need to do to create a high frequency signal. I dont have a set frequency in mind but would rather know how to change it so I can gradually step it up until I get desired results.....Have looked at a lot of stuff on google for how to do this and most refer to a wiring.c file but mine appears to be an updated version to what they have...Anyways any help would be greatly appreciated =)?


The best way to get high frequency clocks out of an arduino is to play with the internal counter/timers - its an advanced topic in Arduino coding.

What is the signal for? Is the signal integral to the operation of the program? Will the frequency need to be fixed? Could you instead produce an signal generator external to the arduino?

I would prefer it to be a fixed frequency that I can adjust through the code...I have looked at some more complex embedded frequencies and that is definitely to much for me at this time.... When it is all said and done it will be a set frequency but I really need to experiment with several different ones to get my desired effect, plus I think it would be good know. So if you have any ideas please post them and I will def. try them =)

A very simple Low Frequency solution with 50% duty cycle on pin 13 is included below for what it is worth.

It has a few problems preventing it from reaching higher frequencies:
1.  One could use delayMicroseconds to shorten the delay times. Even then the delay must be 3 or higher.
2.  digitalWrite is VERY slow.  One can speed up the output by writing directly to the output port.
3.  Software-controlled frequency may get you up to 1MHz or so with very little control.  As you go higher the minimum step between frequencies gets larger.  You might achieve 1MHz and the next step being 500 kHZ.  You just can't get 792 kHz (or some other odd-frequency)

/* Low Frequency Sweep */
// set pin numbers:
const int ledPin = 13; // the number of the LED pin

// Variables will change:
long interval = 1000; //interval to blink the output pin in miliseconds

void setup()
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);

void loop()
  if (interval > 1)
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin, HIGH);
    interval = interval - 1;

Best Wishes

Thanks for the quick response, I will look into this method and see if this is going to work for me...I will post again letting everyone know if it worked or failed....or if I find something that does what I need.

Like I said I dont really have a set frequency I basically want to try a few different frequencies with a project I am working on and would like to know how to (if possible) increase frequency. I have tried several 555 timers to create fast pulsating circuits but none yet have been fast enough.... I was hoping that with the arduino I could perhaps 'easily' change numbers or whatever to increase frequency...