1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Processing time

Discussion in 'Arduino' started by renzen, Sep 23, 2015.

  1. renzen

    renzen Member

    Joined:
    Jan 4, 2013
    Messages:
    43
    Likes:
    0
    The code:
    Code (text):

    unsigned long t1[10], t2[10];
    int i,j;
    void setup() {
      Serial.begin(9600);
      }
    void loop() {  
      for(i=0;i<10;i++) {
      t1[i] = micros();
      j++;
      t2[i] = micros();
      }
      Serial.println("\nrun");
      for(i=0;i<10;i++) {
      Serial.print(t2[i] - t1[i]);
      Serial.print(" us\n");
      }
      delay(10000);
      j=0;
      }
     
    Result:
    temp.jpg

    Is it possible reduce the processing time below 1us?
    If not possible, it's because:
    - Because it's running on Arduino IDE?
    or
    - Because it's the total process time from: read number of microseconds - write to t1 array- read j from memory - increment j - writing j to memory - read number of microseconds - write to t2 array?
    or ....?
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,323
    Likes:
    653
    Location:
    Derbyshire, UK
    I would imagine it's also the unwanted time serial printing as well?.

    But 4uS times for operations in C look pretty reasonable, I also seem to recall that the uS timings aren't particularly accurate anyway?.

    I 'think' the Arduino usually runs at 16Mhz?, but I've no idea how long each machine code instruction takes, but regardless you won't get many in only 4uS.
     
  3. renzen

    renzen Member

    Joined:
    Jan 4, 2013
    Messages:
    43
    Likes:
    0
    Hi,
    Uhmmm... I don't think so. Because the serial printing is not in the same loop(for i loop).


    I'm not sure, but I use same method like this person who testing ADC processing time.
     
    Last edited: Sep 23, 2015

Share This Page