Go Down

Topic: code size (Read 2 times) previous topic - next topic

Coding Badly

explain why the manufacturer puts such was wide range on possible convertion times


13/125000*1000000 ...13 clock cycles / 125000 clock cycles per second * 1000000 microseconds per second.

The 125000 can be configured and depends on the processor's clock rate.

Coding Badly

Consider what happens if the first approximation just happens to match the input data within the required resolution. The comparator output shows conversion is finished.


Nope.  The comparator indicates less-than or greater-than but not equals.  AWOL is correct.  One clock cycle per bit plus a few for overhead.

Quote
I suppose you also think that quicksort also takes exactly the same number of iterations irrespective of the data it is sorting.


Why do you mention quick sort?  It's a successive approximation converter not a quick sort converter.

Quote
Now since that is roughly midway between 13 and 250 us , perhaps the "typical" conversion time is indeed 13 clock cycles or 104 us .


A conversion is always 13 clock cycles (25 after changing channels).

jraskell

Code: [Select]



void setup()
{
    Serial.begin(115200);
    unsigned int maxReadTime = 0, minReadTime = 1000, singleReadTime, ReadVal;
    unsigned long AccumulatedTime = 0;
    ReadVal = analogRead(A0);
    for(int x = 0; x < 1000; x++)
    {
        singleReadTime = micros();
        ReadVal = analogRead(A0);
        singleReadTime = micros() - singleReadTime;
       
        AccumulatedTime += singleReadTime;
       
        if(singleReadTime > maxReadTime) maxReadTime = singleReadTime;
        if(singleReadTime < minReadTime) minReadTime = singleReadTime;
       
    }
   
    Serial.print("Min: ");
    Serial.println(minReadTime);
    Serial.print("Max: ");
    Serial.println(maxReadTime);
    Serial.print("Avg: ");
    Serial.println(AccumulatedTime/1000);
   
}


void loop()
{
   
}


Running that code, I get the following output (thereabouts anyways, there is some occasional variation)
Min: 112
Max: 124
Avg: 116

Comment out the initial analogRead, and you'll see Max jump to around 212, which nicely correlates with the 25 cycles for the initial conversion.

There is simply no rational arguing with empirical data.


ardnut

jraskell, what was the input signal for that test?

AWOL

Do you seriously think it matters?

Quote
I suppose you also think that quicksort also takes exactly the same number of iterations irrespective of the data it is sorting.

No, that would be foolish.

Think, it's a RISC processor, and an extremely low cost one at that.
Ever seen quick sort or anything similar implemented in RISC hardware?
Thought not.

Yesterday I deleted a post by a user on this thread that I thought was inflammatory, but now I'm beginning to see the truth in it.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up