Skip to content

Commit 4dcbc59

Browse files
author
Silver Kuusik
committed
fix for continuous read mode
added delays updated data_mode setup removed ac rejection functionality
1 parent ea30617 commit 4dcbc59

File tree

4 files changed

+22
-12
lines changed

4 files changed

+22
-12
lines changed

AD7173.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,26 @@ void AD7173Class::init() {
1212
SPI.begin();
1313
/* use SPI mode 3 */
1414
SPI.setDataMode(SPI_MODE3);
15+
/* allow the LDOs to power up */
16+
delay(10);
1517
}
1618

1719
void AD7173Class::reset() {
1820
/* sending at least 64 high bits returns ADC to default state */
1921
for (int i = 0; i < 8; i++) {
2022
SPI.transfer(0xFF);
2123
}
24+
/* allow the LDOs to power up */
25+
delay(10);
2226
}
2327

2428
void AD7173Class::sync() {
2529
/* toggle the chip select */
2630
digitalWrite(SS, HIGH);
2731
delay(10);
2832
digitalWrite(SS, LOW);
33+
/* allow the LDOs to power up */
34+
delay(10);
2935
}
3036

3137
void AD7173Class::print_byte(byte value) {
@@ -96,13 +102,13 @@ int AD7173Class::get_current_data_channel(register_t &channel) {
96102
return 0;
97103
}
98104

99-
int AD7173Class::set_adc_mode_config(clock_mode_t clock_mode) {
105+
int AD7173Class::set_adc_mode_config(data_mode_t data_mode, clock_mode_t clock_mode) {
100106
/* Address: 0x01, Reset: 0x2000, Name: ADCMODE */
101107

102108
/* prepare the configuration value */
103109
/* REF_EN [15], RESERVED [14], SING_CYC [13], RESERVED [12:11], DELAY [10:8], RESERVED [7], MODE [6:4], CLOCKSEL [3:2], RESERED [1:0] */
104110
byte value[2] = {0x00, 0x00};
105-
value[1] = (clock_mode << 2);
111+
value[1] = (data_mode << 4) | (clock_mode << 2);
106112

107113
/* update the desired adc_mode configuration */
108114
this->set_register(ADCMODE_REG, value, 2);
@@ -229,13 +235,12 @@ int AD7173Class::set_setup_config(register_t setup, coding_mode_t coding_mode) {
229235
return 0;
230236
}
231237

232-
int AD7173Class::set_filter_config(register_t filter, bool ac_rejection, data_rate_t data_rate) {
238+
int AD7173Class::set_filter_config(register_t filter, data_rate_t data_rate) {
233239
/* Address Range: 0x28 to 0x2F, Reset: 0x0000, Name: FILTCON0 to FILTCON7 */
234240

235241
/* prepare the configuration value */
236242
byte value[2] = {0x00, 0x00};
237243
/* SINC3_MAP0 [15], RESERVED [14:12], ENHFILTEN0 [11], ENHFILT0 [10:8], RESERVED [7], ORDER0 [6:5], ORD0 [4:0] */
238-
value[0] = (ac_rejection << 3);
239244
value[1] = data_rate;
240245

241246
/* update the desired filter configuration */

AD7173.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class AD7173Class {
251251
@return int - error code
252252
================================
253253
*/
254-
int set_adc_mode_config(clock_mode_t);
254+
int set_adc_mode_config(data_mode_t, clock_mode_t);
255255

256256
/*
257257
==================================================
@@ -305,12 +305,11 @@ class AD7173Class {
305305
==========================================
306306
sets the ADC filters data conversion rate
307307
@param byte - filter register
308-
@param bool - enable/disable ac_rejection
309308
@param byte - data rate
310309
@return int - error code
311310
==========================================
312311
*/
313-
int set_filter_config(register_t, bool, data_rate_t);
312+
int set_filter_config(register_t, data_rate_t);
314313

315314
private:
316315
/* ADC data mode */

examples/Basic/Basic.ino

+9-3
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,20 @@ void setup() {
4242

4343
/* set the ADC FILTER0 ac_rejection to false and samplingrate to 1007 Hz */
4444
/* FILTER0 - FILTER7 */
45-
/* true/false to enable/disable 50/60 Hz AC rejection filters */
4645
/* SPS_1, SPS_2, SPS_5, SPS_10, SPS_16, SPS_20, SPS_49, SPS_59, SPS_100, SPS_200 */
4746
/* SPS_381, SPS_503, SPS_1007, SPS_2597, SPS_5208, SPS_10417, SPS_15625, SPS_31250 */
48-
AD7173.set_filter_config(FILTER0, false, SPS_1007);
47+
AD7173.set_filter_config(FILTER0, SPS_1007);
4948

5049
/* set the ADC data and clock mode */
50+
/* CONTINUOUS_CONVERSION_MODE, SINGLE_CONVERSION_MODE */
51+
/* in SINGLE_CONVERSION_MODE after all setup channels are sampled the ADC goes into STANDBY_MODE */
52+
/* to exit STANDBY_MODE use this same function to go into CONTINUOUS or SINGLE_CONVERSION_MODE */
5153
/* INTERNAL_CLOCK, INTERNAL_CLOCK_OUTPUT, EXTERNAL_CLOCK_INPUT, EXTERNAL_CRYSTAL */
52-
AD7173.set_adc_mode_config(INTERNAL_CLOCK);
54+
AD7173.set_adc_mode_config(CONTINUOUS_CONVERSION_MODE, INTERNAL_CLOCK);
55+
56+
/* enable or disable CONTINUOUS_READ_MODE, to exit use AD7173.reset(); */
57+
/* AD7173.reset(); return all registers to default state, so everything has to be setup again */
58+
AD7173.set_interface_mode_config(false);
5359

5460
/* wait for ADC */
5561
delay(10);

library.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name=AD7173
2-
version=0.2
2+
version=0.2.1
33
author=Silver Kuusik <[email protected]>
44
maintainer=Silver Kuusik <[email protected]>
55
sentence=Arduino library for Analog Devices AD7173 analog digital converter
66
paragraph=This library was developed as the 24bit interface for Brain-Duino. It implements basic functionality of the AD7173 for using it with Brain-Duino or other purposes.
77
category=Communication
88
url=https://github.com/brain-duino/AD7173-Arduino
9-
architectures=avr
9+
architectures=avr

0 commit comments

Comments
 (0)