Dependencies:   DMSupport DMemWin

Committer:
destinyXfate
Date:
Thu Jun 02 05:04:57 2016 +0000
Revision:
0:08606a13a816
;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
destinyXfate 0:08606a13a816 1 #include "ADC.h"
destinyXfate 0:08606a13a816 2
destinyXfate 0:08606a13a816 3 ADS8556::ADS8556(SPI *spi, PinName cs, PinName reset, PinName convst,
destinyXfate 0:08606a13a816 4 PinName busy) :
destinyXfate 0:08606a13a816 5 _spi(spi), _cs(DigitalOut(cs)), _reset(DigitalOut(reset)), _convst(
destinyXfate 0:08606a13a816 6 DigitalOut(convst)), _busy(DigitalIn(busy)) {
destinyXfate 0:08606a13a816 7 _convst = 0;
destinyXfate 0:08606a13a816 8 _reset = 0;
destinyXfate 0:08606a13a816 9 _cs = 1;
destinyXfate 0:08606a13a816 10 _spi->format(16, 2);
destinyXfate 0:08606a13a816 11 _spi->frequency(10000000);
destinyXfate 0:08606a13a816 12 _reset = 1;
destinyXfate 0:08606a13a816 13 wait_ns(50);
destinyXfate 0:08606a13a816 14 _reset = 0;
destinyXfate 0:08606a13a816 15
destinyXfate 0:08606a13a816 16 }
destinyXfate 0:08606a13a816 17
destinyXfate 0:08606a13a816 18 void ADS8556::adc(int16_t* data) {
destinyXfate 0:08606a13a816 19
destinyXfate 0:08606a13a816 20 _convst = 1;
destinyXfate 0:08606a13a816 21 wait_ns(20);
destinyXfate 0:08606a13a816 22 while (_busy != 0)
destinyXfate 0:08606a13a816 23 ;
destinyXfate 0:08606a13a816 24 _cs = 0;
destinyXfate 0:08606a13a816 25 wait_ns(5);
destinyXfate 0:08606a13a816 26 uint8_t i;
destinyXfate 0:08606a13a816 27 for (i = 0; i < 6; i++) {
destinyXfate 0:08606a13a816 28 *data++ = _spi->write(0x0000);
destinyXfate 0:08606a13a816 29 }
destinyXfate 0:08606a13a816 30 _cs = 1;
destinyXfate 0:08606a13a816 31 _convst = 0;
destinyXfate 0:08606a13a816 32
destinyXfate 0:08606a13a816 33 }
destinyXfate 0:08606a13a816 34
destinyXfate 0:08606a13a816 35 double toVoltage(int16_t adValue) {
destinyXfate 0:08606a13a816 36 return ((adValue + 32768) * 20.232 / 65535 - 10.116) / 1.01;
destinyXfate 0:08606a13a816 37 }
destinyXfate 0:08606a13a816 38
destinyXfate 0:08606a13a816 39 double ADS8556::get(int16_t* data, uint16_t channel, uint16_t num) {
destinyXfate 0:08606a13a816 40 double d = toVoltage(*(data + ((num * 6) + channel)));
destinyXfate 0:08606a13a816 41 return d;
destinyXfate 0:08606a13a816 42 }
destinyXfate 0:08606a13a816 43
destinyXfate 0:08606a13a816 44 double ADS8556::get2(int16_t* data, uint16_t channel, uint16_t num) {
destinyXfate 0:08606a13a816 45 int16_t d = *(data + ((num * 6) + channel));
destinyXfate 0:08606a13a816 46 return d;
destinyXfate 0:08606a13a816 47 }
destinyXfate 0:08606a13a816 48
destinyXfate 0:08606a13a816 49
destinyXfate 0:08606a13a816 50