-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADS1248_DEVCUBE.h
180 lines (160 loc) · 5.8 KB
/
ADS1248_DEVCUBE.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*!
* @file ADS1248_DEVCUBE.h
*
* This is the header file for the ADS1248 library
* The ADS1248 class is defined here alongwith required macros
*
* Written by Mohammed Asim Merchant
*
* MIT License.
* Copyright (c) 2019 Mohammed Asim Merchant
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*
*/
#ifndef _ADS1248_DEVCUBE_H_INCLUDED
#define _ADS1248_DEVCUBE_H_INCLUDED
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "pins_arduino.h"
// Commands
#define ADS1248_RESET 2
#define ADS1248_START 3
#define ADS1248_DRDY 4
#define ADS1248_SPI_MODE ((0<<CPOL) | (1<<CPHA))
#define ADS1248_CMD_WAKE 0x00
#define ADS1248_CMD_SLEEP 0x02
#define ADS1248_CMD_SYNC 0x04
#define ADS1248_CMD_RESET 0x06
#define ADS1248_CMD_RDATA 0x12
#define ADS1248_CMD_RDATAC 0x14
#define ADS1248_CMD_SDATAC 0x16
#define ADS1248_CMD_RREG 0x20
#define ADS1248_CMD_WREG 0x40
#define ADS1248_CMD_SYSOCAL 0x60
#define ADS1248_CMD_SYSGCAL 0x61
#define ADS1248_CMD_SELFOCAL 0x62
#define ADS1248_CMD_NOP 0xFF
// Registers
#define ADS1248_MUX0 0x00
#define ADS1248_VBIAS 0x01
#define ADS1248_MUX1 0x02
#define ADS1248_SYS0 0x03
#define ADS1248_OFC0 0x04
#define ADS1248_OFC1 0x05
#define ADS1248_OFC2 0x06
#define ADS1248_FSC0 0x07
#define ADS1248_FSC1 0x08
#define ADS1248_FSC2 0x09
#define ADS1248_IDAC0 0x0A
#define ADS1248_IDAC1 0x0B
#define ADS1248_GPIOCFG 0x0C
#define ADS1248_GPIODIR 0x0D
#define ADS1248_GPIODAT 0x0E
// Register Bit Masks
#define ADS1248_CH_MASK 0x07 // Low 3 bits used for MUX in MUX0, IDAC1 and IDAC0
#define ADS1248_PGA_MASK 0x70
#define ADS1248_SPS_MASK 0x0F
#define ADS1248_REFSEL_MASK (0x03 << 3)
#define ADS1248_VREF_MASK (0x03 << 5)
#define ADS1248_MUXCAL_MASK 0x07
#define ADS1248_MAX_VAL 0x7FFFFF
#define ADS1248_MIN_VAL 0x800000
#define ADS1248_RANGE 0xFFFFFF
#define ADS1248_INT_REF_MV 2048
#define ADS1248_TEST_REG ADS1248_MUX1
#define ADS1248_DELAY delayMicroseconds(10)
// Setting defines for ADS1248
#define ADC_5_SPS 0x00
#define ADC_10_SPS 0x01
#define ADC_20_SPS 0x02
#define ADC_40_SPS 0x03
#define ADC_80_SPS 0x04
#define ADC_160_SPS 0x05
#define ADC_320_SPS 0x06
#define ADC_640_SPS 0x07
#define ADC_1000_SPS 0x08
#define ADC_2000_SPS 0x09
#define ADC_PGA_1 (0x00 << 4)
#define ADC_PGA_2 (0x01 << 4)
#define ADC_PGA_4 (0x02 << 4)
#define ADC_PGA_8 (0x03 << 4)
#define ADC_PGA_16 (0x04 << 4)
#define ADC_PGA_32 (0x05 << 4)
#define ADC_PGA_64 (0x06 << 4)
#define ADC_PGA_128 (0x07 << 4)
#define ADC_IDAC_0uA 0x00
#define ADC_IDAC_50uA 0x01
#define ADC_IDAC_100uA 0x02
#define ADC_IDAC_250uA 0x03
#define ADC_IDAC_500uA 0x04
#define ADC_IDAC_750uA 0x05
#define ADC_IDAC_1000uA 0x06
#define ADC_IDAC_1500uA 0x07
#define ADC_IDAC1_IEXT1 (0x80 << 4)
#define ADC_IDAC1_IEXT2 (0x81 << 4)
#define ADC_IDAC1_DISCONNECTED (0xC0 << 4)
#define ADC_IDAC2_IEXT1 0x80
#define ADC_IDAC2_IEXT2 0x81
#define ADC_IDAC2_DISCONNECTED 0xC0
#define ADC_REF0 (0x00 << 3)
#define ADC_REF1 (0x01 << 3)
#define ADC_INTREF (0x02 << 3)
#define ADC_INTREF_REF0 (0x03 << 3)
#define ADC_VREF_OFF (0x00 << 5)
#define ADC_VREF_ON (0x01 << 5)
#define ADC_VREF_ON_LP (0x02 << 5)
#define ADC_MUXCAL_NORM 0x00
#define ADC_MUXCAL_OFFSET 0x01
#define ADC_MUXCAL_GAIN 0x02
#define ADC_MUXCAL_TEMP 0x03
#define ADC_MUXCAL_REF1 0x04
#define ADC_MUXCAL_REF0 0x05
#define ADC_MUXCAL_AVDD 0x06
#define ADC_MUXCAL_DVDD 0x07
/**************************************************************************/
/*!
@brief Class that stores functions for interacting with ADS1248 ADC
*/
/**************************************************************************/
class ADS1248_DEVCUBE {
public:
bool begin(void);
void end(void);
void reset(void);
void wake(void);
void sleep(void);
void stopContinuous(void);
void startSingle(void);
float sample_raw(uint8_t ch_pos, uint8_t ch_neg, uint8_t gain, uint8_t sampleRate, uint8_t ref);
void setPGA(uint8_t gain);
void setSampleRate(uint8_t rate);
void enableIntRef(void);
void selectRef(uint8_t ref_mux);
void selectMuxCal(uint8_t muxcal);
void selfOffsetCal(void);
void dumpRegs(void);
uint8_t readReg(uint8_t addr);
int32_t readData(void);
void writeReg(uint8_t addr, uint8_t data);
private:
void initSPI(void);
};
extern ADS1248_DEVCUBE ADS1248_DEV;
#endif