Back to photostream

arduino . digital 002

Following on from my previous warm-up exercises, I decided to see how fast the Arduino could drive the output pins between HIGH and LOW, and to try and see how clean the wave looked.

 

Reusing the same square wave sketch...

 

int p = 13;

int del = 10;

 

void setup()

{

pinMode(p, OUTPUT);

}

 

void loop()

{

digitalWrite(p, HIGH);

delay(del);

digitalWrite(p, LOW);

delay(del);

}

 

...I tweaked the value 'del' that controls the time spent at each state.

 

del = 5 ms, expected 100 Hz, actual 99.7 Hz

del = 2 ms, expected 250 Hz, actual 245.9 Hz

del = 1 ms, expected 500 Hz, actual 488.1 Hz

del = 0 ms, no expectable value, actual 5490 Hz

 

All of these frequencies are audible if conducted through a speaker or piezo.

 

In the last of these above results the delay instruction was passed a zero value. However the act of calling this instruction takes some measurable time. A version of the code in which the delay statement has been completely removed (pictured above, bottom right) drives the output pin between HIGH and LOW at a staggering 135,000 Hz, which is about 25 times faster than when the delay statements are included but passed a zero value. This frequency is inaudible, at least to me :)

 

Actually my multimeter measured all the frequencies I listed above, but we can cross check using the multimeter's display. Note that the time axis is set to 1usec (microsecond, or 0.000001 seconds) per horizontal unit (bottom left image). We see our cycles takes somewhere around 7.5 units to complete (top left image). The calculation 1/135000 yields 7.407e-6 (the result in the photo is out by 1000) which corresponds to 7.407 usec, or 7.4 units on the screen. Bingo.

 

The peak-to-peak voltage is still just under 5 V. Note that my probes amplify the signal x10, hence the vertical scale being 0.1V per unit and not 1V per unit.

 

Oh and I ran the Arduino at 135kHz for about 30 minutes (the phone rang) and it remained quite cool.

 

The signal quality seems pretty good to me too (top left). Note the small reflections/overshoot at each transition. These were not noticable at lower output frequencies.

 

In fairness, the only Arduino application that could drive an output at that speed is the one shown here. Any additional instructions (even a delay(0) statement) would take some time to execute and hence lower the output frequency considerably.

 

For my purposes the Arduino seems like a very capable chip and I'm looking forward to starting my first project once I've worked which bits of junk around the flat can be fabricated into a solenoid...

1,494 views
1 fave
1 comment
Uploaded on April 20, 2008