Go Down

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

Riva

Jun 01, 2015, 12:41 pm Last Edit: Jun 02, 2015, 09:26 am by Riva Reason: Added Nuclio
While trying to determine the most suitable MCU for a project that needs fast analogue read I decided to knock up a quick bench-test sketch and run it on some of the various MCU's I have kicking around.
Hope the info is helpful and maybe others can add new MCU's or tests.
Quote
Arduino UNO I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About 4.50 Microseconds.
Digital Pin Read  Takes About 4.78 Microseconds.
Analogue Pin Read Takes About 112.00 Microseconds.

Arduino Mega I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About 6.50 Microseconds.
Digital Pin Read  Takes About 6.35 Microseconds.
Analogue Pin Read Takes About 112.01 Microseconds.

Arduino Due I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About 2.00 Microseconds.
Digital Pin Read  Takes About 1.11 Microseconds.
Analogue Pin Read Takes About 3.30 Microseconds.

Teensy 3.1 @ 24MHz I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About 1.00 Microseconds.
Digital Pin Read  Takes About 0.75 Microseconds.
Analogue Pin Read Takes About 12.88 Microseconds.

Teensy 3.1 @ 48MHz I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About 0.50 Microseconds.
Digital Pin Read  Takes About 0.38 Microseconds.
Analogue Pin Read Takes About 10.14 Microseconds.

Teensy 3.1 @ 72MHz I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About 0.00 Microseconds.
Digital Pin Read  Takes About 0.25 Microseconds.
Analogue Pin Read Takes About 7.59 Microseconds.

Teensy 3.1 @ 96MHz I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About 0.00 Microseconds.
Digital Pin Read  Takes About 0.19 Microseconds.
Analogue Pin Read Takes About 10.37 Microseconds.

Fubarino Mini (dev) I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About 1.50 Microseconds.
Digital Pin Read  Takes About 0.85 Microseconds.
Analogue Pin Read Takes About 8.77 Microseconds.

Nucleo STM32F401 I/O Speed Tests Over 1000000 Iterations.
Digital Pin Write Takes About 0.1668 Microseconds.
Digital Pin Read  Takes About 0.1788 Microseconds.
Analogue Pin Read Takes About 3.4917 Microseconds.

Don't PM me for help as I will ignore it.

Riva

#1
Jun 01, 2015, 12:46 pm Last Edit: Jun 02, 2015, 09:29 am by Riva Reason: Added some results
I have created another sketch for the AVR (UNO) that runs the ADC test using different pre-scaler settings.

The results on an UNO
Quote
Arduino UNO I/O Speed Tests Over 1000 Iterations.
ADPS2 Analogue Pin Read Takes About 4.96 Microseconds.
ADPS4 Analogue Pin Read Takes About 6.52 Microseconds.
ADPS8 Analogue Pin Read Takes About 10.04 Microseconds.
ADPS16 Analogue Pin Read Takes About 17.06 Microseconds.
ADPS32 Analogue Pin Read Takes About 30.12 Microseconds.
ADPS64 Analogue Pin Read Takes About 56.10 Microseconds.
ADPS128 Analogue Pin Read Takes About 112.00 Microseconds.
Don't PM me for help as I will ignore it.

Riva

What's an Arduino Duo?
Should have read Due and is now corrected thanks.
Don't PM me for help as I will ignore it.

robtillaart

Made the topic sticky because imho it is very informative.

athough some numbers make me think there is a loss of precision in the math somewhere.

Teensy 3.1 @ 48MHz I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About 0.50 Microseconds.
Digital Pin Read  Takes About 0.38 Microseconds.
Analogue Pin Read Takes About 10.14 Microseconds.

Teensy 3.1 @ 72MHz I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About 0.00 Microseconds.   <<<<<<<<< expected something like 0.33 here
Digital Pin Read  Takes About 0.25 Microseconds.
Analogue Pin Read Takes About 7.59 Microseconds.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Isaac96

The Teensy is fast! When the Tre and Zero come out, they should be benchmarked as well. (Not the 32u4 on the Tre, the Sitara.)
Do not PM me for help.Only links to topics.
CONNECT THE GROUNDS!

After Tuesday, even the calendar goes W T F

Riva

#5
Jun 02, 2015, 09:35 am Last Edit: Jun 02, 2015, 12:10 pm by Riva Reason: Code added
Made the topic sticky because imho it is very informative.

athough some numbers make me think there is a loss of precision in the math somewhere.
Yes there does appear to be some loss of precision, I should maybe have printed to 4 decimal places instead of the default 2 but I have got the results I need for analogue so will probably not alter the code and re-run the tests.
I have added a Nucleo to the results and I had to up the precision there to see anything.

EDIT: I have attached a slightly modified version that displays result to 4 decimal places instead of 2.
Don't PM me for help as I will ignore it.

westfw

Quote
Nucleo STM32F401 I/O Speed Tests Over 1000000 Iterations.
Digital Pin Write Takes About 0.1668 Microseconds.
Digital Pin Read  Takes About 0.1788 Microseconds.
Analogue Pin Read Takes About 3.4917 Microseconds.
Using what SW?  I didn't think the Nucleo supported Arduino libraries yet.

Riva

Using what SW?  I didn't think the Nucleo supported Arduino libraries yet.
The Nucleo is not supported yet but some other STM32 variants have Arduino cores here.
I converted the Benchmark sketch to suit mbed compiler.
Code: [Select]
#include "mbed.h"

#define targetBoard "Nucleo STM32F401"

AnalogIn analoguePin(A0);
DigitalIn digitalPinIn(USER_BUTTON);
DigitalOut digitalPinOut(LED1);

const unsigned int loopCount = 1000000;
Timer timeX;
Serial pc(USBTX, USBRX); // tx, rx

int main()
{
    unsigned int x;
    double ar;
    
    pc.printf(" *****************\n\n\n");
    while(1) {
        pc.printf(targetBoard);
        pc.printf(" I/O Speed Tests Over ");
        pc.printf("%d Iterations.\n", loopCount);
        wait_ms(1000);

        // Digital Write
        timeX.reset();
        timeX.start();
        for (x = 0; x < loopCount; x++) {
            digitalPinOut = 1;
            digitalPinOut = 0;
        }
        timeX.stop();
        pc.printf("Digital Pin Write Takes About %.4f Microseconds.\n", (double)timeX.read_us() / loopCount / 2.0 );
        wait_ms(1000);

        // Digital Read
        timeX.reset();
        timeX.start();
        for (x = 0; x < loopCount; x++) {
            ar = digitalPinIn;
        }
        timeX.stop();
        pc.printf("Digital Pin Read  Takes About %.4f Microseconds.\n", (double)timeX.read_us() / loopCount );
        wait_ms(1000);

        // Analogue
        timeX.reset();
        timeX.start();
        for (x = 0; x < loopCount; x++) {
            ar = analoguePin.read();
        }
        timeX.stop();
        pc.printf("Analogue Pin Read Takes About %.4f Microseconds.\n\n", (double)timeX.read_us() / loopCount );
        wait_ms(2000);
    }
}

Don't PM me for help as I will ignore it.

Coding Badly

#8
Jun 04, 2015, 10:27 am Last Edit: Jun 04, 2015, 10:29 am by Coding Badly
Quote
Arduino UNO I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About → 4.50 ← Microseconds.
Digital Pin Read  Takes About → 4.78 ← Microseconds.

Arduino Mega I/O Speed Tests Over 50000 Iterations.
Digital Pin Write Takes About → 6.50 ← Microseconds.
Digital Pin Read  Takes About → 6.35 ← Microseconds.
Something wrong with your Mega?  Was it running at 12 MHz?  Had too much beer the night before the test?

(The question is rhetorical; meant to goad you into investigating.  I know why there is a difference.)


Riva

Something wrong with your Mega?  Was it running at 12 MHz?  Had too much beer the night before the test?

(The question is rhetorical; meant to goad you into investigating.  I know why there is a difference.)
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.

Ideally the test sketch should do all the I/O pins and maybe include analogWrite() on supported pins but it served the purpose I needed. Maybe I or someone else can do comprehensive tests at some point.
Don't PM me for help as I will ignore it.

Riva

#10
Jun 05, 2015, 11:02 am Last Edit: Jun 05, 2015, 11:06 am by Riva
Ideally the test sketch should do all the I/O pins and maybe include analogWrite() on supported pins.
Starting to quote myself now LOL
Below is a new benchmark sketch that does test all the pins and the results obtained from the 3 boards I have configured and tested it for. Due to the added complexity of doing analogue read/write on boards with not consecutive analogue pins the sketch needs any new board types added & configured in the defines.

Code: [Select]
Benchmark V3.0 05-June-2015
Arduino UNO I/O Speed Tests Over 1000 Iterations. Compiled Using Arduino IDE v1.0.6

Digital Pin Read / Write Times In Microseconds.
 0 4.1520 / 4.1200
 1 4.1520 / 4.1200
 2 4.0880 / 4.1200
 3 4.9720 / 5.0020
 4 4.0880 / 4.1200
 5 4.9720 / 4.9980
 6 4.9080 / 4.9360
 7 4.0920 / 4.1200
 8 4.0920 / 4.1200
 9 4.7760 / 4.8140
 10 5.2840 / 5.3140
 11 4.9720 / 5.0000
 12 4.0920 / 4.1200
 13 4.0920 / 4.1200
 14 4.0880 / 4.1200
 15 4.0920 / 4.1200
 16 4.0920 / 4.1240
 17 4.0920 / 4.1200
 18 4.0880 / 4.1200
 19 4.0920 / 4.1200

Analogue Pin Read Times In Microseconds.
 A0 112.0960
 A1 112.0080
 A2 112.0080
 A3 112.0080
 A4 112.0080
 A5 112.0080

Analogue Pin Write Times In Microseconds.
 3 8.5120
 5 8.3240
 6 8.1400
 9 8.2000
 10 8.8320
 11 8.3880


Benchmark V3.0 05-June-2015
Arduino Leonardo I/O Speed Tests Over 1000 Iterations. Compiled Using Arduino IDE v1.0.6

Digital Pin Read / Write Times In Microseconds.
 0 4.5880 / 4.8740
 1 4.5960 / 4.8760
 2 4.5880 / 4.8720
 3 5.7280 / 6.0060
 4 4.5880 / 4.8760
 5 5.7280 / 6.0040
 6 6.4160 / 6.6960
 7 4.5960 / 4.8760
 8 4.5880 / 4.8760
 9 6.2920 / 6.5680
 10 6.3560 / 6.6340
 11 6.2280 / 6.5120
 12 4.5920 / 4.8760
 13 6.0880 / 6.3200
 14 4.5960 / 4.8760
 15 4.5960 / 4.8720
 16 4.5960 / 4.8760
 17 4.6560 / 4.8720
 18 4.5880 / 4.8760
 19 4.5960 / 4.8760

Analogue Pin Read Times In Microseconds.
 A0 112.1080
 A1 112.0040
 A2 112.0680
 A3 114.4760
 A4 112.5000
 A5 112.1400
 A6 112.1480
 A7 112.1640
 A8 112.1440
 A9 112.1320
 A10 112.1520
 A11 112.1480

Analogue Pin Write Times In Microseconds.
 3 8.2400
 5 8.3040
 6 9.4960
 9 8.8720
 10 9.1240
 11 8.6200
 12 13.0920
 13 8.8720


Benchmark V3.0 05-June-2015
Arduino MEGA2560 I/O Speed Tests Over 1000 Iterations. Compiled Using Arduino IDE v1.0.6

Digital Pin Read / Write Times In Microseconds.
 0 4.7200 / 4.9360
 1 4.7160 / 4.9400
 2 5.9120 / 6.1960
 3 6.6080 / 6.8860
 4 6.1640 / 6.4460
 5 6.6040 / 6.8900
 6 6.5480 / 6.8240
 7 6.6640 / 6.9500
 8 6.1640 / 6.4440
 9 6.3520 / 6.6360
 10 6.8560 / 7.1400
 11 6.5480 / 6.8260
 12 6.0400 / 6.3200
 13 6.7080 / 6.9520
 14 4.6600 / 4.9360
 15 4.6520 / 4.9380
 16 4.6600 / 4.9380
 17 4.6520 / 4.9340
 18 4.6520 / 4.9360
 19 4.6600 / 4.9400
 20 4.7160 / 4.9400
 21 4.7240 / 4.9360
 22 4.6600 / 4.9380
 23 4.6560 / 4.9380
 24 4.6600 / 4.9360
 25 4.6520 / 4.9400
 26 4.6560 / 4.9400
 27 4.6520 / 4.9360
 28 4.6520 / 4.9380
 29 4.6600 / 4.9380
 30 4.6520 / 4.9360
 31 4.6560 / 4.9360
 32 4.6520 / 4.9400
 33 4.6600 / 4.9400
 34 4.6600 / 4.9360
 35 4.6520 / 4.9400
 36 4.6600 / 4.9400
 37 4.6520 / 4.9360
 38 4.6560 / 4.9380
 39 4.6600 / 4.9380
 40 4.6560 / 4.9340
 41 4.6600 / 4.9380
 42 4.6520 / 4.9380
 43 4.6560 / 4.9360
 44 6.7360 / 7.0100
 45 6.5400 / 6.8260
 46 7.1080 / 7.3880
 47 4.6600 / 4.9380
 48 4.6560 / 4.9360
 49 4.6600 / 4.9360
 50 4.6520 / 4.9400
 51 4.6560 / 4.9380
 52 4.6520 / 4.9360
 53 4.6520 / 4.9380

Analogue Pin Read Times In Microseconds.
 A0 112.1080
 A1 112.0040
 A2 112.0040
 A3 112.0040
 A4 112.0040
 A5 112.0040
 A6 112.0040
 A7 112.0040
 A8 112.0040
 A9 112.0040
 A10 112.0040
 A11 112.0040
 A12 112.0040
 A13 112.0040
 A14 112.0080
 A15 112.0040

Analogue Pin Write Times In Microseconds.
 2 8.3960
 3 9.3400
 4 8.5880
 5 9.2160
 6 9.4000
 7 9.2760
 8 8.7760
 9 8.9000
 10 9.3400
 11 9.0240
 12 8.6440
 13 8.9680
 44 9.3400
 45 9.1520
 46 9.5920

Don't PM me for help as I will ignore it.

Riva

#11
Jun 16, 2015, 10:34 am Last Edit: Jun 16, 2015, 10:34 am by Riva Reason: Added test sketch
Yet another test. This time to determine accuracy & jitter while reading an analogue pin at different pre-scale ADC speeds.

First the test using a 10K trimpot connected between 5V & GND with the wiper set to 3.3V
Code: [Select]
Default ADCSRA = 10010111
Arduino MEGA ADC Accuracy Tests Over 500 Iterations.

ADPS2 (ADCSRA = 10010001)
 Baseline Reading: 768 Rolling Average: 768
 Maximum Reading: 768 Minimum Reading: 768 Maximum Jitter: 0

ADPS4 (ADCSRA = 10010010)
 Baseline Reading: 671 Rolling Average: 671
 Maximum Reading: 671 Minimum Reading: 671 Maximum Jitter: 0

ADPS8 (ADCSRA = 10010011)
 Baseline Reading: 675 Rolling Average: 675
 Maximum Reading: 675 Minimum Reading: 675 Maximum Jitter: 0

ADPS16 (ADCSRA = 10010100)
 Baseline Reading: 675 Rolling Average: 675
 Maximum Reading: 676 Minimum Reading: 675 Maximum Jitter: 1

ADPS32 (ADCSRA = 10010101)
 Baseline Reading: 675 Rolling Average: 675
 Maximum Reading: 676 Minimum Reading: 675 Maximum Jitter: 1

ADPS64 (ADCSRA = 10010110)
 Baseline Reading: 676 Rolling Average: 675
 Maximum Reading: 676 Minimum Reading: 675 Maximum Jitter: 1

ADPS128 (ADCSRA = 10010111)
 Baseline Reading: 675 Rolling Average: 675
 Maximum Reading: 676 Minimum Reading: 675 Maximum Jitter: 1

All results are pretty close to expected reading apart from the very fastest ADC read speed.

Second test is a bit pointless as I just left the pin floating but it's interesting (to me) that all subsequent reads after the initial baseline read are lower and generally the slower the ADC the more jitter.
Code: [Select]
Default ADCSRA = 10010111
Arduino MEGA ADC Accuracy Tests Over 500 Iterations.

ADPS2 (ADCSRA = 10010001)
 Baseline Reading: 560 Rolling Average: 574
 Maximum Reading: 575 Minimum Reading: 560 Maximum Jitter: 15

ADPS4 (ADCSRA = 10010010)
 Baseline Reading: 572 Rolling Average: 572
 Maximum Reading: 572 Minimum Reading: 572 Maximum Jitter: 0

ADPS8 (ADCSRA = 10010011)
 Baseline Reading: 568 Rolling Average: 568
 Maximum Reading: 568 Minimum Reading: 568 Maximum Jitter: 0

ADPS16 (ADCSRA = 10010100)
 Baseline Reading: 563 Rolling Average: 560
 Maximum Reading: 563 Minimum Reading: 560 Maximum Jitter: 3

ADPS32 (ADCSRA = 10010101)
 Baseline Reading: 559 Rolling Average: 509
 Maximum Reading: 559 Minimum Reading: 509 Maximum Jitter: 50

ADPS64 (ADCSRA = 10010110)
 Baseline Reading: 537 Rolling Average: 455
 Maximum Reading: 537 Minimum Reading: 455 Maximum Jitter: 82

ADPS128 (ADCSRA = 10010111)
 Baseline Reading: 514 Rolling Average: 426
 Maximum Reading: 514 Minimum Reading: 426 Maximum Jitter: 88
Don't PM me for help as I will ignore it.

ArthurD

#12
Aug 22, 2015, 06:11 pm Last Edit: Aug 22, 2015, 06:17 pm by ArthurD
here's a benchmark test, admittedly just about Mega and Due, but some other 3rd party MCUs additionally, performing different low- and high-level computing tests for integer, floats, binay shift, array sort, matrices,  and much more, maybe some one may find it useful:

http://www.mindstormsforum.de/viewtopic.php?p=64772#p64772

Go Up