September 3, 2010
Hello,
The primary reason I am interested in switching from the Arduino to the Maple is the improved ADC resolution of the Maple (the Arduino has 10-bit ADC while the Maple has 12-bit ADC). The faster ADC sample rate of the STM32 chip is a nice bonus.
In http://forums.leaflabs.com/topic.php?id=149#post-942 gbulmer said:
To be fair, 850K samples/second, on each of two or three ADC's, is so much better than an Arduino's <10k samples/second
This statement is correct, because in section 11.2 of the STM32 reference manual (file 13902.pdf) it says the ADC conversion time is "1.17 microseconds at 72 MHz".
1 / 1.17 microseconds per read = 854,700 samples/second
I decided to do a quick speed comparison using analogPin 0. I agree that sample rate is only one criteria for judging and using ADC data, but I did not examine the values of the analog reads.
The rate I found for the Maple (roughly 150,000 samples/second) is only one-sixth the expected rate.
Is there some ADC overhead which I am not considering? Are there different ways to make the Maple ADC reads faster?
On page 51 of the Insider's Guide to the STM32 ARM Based Microcontroller (file 1221142709.pdf) it says "each ADC channel may be configured with an individual sample rate" (5.1.3.1) and the graphic shows eight options (1.5, 7.5, 13.5, 28.5, 41.5, 55.5, 71.5, and 239.5 cycles).
In the Maple-IDE 0.0.6 how is each ADC channel configured?
Am I interpreting the STM32 documentation correctly? An explanation of the current Maple code will hopefully help me when I am reading relevant descriptions of DMA. Apparently, the ADC can utilize DMA.
Thanks!
Stephen from NYC
/*
Analog Read (Pin 0) Speed Test
Created 2 September 2010, last updated 03 September 2010
By leaflabs.com forums member "Stephen from NYC"This code is released under a Creative Commons Attribution-Share Alike 3.0 license.
Maple Rev 3 (IDE 0.0.6): STM32 Cortex M3
1000 reads: 7 milliseconds
10000 reads: 68 milliseconds
100000 reads: 683 milliseconds
1000000 reads: 6825 millisecondsCalculations: 6.825 microseconds per analogRead() for the Maple Rev 3 [146,520 analogReads per second]
Arduino Duemilanove 2009 (IDE 017): ATMega 328
1000 reads: 112 milliseconds
10000 reads: 1120 milliseconds
100000 reads: 11200 millisecondsCalculations: 112 microseconds per analogRead() for the Arduino Duemilanove [8,928 analogReads per second]
Conclusion: Using this simple benchmark the Maple is 16.4X faster than the Arduino. A signficant increase, but not as large as one would expect from the specifications.
*/
#define COMM SerialUSB // use this for Maple
// #define COMM Serial // use this for Arduinounsigned long start=0;
unsigned long stop=0;unsigned long counter=0;
unsigned long limit=1000;
void setup()
{
// the following line is needed for Maple
pinMode(0, INPUT_ANALOG);// the following line is needed for Arduino
// COMM.begin(57600);
}void loop()
{
COMM.println("\nStarting loops:");start=millis();
counter=0;
while (counter++ < limit)
{
analogRead(0);
}stop=millis();
COMM.println("Stop loops:");
COMM.print("Elapsed Time: ");
COMM.print(stop-start);
COMM.print(" milliseconds (for ");
COMM.print(limit);
COMM.println(" analog reads)");
}