Playing with analog-to-digital converter on Arduino Due

I like the Arduino platform. It makes using complex microcontrollers much simpler and faster. Lets take for example the analog-to-digital converter. To configure it even on Atmega328 (Arduino Uno/Duemilanove) you must understand and set correct values in 4 registers. And it can be much more in complex device, like 14 in ATSAM3X8E (Arduino Due)!
In Arduino, for no matter which processor, all you need to do is:

val = analogRead(A0);

It’s simple and useful. But there are situations, where you need to use more potential of your chip. Arduino allows you to do so – after all it’s just C++ with some additions.
In my project on Arduino Due I need to sample voltage continuously and as fast as possible. Lets try it the simplest way:

int input = A0;
int led = 13;
int val;
void setup()
void loop()
  val = analogRead(input);

Anything the program does is reading ADC and toggling the led line, so I can measure how fast it happens. So lets compile program and look at the oscilloscope:analog-to-digital converter

There is nice square ~100kHz wave. So the sampling frequency is about 100kS/s. Not bad, but according to datasheet it can be much higher (1Ms/s). And I’m not doing anything else, just reading ADC and wasting all the processor’s time. There is also another problem, which is clearly visible when looking on a wave with oscilloscope with persistence:Good news is that Arduino let’s you use almost all the capabilities of microcontroller by using low level C/C++ programming. Bad news – this is quite hard, especially with complex ARM processors. Processors peripherals’ documentation is large (about 100 pages in datasheet and two application notes for ADC alone). And it’s barely enough to understand all the details. Another useful info are examples available in Atmel Studio and the Arduino libraries’ source (\%arduino%\hardware\arduino\sam\cores\arduino).

For more detail: Playing with analog-to-digital converter on Arduino Due

© 2015 Powered By Engineering Projects Team, Raspberry Pi Projects

Scroll to top