Analog Devices 16 channels, 1MSPS, 12bit ADC with SPI interface
Analog Devices' AD7490 A/D converter chip is a great choice to increase ADC channels to mbed. I wrote a C++ class library, which allows multiple chips on the same SPI serial bus line.
main.cpp - usage of sequential mode (use 2 ADCs)
#include "mbed.h"
#include "AD7490.h"
DigitalOut myled(LED1);
SPI spi(p11,p12,p13);
int main() {
// set up SPI interface.
// should be set before call AD7490 constructer
spi.format(16,0);
spi.frequency(1000000);
// construct AD7490 instances
AD7490 ad1(spi, p9);
AD7490 ad2(spi, p10);
// start ad conversion with sequential mode
ad1.sequential();
ad2.sequential();
while(1) {
short ad_data[32]; // user buffer area
myled = 1;
ad1.read(&ad_data[ 0]); // save the first ADC data to buffer
ad2.read(&ad_data[16]); // save the second ADC data to buffer
myled = 0;
for(int i=0; i<32; i++)
printf("ch[%2d]: %d\n", i, ad_data[i]);
puts("");
wait(1);
}
}
API
| AD7490 | |
| AD7490(SPI _spi, PinName _cs) | Constructor. needs SPI instance and the Chip select pin |
| unsigned short convert(int ch=0) | Single channel (one shot) conversion. |
| void convert(short data[]); | All channels conversion with multiple 'one shot conversion' |
| unsigned short sequential(int ch=15); | Start sequential mode, from channel 0 to 'ch'. ch=15 is default |
| void read(short buffer[]); | Read data channel [0] to [ch], and copy them to user buffer area |
AD7490.h
- Committer:
- ykuroda
- Date:
- 2012-09-24
- Revision:
- 4:f059fdd25051
- Parent:
- 3:b7e72acaade2
File content as of revision 4:f059fdd25051:
//
// AD7490 ... Analog Devices 16 channels, 1MSPS, 12bit ADC
//
// 2012.08.29 ... Originaly written by Yoji KURODA
//
#ifndef _AD7490_H
#define _AD7490_H
class AD7490 {
protected:
enum CREG {
CREG_WRITE = 0x800,
CREG_SEQ = 0x400,
CREG_ADD3 = 0x200,
CREG_ADD2 = 0x100,
CREG_ADD1 = 0x080,
CREG_ADD0 = 0x040,
CREG_PM1 = 0x020,
CREG_PM0 = 0x010,
CREG_SHADOW = 0x008,
CREG_WEAK = 0x004,
CREG_RANGE = 0x002,
CREG_CODING = 0x001
};
SPI spi;
DigitalOut cs;
unsigned short read(void); // dummy read for triggering at sequential mode
public:
AD7490(SPI _spi, PinName _cs);
virtual ~AD7490(){};
unsigned short convert(int ch=0); // one shot conversion at channel [ch]
void convert(short data[]); // convert all (16) channels with one short conv.
unsigned short sequential(int ch=15); // start sequential mode from channel [0] to [ch]
void read(short data[]); // read [0] to [ch], and copy to user area
};
#endif // _AD7490_H
Yoji KURODA