Pages: [1]   Go Down
Author Topic: due speed specs?  (Read 1279 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 4
Posts: 1730
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I haven't got one yet and im debating not on getting one but how soon I want one lol, but just curious has anyone done any testing/breakdowns on the speed of common I/o actions? Like analogwrite/read digitalwrite/read as well as the new dac features
also if anyones up to it perhaps some tips on more direct ways and the different that would make
Logged

Offline Offline
God Member
*****
Karma: 32
Posts: 506
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did do some profiling for my digitalWriteDirect function:
Code:
inline void digitalWriteDirect(int pin, boolean val){
  if(val) g_APinDescription[pin].pPort -> PIO_SODR = g_APinDescription[pin].ulPin;
  else    g_APinDescription[pin].pPort -> PIO_CODR = g_APinDescription[pin].ulPin;
}


void setup() {               
  pinMode(13, OUTPUT); 
  Serial.begin(9600); 
}


void loop() {
  long t;
 
  delay(1000);
  t=micros();
  for(int i=0;i<1000000;i++){
    digitalWriteDirect(13,HIGH); 
    digitalWriteDirect(13,LOW);
  }
  t=micros()-t;
  Serial.print("digitalWriteDirect : 1 million blinks in ");
  Serial.print(t);
  Serial.print(" uS = ");
  Serial.print(1000000.0/t);
  Serial.println(" MHz");
 
  delay(1000);
  t=micros();
  for(int i=0;i<1000000;i++){
    digitalWrite(13,HIGH); 
    digitalWrite(13,LOW);
  }
  t=micros()-t;
  Serial.print("digitalWrite: 1 million blinks in ");
  Serial.print(t);
  Serial.print(" uS = ");
  Serial.print(1000000.0/t);
  Serial.println(" MHz"); 
 
}

digitalWriteDirect : 1 million blinks in 107251 uS = 9.32 MHz
digitalWrite: 1 million blinks in 4682844 uS = 0.21 MHz

I think digitalWrite on the Uno was about half as fast
Logged


Offline Offline
Edison Member
*
Karma: 4
Posts: 1730
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Wow that directwrite is amazingly fast, atleast compared to a regular 328 lol, funny how much slower the regular write is, just like it is on the uno
Logged

Venezuela
Offline Offline
Sr. Member
****
Karma: 12
Posts: 435
Ground.......ground........always ground
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here the results in my Due:

digitalWriteDirect : 1 million blinks in 107251 uS = 9.32 MHz
digitalWrite: 1 million blinks in 5135730 uS = 0.19 MHz

Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 106
Posts: 6381
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The current implementation of digitalWrite() for Due is pretty icky, using an Atmel-provided function that does the equivalent of both pinMode() and digitalWrite() for each call (plus the relatively significant added overhead of the additional function call.)  It's the sort of penalty you pay for putting one abstraction on top of another :-(

Given the long-time resistance of the Arduino team to speed improvements in similar areas, or to provide digitalWriteFast(), I wouldn't be inclined to expend much effort on making improvements.  But it would be nice if digitalWrite() on Due was faster than digitalWrite() on Uno, at least in a ratio similar to their clock rates.
Logged

Pages: [1]   Go Up
Jump to: