Show Posts
Pages: [1]
1  Products / Arduino Due / Re: Analog I/O Pins and ADC Sampling Frequency on: May 02, 2013, 03:43:46 pm
I am also interested in knowing how to increase the speed of digitalRead() and digitalWrite().

I know there's a library with faster calls for that operation, but I don't know if it supports the Arduino DUE.

The values I have currently are enough for a simple input / output measurement, but I am concerned with accuracy loss the more pins are used.
2  Products / Arduino Due / Re: Analog I/O Pins and ADC Sampling Frequency on: May 02, 2013, 12:12:02 am
Ok, here's some testings I made, I really don't know what I'm doing, but if someone assures me there's no danger of frying my board with this, I'll be happy... see my comments:

#define MAX_ADC_RESOLUTION 10 //changing resolution doesn't seem to affect sampling rate speed in this test

void setup() {
  //I tested this with a hall sensor, not sure if results will vary according to the sensor used, but please be gentle with me, I just started learning this 3 days ago, I'm just an amateur programmer. :-)

  //check adc.h in the /sam folder
  analogReadResolution(MAX_ADC_RESOLUTION); //
  //by default, I get around 25000 samples per second, readings around 570 ( 10bit ) with a hall sensor plugged in
  //adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX*2, 1); //~313000 samples per second, A/D readings kaput
  //adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX*2, 2); //~288 000 samples per second, A/D readings now have about 10% deviation
     adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX*2, 3); //~267000 samples per second, A/D readings OK, the best compromise I got
  //adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX*2, 4); //~220000 samples per second, A/D readings OK
  //adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX*2, ADC_STARTUP_NORM ); //~65000 samples per second,A/D readings OK
  //adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX*2, ADC_STARTUP_FAST ); //~47000 samples per second, from the name, I was tempted to think this would perform better. But I know nothing.

  edit: correction, I missed that 4 bit part from Dave's documentation. :-/

void loop() {  
  int start = millis();
  int num_samples = 0;
  //just to evaluate any possible accurancy degradation while messing around with this
  int value = 0;
  int max_value = 0;
  int min_value = 2^MAX_ADC_RESOLUTION;
  //let's see how many samples we can read in 1 second
  while( millis() - start < 1000 )
    value = analogRead(ADC0);
    if(value > max_value )
    max_value = value;
    if(value < min_value )
    min_value = value;

  // print out the control results
  Serial.println("\nsamples read: ");
  Serial.println("\nMax value: ");
  Serial.print( max_value );
  Serial.println("\nMin value: ");
  Serial.print( max_value );

Any thoughts?
3  Products / Arduino Due / Re: Analog I/O Pins and ADC Sampling Frequency on: May 01, 2013, 11:24:37 pm

I am also interested in knowing more about this, I found some information about how to increase other Arduino boards sampling frequency, but there is very little about the DUE.

Jason504, thanks for this information, I was able to double the default ADC samplerate adding that to the setup() function ( but I would still need at least 100Khz ).

I bought the DUE because it had better processing capabilities, looking forward to see further developments in this part.
Pages: [1]