Delay Query; further info on reading from the ADC?

Hi all, first time user here (got my hands on a diecimila yesterday).

As a first project, i wanted to modify the standard pot-controlled led flashing tutorial so that

1: it reacted pretty much straight away, and 2: the timing was scalable.

My idea was to loop a polling command and have a delay which is then used to scale the maximum delay. The program works well (the flashing rate scales quite linearly), but I seem to hit a wall around 100microseconds or so. After this point, the slowest flashing rate (maximium reading, or 100*1023 microseconds) does not increase.

I think I may be hitting the processing limit of the cpu here, and would like to find a better way to poll an input (and react accordingly) every x microseconds.

int potPin = 5;    
int ledPin = 13;   
int onems = 0;
int ledstate = HIGH;

void setup() {
  pinMode(ledPin, OUTPUT);
void hope (int tval) {
  if (onems >= tval + 1) {
    if (ledstate) {
        digitalWrite(ledPin, HIGH);
        onems = 0;
        ledstate = LOW;
      else {
        digitalWrite(ledPin, LOW);
        onems = 0;
        ledstate = HIGH;
  else {
void loop() {
  //Serial.println(val, DEC);

This link seems to make use of the commands I need, but can make head nor tail of it without some sort of reference:

The wall you are hitting is the time it takes analogRead to return the pot value. Changing the sampling rate of the analog to digital converter (ADC) was covered in a thread recently so you may want to do search to see how to do that.
is what I found. Making this modification did indeed reduce the latency significantly! (and apparently the ADC has a lot of headroom, well beyond the maximum frequency of this chip!).

All working well now, want to reduce the amount of cycles needed for an analogRead() further! How do you go about getting this info direct from the ADC? is nice, but… someone needs to spell it out for this dumbo <---- :-[ 16microseconds is too long!

16microseconds is too long!

How fast is fast enough?

One of the pleasures of the arduino environment is that it insulates newcomers from the complexity of accessing the low level chip registers. The Arduino abstractions like analogRead and digitalWrite sacrifice execution speed for ease of use. If you are out to squeeze the maximum performance out of the ATmega168 chip you may find more information on this topic in the avrfreaks forum:

You will find there is a significant learning curve if you delve under the Arduino covers, is your goal to learn about this technology or just to realize a specific project.

I must admit that by nature I tend to grab tendrils and wring them for all that I can get ;)

My main goal at the moment is to get a handle on running programs in a finite state machine kind of way, so that I can process multiple inputs and outputs in as near to real time as possible. One goal is to drive more than 1 stepper motor from more than 1 individual input. Will see how far I can get 8-)

Thank you for the link :) It is nice to know that if i ever get stuck or sick of complexities; the arudino will let me go back to nice and easy. I am certainly very impressed with how easy it is for a new comer to get up and running with this!