5#define ADC_WAKE 0b00000000
6#define ADC_SYNC 0b00000100
7#define ADC_RESET 0b00000110
8#define ADC_RDATA 0b00010010
9#define ADC_RDATAC 0b00010100
10#define ADC_SDATAC 0b00010110
11#define ADC_SELFOCAL 0b01100010
12#define ADC_NOP 0b11111111
13#define ADC_NOP24 0xFFFFFF
14#define ADC_RREG 0b0010
15#define ADC_WREG 0b0100
18#define ADC_REG_MUX0 0x0
19#define ADC_REG_VBIAS 0x1
20#define ADC_REG_MUX1 0x2
21#define ADC_REG_SYS0 0x3
22#define ADC_REG_OFC0 0x4
23#define ADC_REG_OFC1 0x5
24#define ADC_REG_OFC2 0x6
25#define ADC_REG_FSC0 0x7
26#define ADC_REG_FSC1 0x8
27#define ADC_REG_FSC2 0x9
28#define ADC_REG_IDAC0 0xA
29#define ADC_REG_IDAC1 0xB
30#define ADC_REG_GPIOCFG 0xC
31#define ADC_REG_GPIODIR 0xD
32#define ADC_REG_GPIODAT 0xE
35#define ADC_MUX1_NORMAL 0x0
36#define ADC_MUX1_OFFCAL 0x1
37#define ADC_MUX1_GAINCAL 0x2
38#define ADC_MUX1_TEMP 0x3
39#define ADC_MUX1_REF1 0x4
40#define ADC_MUX1_REF0 0x5
41#define ADC_MUX1_ASMON 0x6
42#define ADC_MUX1_DSMON 0x7
45#define ADC_TEMP_CONV 0.405
46#define ADC_TEMP_25C 118.
70 std::cout <<
"SPI/GPIO not yet initialized!" << std::endl;
72 std::cout <<
"Ads1248::cselect = " << cselect <<
", nanoPi = " << nanoPi << std::endl;
75 void Reset() { nanoPi->Exch8(cselect, ADC_RESET); }
77 void StopC() { nanoPi->Exch8(cselect, ADC_SDATAC); }
79 void WriteReg(uint8_t reg, uint8_t data);
81 bool SetCh(
unsigned short ch0,
unsigned short ch1);
83 std::pair<unsigned short, unsigned short>
GetGainRate();
97 double adc2val = 2. * vref / ampLSB / double(gainrate.first) * cgain;
98 return adc2val * data;
106 cgain = 1e9 / resist;
115 double GetTemp(
unsigned short n = 5);
124 bool verbose =
false;
127 double resist = 40.2e3;
130 double resist = 30.0e3;
133 double cgain = 1. / resist;
134 const uint32_t ampLSB = 1 << 24;
135 std::pair<unsigned short, unsigned short> gainrate = std::pair<unsigned short, unsigned short>(1, 5);
136 std::pair<unsigned short, unsigned short>
GetGainRate(uint8_t readback);
void SetVref(double v)
Set reference voltage applied to ADC.
Definition ads1248.h:109
void WriteReg(uint8_t reg, uint8_t data)
Write register.
Definition ads1248.cc:15
void SetResist(double r)
Convenience function to set conversion gain via load resistor to measure current.
Definition ads1248.h:103
Ads1248(NanoPi &np, int cs)
Constructor.
Definition ads1248.h:67
double GetVal(double data)
Convert readout into voltage using set constant.
Definition ads1248.h:95
void SetCGain(double g)
Set conversion gain (mutliplied in GetVal())
Definition ads1248.h:101
uint8_t ReadReg(uint8_t reg)
Read register.
Definition ads1248.cc:6
std::pair< unsigned short, unsigned short > GetGainRate()
Return (gain, rate) in real units (rate in Hz)
Definition ads1248.cc:101
void Reset()
Reset registers to default values.
Definition ads1248.h:75
int32_t ReadData()
Read data from ADC.
Definition ads1248.cc:119
void StopC()
Turn off continuous data readout.
Definition ads1248.h:77
bool SetGainRate(int gain, int rate)
Set gain (0..7) and rate (0..9) settings, see manual.
Definition ads1248.cc:79
bool SetCh(unsigned short ch0, unsigned short ch1)
Select which inputs to measure between.
Definition ads1248.cc:24
double GetTemp(unsigned short n=5)
Read out chip temperature.
Definition ads1248.cc:129
Class to control GPIO and SPI communication from a nanoPi Neo2.
Definition nanopi.h:50
bool HasGPIO()
Check whether GPIO was correctly initialized.
Definition nanopi.h:60
bool HasSPI()
Check whether SPI was correctly initialized.
Definition nanopi.h:58