Skip to content

Commit 82b876e

Browse files
author
Silver Kuusik
committed
new function set_offset_config
added new function for setting offset value for DC offset compensation
1 parent 4dcbc59 commit 82b876e

File tree

6 files changed

+62
-20
lines changed

6 files changed

+62
-20
lines changed

AD7173.cpp

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,10 @@ int AD7173Class::get_current_data_channel(register_t &channel) {
9696
/* get ADC status register */
9797
byte value[1];
9898
this->get_register(STATUS_REG, value, 1);
99+
99100
/* assign to return channel register value */
100101
channel = (register_t) (value[0] & 0x0F);
102+
101103
/* return error code */
102104
return 0;
103105
}
@@ -110,10 +112,10 @@ int AD7173Class::set_adc_mode_config(data_mode_t data_mode, clock_mode_t clock_m
110112
byte value[2] = {0x00, 0x00};
111113
value[1] = (data_mode << 4) | (clock_mode << 2);
112114

113-
/* update the desired adc_mode configuration */
115+
/* update the configuration value */
114116
this->set_register(ADCMODE_REG, value, 2);
115117

116-
/* verify updated adc_mode configuration */
118+
/* verify the updated configuration value */
117119
this->get_register(ADCMODE_REG, value, 2);
118120

119121
/* return error code */
@@ -128,10 +130,10 @@ int AD7173Class::set_interface_mode_config(bool continuous_read) {
128130
byte value[2] = {0x00, 0x00};
129131
value[1] = (continuous_read << 7);
130132

131-
/* update the desired interface_mode configuration */
133+
/* update the configuration value */
132134
this->set_register(IFMODE_REG, value, 2);
133135

134-
/* verify updated interface_mode configuration */
136+
/* verify the updated configuration value */
135137
this->get_register(IFMODE_REG, value, 2);
136138

137139
/* when continuous read mode */
@@ -207,10 +209,10 @@ int AD7173Class::set_channel_config(register_t channel, bool enable, register_t
207209
value[0] = (enable << 7) | (setup << 4) | (ain_pos >> 3);
208210
value[1] = (ain_pos << 5) | ain_neg;
209211

210-
/* update the desired channel configuration */
212+
/* update the configuration value */
211213
this->set_register(channel, value, 2);
212214

213-
/* verify the updated channel configuration */
215+
/* verify the updated configuration value */
214216
this->get_register(channel, value, 2);
215217

216218
/* return error code */
@@ -225,10 +227,10 @@ int AD7173Class::set_setup_config(register_t setup, coding_mode_t coding_mode) {
225227
value[0] = (coding_mode << 4);
226228
value[1] = 0x00;
227229

228-
/* update the desired setup configuration */
230+
/* update the configuration value */
229231
this->set_register(setup, value, 2);
230232

231-
/* verify the updated setup configuration */
233+
/* verify the updated configuration value */
232234
this->get_register(setup, value, 2);
233235

234236
/* return error code */
@@ -243,12 +245,31 @@ int AD7173Class::set_filter_config(register_t filter, data_rate_t data_rate) {
243245
/* SINC3_MAP0 [15], RESERVED [14:12], ENHFILTEN0 [11], ENHFILT0 [10:8], RESERVED [7], ORDER0 [6:5], ORD0 [4:0] */
244246
value[1] = data_rate;
245247

246-
/* update the desired filter configuration */
248+
/* update the configuration value */
247249
this->set_register(filter, value, 2);
248250

249-
/* verify updated filter configuration */
251+
/* verify the updated configuration value */
250252
this->get_register(filter, value, 2);
251253

254+
/* return error code */
255+
return 0;
256+
}
257+
258+
int AD7173Class::set_offset_config(register_t offset, uint32_t offset_value) {
259+
/* Address Range: 0x30 to 0x37, Reset: 0x0000, Name: OFFSET0 to OFFSET7 */
260+
261+
/* prepare the configuration value */
262+
byte value[3] = {0x00, 0x00, 0x00};
263+
value[0] = offset_value;
264+
value[1] = offset_value >> 8;
265+
value[2] = offset_value >> 16;
266+
267+
/* update the configuration value */
268+
this->set_register(offset, value, 3);
269+
270+
/* verify the updated configuration value */
271+
this->get_register(offset, value, 3);
272+
252273
/* return error code */
253274
return 0;
254275
}

AD7173.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,16 @@ class AD7173Class {
311311
*/
312312
int set_filter_config(register_t, data_rate_t);
313313

314+
/*
315+
======================================
316+
sets the ADC offset compensation value
317+
@param byte - offset register
318+
@param uint32_t - offset value
319+
@return int - error code
320+
======================================
321+
*/
322+
int set_offset_config(register_t, uint32_t);
323+
314324
private:
315325
/* ADC data mode */
316326
data_mode_t m_data_mode;

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ This library is developed for AD7173 to be used with Brain-Duino and therefore i
66
For Brain-Duino we use the following setup, meaning this is the most tested setup for this library:
77

88
* 1007 data rate
9-
* internal clock
9+
* external crystal
1010
* continuous conversion mode
1111
* 4 analog inputs, 2 bipolar channels
1212

1313
```c
14-
AD7173.set_clock_mode(INTERNAL_CLOCK);
15-
AD7173.set_data_rate(FILTER0, SPS_1007);
16-
AD7173.setup_channel(CH0, true, AIN8, AIN9);
17-
AD7173.setup_channel(CH1, true, AIN10, AIN11);
18-
AD7173.set_data_mode(CONTINUOUS_CONVERSION_MODE);
14+
AD7173.set_channel_config(CH0, true, SETUP0, AIN8, AIN9);
15+
AD7173.set_channel_config(CH1, true, SETUP0, AIN10, AIN11);
16+
AD7173.set_setup_config(SETUP0, BIPOLAR);
17+
AD7173.set_filter_config(FILTER0, SPS_1007);
18+
AD7173.set_adc_mode_config(CONTINUOUS_CONVERSION_MODE, EXTERNAL_CRYSTAL);
1919
```

examples/Basic/Basic.ino

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ void setup() {
1919
/* reset the ADC registers to default */
2020
AD7173.reset();
2121

22-
/* resync the ADC */
23-
AD7173.sync();
24-
2522
/* check if the ID register of the ADC is valid */
2623
if (AD7173.is_valid_id()) Serial.println("AD7173 ID is valid");
2724
else Serial.println("AD7173 ID is invalid");
@@ -40,6 +37,10 @@ void setup() {
4037
/* BIPOLAR, UNIPOLAR */
4138
AD7173.set_setup_config(SETUP0, BIPOLAR);
4239

40+
/* set ADC OFFSET0 offset value */
41+
/* OFFSET0 - OFFSET7 */
42+
AD7173.set_offset_config(OFFSET0, 8388608);
43+
4344
/* set the ADC FILTER0 ac_rejection to false and samplingrate to 1007 Hz */
4445
/* FILTER0 - FILTER7 */
4546
/* SPS_1, SPS_2, SPS_5, SPS_10, SPS_16, SPS_20, SPS_49, SPS_59, SPS_100, SPS_200 */

keywords.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ sync KEYWORD2
1818
get_data KEYWORD2
1919
is_valid_id KEYWORD2
2020
set_setup_config KEYWORD2
21+
set_offset_config KEYWORD2
2122
set_filter_config KEYWORD2
2223
set_channel_config KEYWORD2
2324
set_adc_mode_config KEYWORD2
@@ -104,6 +105,15 @@ SETUP5 LITERAL1
104105
SETUP6 LITERAL1
105106
SETUP7 LITERAL1
106107

108+
OFFSET0 LITERAL1
109+
OFFSET1 LITERAL1
110+
OFFSET2 LITERAL1
111+
OFFSET3 LITERAL1
112+
OFFSET4 LITERAL1
113+
OFFSET5 LITERAL1
114+
OFFSET6 LITERAL1
115+
OFFSET7 LITERAL1
116+
107117
DATA_READY LITERAL1
108118

109119
BIPOLAR LITERAL1

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=AD7173
2-
version=0.2.1
2+
version=0.3
33
author=Silver Kuusik <silver.kuusik@gmail.com>
44
maintainer=Silver Kuusik <silver.kuusik@gmail.com>
55
sentence=Arduino library for Analog Devices AD7173 analog digital converter

0 commit comments

Comments
 (0)