Quantcast
Channel: Intel Communities: Message List
Viewing all articles
Browse latest Browse all 20046

Performing a sequence of analogReads faster?

$
0
0

I am working on a program that performs a sequence of 512 analogReads. The analogRead function is not particularly fast. I have found that it takes approximately 7 ms before the converted value is available to use within the program.

 

I have noticed that the Galileo board uses a I2C interface with the Mux, and SPI interface with the ADC. However, during a long sequence of sequential reads, the Mux should not need to be changed since all of the A/D conversions are being performed from the same analog input port (A0, for example).

 

So, is there anyway that I could write a function that would setup the Mux once in the beginning in order to decrease the overall conversion time? Are there any low-level Linux-based functions that I could call in order to interface with the Mux and A/D?

 

I found the code below at this website: (Faster Analog Read? - Arduino Forum)

 

The code changes ADC clock prescaler, causing the A/D conversion to be completed more quickly. The code works on an Arduino Uno but not the Galileo Board. How could this code be modified to function with the Galileo Board?

#define FASTADC 1

 

// defines for setting and clearing register bits

#ifndef cbi

#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))

#endif

#ifndef sbi

#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))

#endif

 

void setup() {

  int start ;

  int i ;

 

#if FASTADC

  // set prescale to 16

  sbi(ADCSRA,ADPS2) ;

  cbi(ADCSRA,ADPS1) ;

  cbi(ADCSRA,ADPS0) ;

#endif

 

  Serial.begin(9600) ;

  Serial.print("ADCTEST: ") ;

  start = millis() ;

  for (i = 0 ; i < 1000 ; i++)

    analogRead(0) ;

  Serial.print(millis() - start) ;

  Serial.println(" msec (1000 calls)") ;

}

 

void loop() {

}


Viewing all articles
Browse latest Browse all 20046

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>