AEM
ad7689.h
Go to the documentation of this file.
1 #ifndef AD7689_H
2 #define AD7689_H
3 
4 #if defined(ARDUINO) && ARDUINO >= 100
5 #include <Arduino.h>
6 #else
7 #include <WProgram.h>
8 #endif
9 
10 #include "yspi.h"
11 #include "yADC.h"
12 
13 // input configuration: bipolar/unipolar, single ended or differential
14 #define INCC_BIPOLAR_DIFF (0b000) // 00X
15 #define INCC_BIPOLAR_COM (0b010)
16 #define INCC_TEMP (0b011)
17 #define INCC_UNIPOLAR_DIFF (0b100)// 10X
18 #define INCC_UNIPOLAR_REF_COM (0b110)
19 #define INCC_UNIPOLAR_REF_GND (0b111)
20 
21 // reference voltage (note: decoupling caps required on REF/REFIN when using INT_REF!)
22 #define INT_REF_25 (0b000)
23 #define INT_REF_4096 (0b001)
24 #define EXT_REF_TEMP_ON (0b010)
25 #define EXT_REF_TEMP_BUF (0b011)
26 #define EXT_REF_TEMP_OFF (0b110)
27 #define EXT_REF_TEMP_OFF_BUF (0b111)
28 
29 // sequencer configuration (default: no sequencer)
30 #define SEQ_OFF (0b00)
31 #define SEQ_UPDATE (0b01)
32 #define SEQ_SCAN_INPUT_TEMP (0b10)
33 #define SEQ_SCAN_INPUT (0b11)
34 
35 #define MAX_FREQ (38000000) // 26 ns period @ VDD 5V and VIO 3.3 - 5V
36 
37 #define UNIPOLAR_MODE (0)
38 #define BIPOLAR_MODE (1)
39 #define DIFFERENTIAL_MODE (2)
40 
41 #define REF_INTERNAL (0)
42 #define REF_EXTERNAL (1)
43 #define REF_GND (2)
44 #define REF_COM (3)
45 
46 // bit shifts needed for config register values, from datasheet p. 27 table 11:
47 #define CFG (13)
48 #define INCC (10)
49 #define INx (7)
50 #define BW (6)
51 #define REF (3)
52 #define SEQ (1)
53 #define RB (0)
54 
55 #define TEMP_REF (4.096) // reference voltage to be used for temperature measurement, either 2.5V or 4.096V
56 #define BASE_TEMP (25)
57 #define TEMP_BASE_VOLTAGE (0.283)
58 #define TEMP_RICO (0.001)
59 #define INTERNAL_25 (2.5)
60 #define INTERNAL_4096 (4.096)
61 #define TOTAL_CHANNELS (8)
62 #define TOTAL_STEPS (65536)
63 #define TCONV (4)
64 #define TACQ (2)
65 #define STARTUP_DELAY (100)
66 
71 struct AD7689_conf {
72  bool CFG_conf;
73  uint8_t INCC_conf;
74  uint8_t INx_conf;
75  uint8_t BW_conf;
76  uint8_t REF_conf;
77  uint8_t SEQ_conf;
78  float REF_voltage;
79  bool RB_conf;
80 };
81 
85 class AD7689 : public YADC {
86  protected:
89  const float posref;
90  const float negref;
91  const uint8_t refsrc;
92  const uint8_t inputConfig;
93  const uint8_t refConfig;
95  uint32_t timeStamps[TOTAL_CHANNELS];
96  uint16_t samples[TOTAL_CHANNELS];
97  uint16_t framePeriod;
98  uint16_t curTemp;
99  uint16_t tempTime;
100  uint32_t lastSeqEndTime;
101  uint8_t inputCount;
107  uint16_t shiftTransaction(uint16_t command, bool readback, uint16_t* rb_cmd_ptr) const;
108  uint16_t toCommand(AD7689_conf cfg) const;
109  AD7689_conf getADCConfig(bool default_config = false);
110  float readTemperature(void);
111  void configureSequencer();
112  void readChannels(uint8_t channels, uint8_t mode, uint16_t* data, uint16_t* temp);
113  float calculateVoltage(uint16_t sample) const;
114  float calculateTemp(uint16_t temp) const;
115  uint32_t initSampleTiming(void);
116  void cycleTimingBenchmark(void);
117 
118  // initialisation funcitons
119  uint8_t getInputConfig(uint8_t polarity, bool differential) const;
120  float getNegRef(float posR, uint8_t polarity) const;
121  uint8_t getRefSrc(uint8_t refS, float posR) const;
122  float getPosRef(uint8_t refS, float posR) const;
123 
124  public:
125  AD7689(const YSPI *const y, uint8_t numberChannels = TOTAL_CHANNELS);
126  void enableFiltering(bool onOff);
127  float acquireChannel(uint8_t channel, uint32_t* timeStamp);
128  float acquireChannel(uint8_t channel);
129  float acquireTemperature();
130  bool selftest(void);
131 };
132 #endif
133 
134 
bool CFG_conf
Definition: ad7689.h:72
bool RB_conf
Definition: ad7689.h:79
AD7689_conf conf
Definition: ad7689.h:87
uint16_t tempTime
Definition: ad7689.h:99
uint16_t framePeriod
Definition: ad7689.h:97
const uint8_t refsrc
Definition: ad7689.h:91
#define TOTAL_CHANNELS
Definition: ad7689.h:61
uint16_t curTemp
Definition: ad7689.h:98
const float posref
Definition: ad7689.h:89
uint8_t REF_conf
Definition: ad7689.h:76
const float negref
Definition: ad7689.h:90
float REF_voltage
Definition: ad7689.h:78
uint8_t inputCount
Definition: ad7689.h:101
uint8_t INx_conf
Definition: ad7689.h:74
bool sequencerActive
Definition: ad7689.h:103
uint8_t INCC_conf
Definition: ad7689.h:73
Definition: yspi.h:34
const uint8_t inputConfig
Definition: ad7689.h:92
Definition: ad7689.h:71
const uint8_t refConfig
Definition: ad7689.h:93
uint32_t lastSeqEndTime
Definition: ad7689.h:100
uint8_t BW_conf
Definition: ad7689.h:75
Definition: ad7689.h:85
bool filterConfig
Definition: ad7689.h:104
uint8_t SEQ_conf
Definition: ad7689.h:77
Definition: yADC.h:17