Go Down

Topic: Microcontroller I/O & ADC Benchmarks (Read 5505 times) previous topic - next topic

spirit

hi.

i did also make a sketch to benchmark the IO/analog speed. on a DUE

here are the results:
Code: [Select]
Digital IO results
Pin.no / DigitalWrite / WriteReg / DigitalRead / ReadReg / PWM
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| Pin 0|| Pin 1|| Pin 2|| Pin 3|| Pin 4|| Pin 5|| Pin 6|| Pin 7|| Pin 8|| Pin 9|| Pin10|| Pin11|| Pin12|| Pin13|| Pin14|| Pin15|| Pin16|| Pin17|| Pin18|| Pin19|| Pin20|| Pin21|| Pin22|| Pin23|| Pin24|| Pin25|| Pin26|| Pin27|| Pin28|| Pin29|| Pin30|| Pin31|| Pin32|| Pin33|| Pin34|| Pin35|| Pin36|| Pin37|| Pin38|| Pin39|| Pin40|| Pin41|| Pin42|| Pin43|| Pin44|| Pin45|| Pin46|| Pin47|| Pin48|| Pin49|| Pin50|| Pin51|| Pin52|| Pin53|
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 1.23 || 1.15 || 1.40 || 1.35 || 1.35 || 1.27 || 1.40 || 1.35 || 1.35 || 1.27 || 1.40 || 1.35 || 1.35 || 1.27 || 1.28 || 1.23 || 1.23 || 1.15 || 1.28 || 1.23 || 1.35 || 1.27 || 1.40 || 1.35 || 1.35 || 1.27 || 1.40 || 1.35 || 1.35 || 1.27 || 1.40 || 1.35 || 1.35 || 1.27 || 1.40 || 1.35 || 1.35 || 1.27 || 1.40 || 1.35 || 1.35 || 1.27 || 1.40 || 1.35 || 1.35 || 1.27 || 1.40 || 1.35 || 1.35 || 1.27 || 1.40 || 1.35 || 1.35 || 1.15 |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 1.09 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 0.14 || 0.14 || 0.13 || 0.14 || 0.13 || 0.14 || 0.14 || 0.14 || 0.13 || 0.13 || 0.13 || 0.13 || 0.14 || 0.13 || 0.14 || 0.13 || 0.13 || 0.14 || 0.13 || 0.14 || 0.13 || 0.13 || 0.14 || 0.13 || 0.14 || 0.13 || 0.13 || 0.14 || 0.13 || 0.14 || 0.13 || 0.13 || 0.14 || 0.13 || 0.14 || 0.13 || 0.13 || 0.14 || 0.13 || 0.14 || 0.13 || 0.13 || 0.14 || 0.13 || 0.14 || 0.13 || 0.13 || 0.14 || 0.13 || 0.14 || 0.13 || 0.13 || 0.14 || 0.13 |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| 3.92 || 3.91 || 3.84 || 3.91 || 2.76 || 2.76 || 2.76 || 2.76 || 3.84 || 3.91 || 3.84 || 3.84 |
------------------------------------------------------------------------------------------------
Analog / Digital IO results
Pin.no / DigitalWrite / WriteReg / DigitalRead / ReadReg / AnalogRead 8bit / AnalogRead 10bit / AnalogRead 12bit
--------------------------------------------------------------------------------------------------------------------------------
| Pin 0|| Pin 1|| Pin 2|| Pin 3|| Pin 4|| Pin 5|| Pin 6|| Pin 7|| Pin 8|| Pin 9|| Pin10|| Pin11|| Pin12|| Pin13|| Pin14|| Pin15|
--------------------------------------------------------------------------------------------------------------------------------
| 1.41 || 1.36 || 1.36 || 1.28 || 1.41 || 1.36 || 1.36 || 1.28 || 1.41 || 1.36 || 1.36 || 1.28 || 1.29 || 1.36 || 1.25 || 1.16 |
--------------------------------------------------------------------------------------------------------------------------------
| 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 || 0.05 |
--------------------------------------------------------------------------------------------------------------------------------
| 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 || 1.13 || 1.08 || 1.08 || 1.04 |
--------------------------------------------------------------------------------------------------------------------------------
| 0.12 || 0.12 || 0.12 || 0.12 || 0.12 || 0.12 || 0.12 || 0.12 || 0.12 || 0.12 || 0.12 || 0.12 || 0.12 || 0.12 || 0.12 || 0.12 |
--------------------------------------------------------------------------------------------------------------------------------
| 3.39 || 3.38 || 3.38 || 3.38 || 3.38 || 3.38 || 3.38 || 3.38 || 3.38 || 3.38 || 3.38 || 3.38 |
------------------------------------------------------------------------------------------------
| 3.47 || 3.47 || 3.47 || 3.47 || 3.47 || 3.47 || 3.47 || 3.47 || 3.47 || 3.47 || 3.47 || 3.47 |
------------------------------------------------------------------------------------------------
| 3.40 || 3.40 || 3.40 || 3.40 || 3.40 || 3.40 || 3.40 || 3.40 || 3.40 || 3.40 || 3.40 || 3.40 |
------------------------------------------------------------------------------------------------

all are 50000 Iterations.

and for WriteReg and ReadReg i used this code:
Code: [Select]
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;
}

inline int digitalReadDirect(int pin) {
  return !!(g_APinDescription[pin].pPort -> PIO_PDSR & g_APinDescription[pin].ulPin);
}

DrDiettrich

I had noticed the Mega seemed slower at digital I/O but never bothered to investigate as it was analogue I was interested in. Maybe it's due to core differences in how pins are read/written as pin 9 is PWM on both UNO & MEGA and don't seem to serve as multi function pins (I2C, SPI, UART etc.) that may slow things down. The only other possibility I can think of is interrupt overheads as I don't disable them for testing but analogue read is the same between both UNO & Mega.
The Mega has at least one overly bloated #define for the digitalPinToPCICRbit macro, in the 1.6.7 version. The 6 comparisons of the pin number could be reduced to 2, which yield a result different from zero.

Dunno if that (all those #defines in pins_arduino.h) affects digital I/O timing, though. The mapping of pins to ports and bits is straight forward (array index), no comparisons there.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy