├── .gitignore ├── AD7173.cpp ├── AD7173.h ├── LICENSE ├── Neurolab.cpp ├── Neurolab.h ├── README.md ├── definitions.h ├── examples └── Basic │ └── Basic.ino ├── keywords.txt └── library.properties /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | -------------------------------------------------------------------------------- /AD7173.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ================================= 3 | library to control the AD7173 ADC 4 | ================================= 5 | */ 6 | #include "AD7173.h" 7 | 8 | AD7173Class AD7173; 9 | 10 | void AD7173Class::init() { 11 | /* initiate SPI communication */ 12 | SPI.begin(); 13 | /* use SPI mode 3 */ 14 | SPI.setDataMode(SPI_MODE3); 15 | /* allow the LDOs to power up */ 16 | delay(10); 17 | } 18 | 19 | void AD7173Class::reset() { 20 | /* sending at least 64 high bits returns ADC to default state */ 21 | for (int i = 0; i < 8; i++) { 22 | SPI.transfer(0xFF); 23 | } 24 | /* allow the LDOs to power up */ 25 | delay(10); 26 | } 27 | 28 | void AD7173Class::sync() { 29 | /* toggle the chip select */ 30 | digitalWrite(SS, HIGH); 31 | delay(10); 32 | digitalWrite(SS, LOW); 33 | /* allow the LDOs to power up */ 34 | delay(10); 35 | } 36 | 37 | void AD7173Class::print_byte(byte value) { 38 | char format[10]; 39 | sprintf(format, "0x%.2X ", value); 40 | Serial.print(format); 41 | } 42 | 43 | int AD7173Class::set_register(adc7173_register_t reg, byte *value, int value_len) { 44 | /* send communication register id 0x00 */ 45 | SPI.transfer(0x00); 46 | /* send write command to the desired register 0x00 - 0xFF */ 47 | SPI.transfer(0x00 | reg); 48 | /* send the desired amount of bytes */ 49 | for (int i = 0; i < value_len; i++) { 50 | SPI.transfer(value[i]); 51 | } 52 | /* when debug enabled */ 53 | if (DEBUG_ENABLED) { 54 | Serial.print("set_register: set [ "); 55 | for (int i = 0; i < value_len; i++) { 56 | this->print_byte(value[i]); 57 | } 58 | Serial.print("] to reg [ "); 59 | this->print_byte(reg); 60 | Serial.println("]"); 61 | } 62 | /* TODO: find out correct delay */ 63 | delay(READ_WRITE_DELAY); 64 | /* return error code */ 65 | return 0; 66 | } 67 | 68 | int AD7173Class::get_register(adc7173_register_t reg, byte *value, int value_len) { 69 | /* send communication register id 0x00 */ 70 | SPI.transfer(0x00); 71 | /* send read command to the desired register 0x00 - 0xFF */ 72 | SPI.transfer(0x40 | reg); 73 | /* receive the desired amount of bytes */ 74 | for (int i = 0; i < value_len; i++) { 75 | value[i] = SPI.transfer(0x00); 76 | } 77 | /* when debug enabled */ 78 | if (DEBUG_ENABLED) { 79 | Serial.print("get_register: got [ "); 80 | for (int i = 0; i < value_len; i++) { 81 | this->print_byte(value[i]); 82 | } 83 | Serial.print("] from reg [ "); 84 | this->print_byte(reg); 85 | Serial.println(" ]"); 86 | } 87 | /* TODO: find out correct delay */ 88 | delay(READ_WRITE_DELAY); 89 | /* return error code */ 90 | return 0; 91 | } 92 | 93 | int AD7173Class::get_current_data_channel(adc7173_register_t &channel) { 94 | /* Address: 0x00, Reset: 0x80, Name: STATUS */ 95 | 96 | /* get ADC status register */ 97 | byte value[1]; 98 | this->get_register(STATUS_REG, value, 1); 99 | 100 | /* assign to return channel register value */ 101 | channel = (adc7173_register_t) (value[0] & 0x0F); 102 | 103 | /* return error code */ 104 | return 0; 105 | } 106 | 107 | int AD7173Class::set_adc_mode_config(data_mode_t data_mode, clock_mode_t clock_mode) { 108 | /* Address: 0x01, Reset: 0x2000, Name: ADCMODE */ 109 | 110 | /* prepare the configuration value */ 111 | /* 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] */ 112 | byte value[2] = {0x00, 0x00}; 113 | value[1] = (data_mode << 4) | (clock_mode << 2); 114 | 115 | /* update the configuration value */ 116 | this->set_register(ADCMODE_REG, value, 2); 117 | 118 | /* verify the updated configuration value */ 119 | this->get_register(ADCMODE_REG, value, 2); 120 | 121 | /* return error code */ 122 | return 0; 123 | } 124 | 125 | int AD7173Class::set_interface_mode_config(bool continuous_read, bool append_status_reg) { 126 | /* Address: 0x02, Reset: 0x0000, Name: IFMODE */ 127 | 128 | /* prepare the configuration value */ 129 | /* RESERVED [15:13], ALT_SYNC [12], IOSTRENGTH [11], HIDE_DELAY [10], RESERVED [9], DOUT_RESET [8], CONTREAD [7], DATA_STAT [6], REG_CHECK [5], RESERVED [4], CRC_EN [3:2], RESERVED [1], WL16 [0] */ 130 | byte value[2] = {0x00, 0x00}; 131 | value[1] = (continuous_read << 7) | (append_status_reg << 6); 132 | 133 | /* update the configuration value */ 134 | this->set_register(IFMODE_REG, value, 2); 135 | 136 | /* verify the updated configuration value */ 137 | this->get_register(IFMODE_REG, value, 2); 138 | 139 | /* when continuous read mode */ 140 | if (continuous_read) { 141 | /* update the data mode */ 142 | this->m_data_mode = CONTINUOUS_READ_MODE; 143 | } 144 | 145 | /* return error code */ 146 | return 0; 147 | } 148 | 149 | int AD7173Class::get_data(byte *value) { 150 | /* Address: 0x04, Reset: 0x000000, Name: DATA */ 151 | 152 | /* when not in continuous read mode, send the read command */ 153 | if (this->m_data_mode != CONTINUOUS_READ_MODE) { 154 | /* send communication register id 0x00 */ 155 | SPI.transfer(0x00); 156 | /* send read command 0x40 to the data register 0x04 */ 157 | SPI.transfer(0x40 | DATA_REG); 158 | } 159 | /* get the ADC conversion result (24 bits) */ 160 | value[0] = SPI.transfer(0x00); 161 | value[1] = SPI.transfer(0x00); 162 | value[2] = SPI.transfer(0x00); 163 | 164 | /* when debug enabled */ 165 | if (DEBUG_ENABLED) { 166 | Serial.print("get_data: read [ "); 167 | this->print_byte(value[0]); 168 | this->print_byte(value[1]); 169 | this->print_byte(value[2]); 170 | Serial.println("] from reg [ 0x04 ]"); 171 | } 172 | /* return error code */ 173 | return 0; 174 | } 175 | 176 | bool AD7173Class::is_valid_id() { 177 | /* Address: 0x07, Reset: 0x30DX, Name: ID */ 178 | 179 | /* get the ADC device ID */ 180 | byte id[2]; 181 | this->get_register(ID_REG, id, 2); 182 | /* check if the id matches 0x30DX, where X is don't care */ 183 | id[1] &= 0xF0; 184 | bool valid_id = id[0] == 0x30 && id[1] == 0xD0; 185 | 186 | /* when debug enabled */ 187 | if (DEBUG_ENABLED) { 188 | if (valid_id) { 189 | Serial.println("init: ADC device ID is valid :)"); 190 | } else { 191 | Serial.print("init: ADC device ID is invalid :( [ "); 192 | this->print_byte(id[0]); 193 | this->print_byte(id[1]); 194 | Serial.print(" ]"); 195 | Serial.println(); 196 | } 197 | } 198 | /* return validity of ADC device ID */ 199 | return valid_id; 200 | } 201 | 202 | int AD7173Class::set_channel_config(adc7173_register_t channel, bool enable, adc7173_register_t setup, analog_input_t ain_pos, analog_input_t ain_neg) { 203 | /* Address: 0x10, Reset: 0x8001, Name: CH0 */ 204 | /* Address Range: 0x11 to 0x1F, Reset: 0x0001, Name: CH1 to CH15 */ 205 | 206 | /* prepare the configuration value */ 207 | /* CH_EN0 [15], SETUP_SEL0 [14:12], RESERVED [11:10], AINPOS0 [9:5], AINNEG0 [4:0] */ 208 | byte value[2] = {0x00, 0x00}; 209 | value[0] = (enable << 7) | (setup << 4) | (ain_pos >> 3); 210 | value[1] = (ain_pos << 5) | ain_neg; 211 | 212 | /* update the configuration value */ 213 | this->set_register(channel, value, 2); 214 | 215 | /* verify the updated configuration value */ 216 | this->get_register(channel, value, 2); 217 | 218 | /* return error code */ 219 | return 0; 220 | } 221 | 222 | int AD7173Class::set_setup_config(adc7173_register_t setup, coding_mode_t coding_mode) { 223 | /* Address Range: 0x20 to 0x27, Reset: 0x1000, Name: SETUPCON0 to SETUPCON7 */ 224 | 225 | /* prepare the configuration value */ 226 | byte value[2] = {0x00, 0x00}; 227 | value[0] = (coding_mode << 4); 228 | value[1] = 0x00; 229 | 230 | /* update the configuration value */ 231 | this->set_register(setup, value, 2); 232 | 233 | /* verify the updated configuration value */ 234 | this->get_register(setup, value, 2); 235 | 236 | /* return error code */ 237 | return 0; 238 | } 239 | 240 | int AD7173Class::set_filter_config(adc7173_register_t filter, data_rate_t data_rate) { 241 | /* Address Range: 0x28 to 0x2F, Reset: 0x0000, Name: FILTCON0 to FILTCON7 */ 242 | 243 | /* prepare the configuration value */ 244 | byte value[2] = {0x00, 0x00}; 245 | /* SINC3_MAP0 [15], RESERVED [14:12], ENHFILTEN0 [11], ENHFILT0 [10:8], RESERVED [7], ORDER0 [6:5], ORD0 [4:0] */ 246 | value[1] = data_rate; 247 | 248 | /* update the configuration value */ 249 | this->set_register(filter, value, 2); 250 | 251 | /* verify the updated configuration value */ 252 | this->get_register(filter, value, 2); 253 | 254 | /* return error code */ 255 | return 0; 256 | } 257 | 258 | int AD7173Class::set_offset_config(adc7173_register_t offset, uint32_t offset_value) { 259 | /* Address Range: 0x30 to 0x37, Reset: 0x0000, Name: OFFSET0 to OFFSET7 */ 260 | 261 | /* add the default offset value */ 262 | offset_value += 8388608; 263 | /* prepare the configuration value */ 264 | byte value[3] = {0x00, 0x00, 0x00}; 265 | value[0] = offset_value >> 16; 266 | value[1] = offset_value >> 8; 267 | value[2] = offset_value; 268 | 269 | /* update the configuration value */ 270 | this->set_register(offset, value, 3); 271 | 272 | /* verify the updated configuration value */ 273 | this->get_register(offset, value, 3); 274 | 275 | /* return error code */ 276 | return 0; 277 | } 278 | 279 | int AD7173Class::set_gain_registers(adc7173_register_t gain, uint32_t gain_value) { 280 | /* Address Range: 0x38 to 0x3F, Reset: 0x5XXXX0 , Name: GAIN0 to GAIN7 */ 281 | 282 | /* prepare the configuration value */ 283 | byte value[3] = {0x00, 0x00, 0x00}; 284 | value[0] = gain_value >> 16; 285 | value[1] = gain_value >> 8; 286 | value[2] = gain_value; 287 | 288 | /* update the configuration value */ 289 | this->set_register(gain, value, 3); 290 | 291 | /* verify the updated configuration value */ 292 | this->get_register(gain, value, 3); 293 | 294 | /* return error code */ 295 | return 0; 296 | } 297 | -------------------------------------------------------------------------------- /AD7173.h: -------------------------------------------------------------------------------- 1 | /* 2 | =================================================================================== 3 | library to control the AD7173 ADC 4 | 5 | G A A A A A A 6 | R R P I I I I I I A 7 | E E I N N N N N N I 8 | F F O 1 1 1 1 1 1 N 9 | + - 3 5 4 3 2 1 0 9 10 | | | | | | | | | | | 11 | _________________________________________________________ 12 | / 40. 39. 38. 37. 36. 35. 34. 33. 32. 31. | 13 | | | 14 | AIN16 --| 1. 30. |-- AIN8 15 | AIN0/REF2- --| 2. 29. |-- AIN7 16 | AIN1/REF2+ --| 3. 28. |-- AIN6 17 | AIN2 --| 4. 27. |-- AIN5 18 | AIN3 --| 5. 26. |-- AIN4 19 | REFOUT --| 6. 25. |-- GPIO2 20 | REGCAPA --| 7. 24. |-- GPIO1 21 | AVSS --| 8. 23. |-- GPIO0 22 | AVDD1 --| 9. 22. |-- REGCAPD 23 | AVDD2 --| 10. 21. |-- DGND 24 | | | 25 | | 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. | 26 | |__________________________________________________________| 27 | | | | | | | | | | | 28 | P X X D D S C E S I 29 | D T T O I C S R Y O 30 | S A A U N L R N V 31 | W L L T K O C D 32 | 1 2 R D 33 | / 34 | C 35 | L 36 | K 37 | I 38 | O 39 | =================================================================================== 40 | */ 41 | 42 | #ifndef _AD7173_H_INCLUDED 43 | #define _AD7173_H_INCLUDED 44 | 45 | #if ARDUINO >= 100 46 | #include "Arduino.h" 47 | #else 48 | #include "WProgram.h" 49 | #endif 50 | 51 | #include "SPI.h" 52 | #include "definitions.h" 53 | 54 | /* enable or disable debug */ 55 | #define DEBUG_ENABLED 0 56 | 57 | /* delay for reading and writing registers */ 58 | #define READ_WRITE_DELAY 1 59 | 60 | /* ADC data ready indicator */ 61 | #define DATA_READY digitalRead(MISO) == LOW 62 | 63 | class AD7173Class { 64 | public: 65 | /* 66 | ===================================== 67 | constructor 68 | set default ADC setup coding mode 69 | set default ADC data conversion mode 70 | ===================================== 71 | */ 72 | AD7173Class() : m_data_mode(CONTINUOUS_CONVERSION_MODE) { 73 | /* ... */ 74 | } 75 | 76 | /* 77 | ============================================ 78 | initializes the SPI connection with the ADC 79 | ============================================ 80 | */ 81 | void init(); 82 | 83 | /* 84 | ================================================== 85 | cancels the current transaction to resync the ADC 86 | ================================================== 87 | */ 88 | void sync(); 89 | 90 | /* 91 | ============================================== 92 | resets the ADC registers to the default state 93 | ============================================== 94 | */ 95 | void reset(); 96 | 97 | /* 98 | ============================================= 99 | gets the current conversion results channel 100 | @param byte - current data channel 101 | @return int - error code 102 | ============================================= 103 | */ 104 | int get_current_data_channel(adc7173_register_t &); 105 | 106 | /* 107 | ================================ 108 | sets the ADC mode configuration 109 | @param clock_mode_t - clock mode 110 | @return int - error code 111 | ================================ 112 | */ 113 | int set_adc_mode_config(data_mode_t, clock_mode_t); 114 | 115 | /* 116 | ================================================== 117 | sets the ADC interface mode configuration 118 | @param bool - ensable/disable continuous read mode 119 | @return int - error code 120 | ================================================== 121 | */ 122 | int set_interface_mode_config(bool, bool); 123 | 124 | /* 125 | ========================================== 126 | gets the ADC conversion result 127 | @return byte[] - the ADC conversion result 128 | ========================================== 129 | */ 130 | int get_data(byte *); 131 | 132 | /* 133 | ============================================ 134 | checks the ID register of the ADC 135 | @return bool - true if the ADC ID valid 136 | ============================================ 137 | */ 138 | bool is_valid_id(); 139 | 140 | /* 141 | ===================================== 142 | configures ADC channels 143 | @param byte - channel register 144 | @param bool - enable/disable channel 145 | @param byte - setup register 146 | @param byte - analog input positive 147 | @param byte - analog input negative 148 | @return int - error code 149 | ===================================== 150 | */ 151 | int set_channel_config(adc7173_register_t, bool, adc7173_register_t, analog_input_t, analog_input_t); 152 | 153 | /* 154 | ================================== 155 | sets the ADC setups coding mode 156 | @param byte - setup register 157 | @param condig_mode_t - coding mode 158 | @return int - error code 159 | ================================== 160 | */ 161 | int set_setup_config(adc7173_register_t, coding_mode_t); 162 | 163 | /* 164 | ========================================== 165 | sets the ADC filters data conversion rate 166 | @param byte - filter register 167 | @param byte - data rate 168 | @return int - error code 169 | ========================================== 170 | */ 171 | int set_filter_config(adc7173_register_t, data_rate_t); 172 | 173 | /* 174 | ====================================== 175 | sets the ADC offset compensation value 176 | @param byte - offset register 177 | @param uint32_t - offset value 178 | @return int - error code 179 | ====================================== 180 | */ 181 | int set_offset_config(adc7173_register_t, uint32_t); 182 | 183 | /* 184 | ====================================== 185 | sets the ADC gain compensation value 186 | @param byte - gain register 187 | @param uint32_t - gain value 188 | @return int - error code 189 | ====================================== 190 | */ 191 | int set_gain_registers(adc7173_register_t, uint32_t); 192 | private: 193 | /* ADC data mode */ 194 | data_mode_t m_data_mode; 195 | 196 | /* 197 | =========================== 198 | print bytes in nice format 199 | @param byte - byte to print 200 | =========================== 201 | */ 202 | void print_byte(byte); 203 | 204 | /* 205 | ======================================= 206 | set a desired ADC register value 207 | @param byte - the register to set 208 | @param byte[] - the bytes to set 209 | @param int - the length of bytes to set 210 | ======================================= 211 | */ 212 | int set_register(adc7173_register_t, byte *, int); 213 | 214 | /* 215 | ======================================= 216 | get a desired ADC register value 217 | @param byte - the register to get 218 | @param int - the length of bytes to get 219 | @return byte[] - the ADC register value 220 | ======================================= 221 | */ 222 | int get_register(adc7173_register_t, byte *, int); 223 | }; 224 | 225 | extern AD7173Class AD7173; 226 | 227 | #endif 228 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | 204 | 205 | 206 | 207 | The initial code of this library is under a Creative Commons Attribution 4.0 International Public License. Later versions and parts developed by current contributors are under the Apache V.2 License. 208 | 209 | 210 | 211 | 212 | 213 | 214 | Creative Commons Attribution 4.0 International Public License 215 | 216 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 217 | 218 | Section 1 – Definitions. 219 | 220 | Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 221 | Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 222 | Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 223 | Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 224 | Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 225 | Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 226 | Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 227 | Licensor means the individual(s) or entity(ies) granting rights under this Public License. 228 | Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 229 | Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 230 | You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 231 | Section 2 – Scope. 232 | 233 | License grant. 234 | Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 235 | reproduce and Share the Licensed Material, in whole or in part; and 236 | produce, reproduce, and Share Adapted Material. 237 | Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 238 | Term. The term of this Public License is specified in Section 6(a). 239 | Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 240 | Downstream recipients. 241 | Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 242 | No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 243 | No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 244 | Other rights. 245 | 246 | Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 247 | Patent and trademark rights are not licensed under this Public License. 248 | To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. 249 | Section 3 – License Conditions. 250 | 251 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 252 | 253 | Attribution. 254 | 255 | If You Share the Licensed Material (including in modified form), You must: 256 | 257 | retain the following if it is supplied by the Licensor with the Licensed Material: 258 | identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 259 | a copyright notice; 260 | a notice that refers to this Public License; 261 | a notice that refers to the disclaimer of warranties; 262 | a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 263 | indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 264 | indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 265 | You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 266 | If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 267 | If You Share Adapted Material You produce, the Adapter's License You apply must not prevent recipients of the Adapted Material from complying with this Public License. 268 | Section 4 – Sui Generis Database Rights. 269 | 270 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 271 | 272 | for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; 273 | if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and 274 | You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 275 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 276 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 277 | 278 | Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You. 279 | To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You. 280 | The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 281 | Section 6 – Term and Termination. 282 | 283 | This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 284 | Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 285 | 286 | automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 287 | upon express reinstatement by the Licensor. 288 | For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 289 | For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 290 | Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 291 | Section 7 – Other Terms and Conditions. 292 | 293 | The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 294 | Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 295 | Section 8 – Interpretation. 296 | 297 | For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 298 | To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 299 | No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 300 | Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 301 | 302 | MIT LICENSE 303 | 304 | The initial code of this project is licensed under the MIT License. Later code developed in this repository is licensed under the Apache License as stated above. For details on the MIT license see: https://github.com/brain-duino/AD7173/blob/master/LICENSE 305 | 306 | The MIT License (MIT) 307 | 308 | Copyright (c) 2014 Silver Kuusik 309 | 310 | Permission is hereby granted, free of charge, to any person obtaining a copy 311 | of this software and associated documentation files (the "Software"), to deal 312 | in the Software without restriction, including without limitation the rights 313 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 314 | copies of the Software, and to permit persons to whom the Software is 315 | furnished to do so, subject to the following conditions: 316 | 317 | The above copyright notice and this permission notice shall be included in all 318 | copies or substantial portions of the Software. 319 | 320 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 321 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 322 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 323 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 324 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 325 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 326 | SOFTWARE. 327 | -------------------------------------------------------------------------------- /Neurolab.cpp: -------------------------------------------------------------------------------- 1 | #include "Neurolab.h" 2 | 3 | AD7173Class ads; 4 | 5 | // VARIABLES 6 | int outputType; 7 | int auxData[3]; 8 | boolean useAux; 9 | 10 | // BOARD WIDE FUNCTIONS 11 | void Neurolab::initialize(void){ 12 | /* initiate serial communication */ 13 | Serial.begin(230400); 14 | 15 | /* initialize SPI connection to the ADC */ 16 | initialize_adc(); 17 | 18 | /* sync the ADC */ 19 | sync_adc(); 20 | } 21 | 22 | /* 23 | ================================================== 24 | TO-DO list 25 | ================================================== 26 | */ 27 | void Neurolab::updateChannelSettings(void){ 28 | /* ... */ 29 | } 30 | 31 | void Neurolab::writeChannelSettings(void){ 32 | /* ... */ 33 | } 34 | 35 | void Neurolab::setChannelsToDefault(void){ 36 | /* ... */ 37 | } 38 | 39 | void Neurolab::sendChannelData(byte){ 40 | /* ... */ 41 | } 42 | 43 | void Neurolab::reportDefaultChannelSettings(void){ 44 | /* ... */ 45 | } 46 | 47 | void Neurolab::startStreaming(void){ 48 | /* ... */ 49 | } 50 | 51 | void Neurolab::stopStreaming(void){ 52 | /* ... */ 53 | } 54 | 55 | /* 56 | ================================================== 57 | AD7173 functions 58 | ================================================== 59 | */ 60 | void Neurolab::initialize_adc(void){ 61 | /* initialize SPI connection to the ADC */ 62 | AD7173.init(); 63 | } 64 | 65 | void Neurolab::reset_adc(void){ 66 | /* reset ADC to default */ 67 | AD7173.reset(); 68 | } 69 | 70 | void Neurolab::sync_adc(void){ 71 | /* sync the ADC */ 72 | AD7173.sync(); 73 | } 74 | 75 | void Neurolab::get_current_adc_data_channel(adc7173_register_t &channel){ 76 | /*gets the current conversion results channel*/ 77 | AD7173.get_current_data_channel(channel); 78 | } 79 | 80 | void Neurolab::set_adc_mode_config(data_mode_t data_mode, clock_mode_t clock_mode){ 81 | /*sets the ADC mode configuration*/ 82 | AD7173.set_adc_mode_config(data_mode, clock_mode); 83 | } 84 | 85 | void Neurolab::set_adc_interface_mode_config(bool continuous_read, bool append_status_reg){ 86 | /* sets the ADC interface mode configuration */ 87 | AD7173.set_interface_mode_config(continuous_read, append_status_reg); 88 | } 89 | 90 | void Neurolab::get_adc_data(byte *value){ 91 | /*gets the ADC conversion result*/ 92 | AD7173.get_data(value); 93 | } 94 | 95 | void Neurolab::set_adc_channel_config(adc7173_register_t channel, bool enable, adc7173_register_t setupc, analog_input_t ain_pos, analog_input_t ain_neg){ 96 | /* configures ADC channels */ 97 | AD7173.set_channel_config(channel,enable, setupc, ain_pos, ain_neg); 98 | } 99 | 100 | void Neurolab::set_adc_setup_config(adc7173_register_t setupc, coding_mode_t coding_mode){ 101 | /*sets the ADC setups coding mode*/ 102 | AD7173.set_setup_config(setupc ,coding_mode); 103 | } 104 | 105 | void Neurolab::set_adc_filter_config(adc7173_register_t filter, data_rate_t data_rate){ 106 | /*sets the ADC filters data conversion rate*/ 107 | AD7173.set_filter_config(filter, data_rate); 108 | } 109 | 110 | void Neurolab::set_adc_gain_registers(adc7173_register_t gain, uint32_t gain_value){ 111 | /*sets the ADC gain compensation value*/ 112 | AD7173.set_gain_registers( gain ,gain_value); 113 | } 114 | -------------------------------------------------------------------------------- /Neurolab.h: -------------------------------------------------------------------------------- 1 | #ifndef ____Neurolab__ 2 | #define ____Neurolab__ 3 | 4 | #include "AD7173.h" 5 | #include "definitions.h" 6 | class Neurolab{ 7 | 8 | public: 9 | 10 | AD7173Class ads; 11 | 12 | /* VARIABLES */ 13 | int outputType; 14 | 15 | /* BOARD WIDE FUNCTIONS 16 | TO-DO list */ 17 | void initialize(void); 18 | void updateChannelSettings(void); 19 | void writeChannelSettings(void); 20 | void setChannelsToDefault(void); 21 | void sendChannelData(byte); 22 | void reportDefaultChannelSettings(void); 23 | void startStreaming(void); 24 | void stopStreaming(void); 25 | 26 | /* ADS1299 FUNCITONS */ 27 | /* 28 | ============================================ 29 | initializes the SPI connection with the ADC 30 | ============================================ 31 | */ 32 | void initialize_adc(void); 33 | 34 | /* 35 | ============================================== 36 | resets the ADC registers to the default state 37 | ============================================== 38 | */ 39 | void reset_adc(void); 40 | 41 | /* 42 | ================================================== 43 | cancels the current transaction to resync the ADC 44 | ================================================== 45 | */ 46 | void sync_adc(void); 47 | 48 | /* 49 | ============================================= 50 | gets the current conversion results channel 51 | @param byte - current data channel 52 | @return int - error code 53 | ============================================= 54 | */ 55 | void get_current_adc_data_channel(adc7173_register_t &); 56 | 57 | /* 58 | ================================ 59 | sets the ADC mode configuration 60 | @param clock_mode_t - clock mode 61 | @return int - error code 62 | ================================ 63 | */ 64 | void set_adc_mode_config(data_mode_t, clock_mode_t); 65 | 66 | /* 67 | ================================================== 68 | sets the ADC interface mode configuration 69 | @param bool - ensable/disable continuous read mode 70 | @return int - error code 71 | ================================================== 72 | */ 73 | void set_adc_interface_mode_config(bool, bool); 74 | 75 | /* 76 | ========================================== 77 | gets the ADC conversion result 78 | @return byte[] - the ADC conversion result 79 | ========================================== 80 | */ 81 | void get_adc_data(byte *); 82 | 83 | /* 84 | ===================================== 85 | configures ADC channels 86 | @param byte - channel register 87 | @param bool - enable/disable channel 88 | @param byte - setup register 89 | @param byte - analog input positive 90 | @param byte - analog input negative 91 | @return int - error code 92 | ===================================== 93 | */ 94 | void set_adc_channel_config(adc7173_register_t, bool, adc7173_register_t, analog_input_t, analog_input_t); 95 | 96 | /* 97 | ================================== 98 | sets the ADC setups coding mode 99 | @param byte - setup register 100 | @param condig_mode_t - coding mode 101 | @return int - error code 102 | ================================== 103 | */ 104 | void set_adc_setup_config(adc7173_register_t, coding_mode_t); 105 | 106 | /* 107 | ========================================== 108 | sets the ADC filters data conversion rate 109 | @param byte - filter register 110 | @param byte - data rate 111 | @return int - error code 112 | ========================================== 113 | */ 114 | void set_adc_filter_config(adc7173_register_t, data_rate_t); 115 | 116 | /* 117 | ====================================== 118 | sets the ADC offset compensation value 119 | @param byte - offset register 120 | @param uint32_t - offset value 121 | @return int - error code 122 | ====================================== 123 | */ 124 | void set_adc_gain_registers(adc7173_register_t, uint32_t); 125 | 126 | /* 127 | Here you can implement other functions related to Neurolab like 128 | accelerometer, sdcard, wifi module etc.. 129 | 130 | */ 131 | 132 | }; 133 | 134 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Neurolab Firmware 2 | 3 | Repository for firmware of Neurolab Open Hardware Platform. 4 | 5 | [![Build Status](https://travis-ci.org/fossasia/neurolab-firmware.svg?branch=master)](https://travis-ci.org/fossasia/neurolab-firmware) 6 | [![Gitter](https://badges.gitter.im/fossasia/neurolab.svg)](https://gitter.im/fossasia/neurolab?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) 7 | [![Mailing List](https://img.shields.io/badge/Mailing%20List-FOSSASIA-blue.svg)](https://groups.google.com/forum/#!forum/pslab-fossasia) 8 | [![Twitter Follow](https://img.shields.io/twitter/follow/pslabio.svg?style=social&label=Follow&maxAge=2592000?style=flat-square)](https://twitter.com/pslabio) 9 | 10 | We are developing a neuro-device as a headband with integrated electronics. This repository holds the firmware for the Neurolab Hardware. The initial version of the firmware is based on the original AD7173-Arduino library of the Brain-Duino project. 11 | 12 | ## Buy 13 | 14 | * You can get the device in future from the [FOSSASIA Shop](https://fossasia.com). 15 | * More resellers will be listed on the [PSLab website](https://pslab.io/shop/). 16 | 17 | ## Communication 18 | 19 | * The Neurolab [chat channel is on Gitter](https://gitter.im/fossasia/neurolab). 20 | * Please also join us on the [Mailing List](https://groups.google.com/forum/#!forum/pslab-fossasia). 21 | 22 | ## Goals of Neurolab 23 | 24 | The goal of the Neurolab project is to develop an easy to use open hardware measurement headset device for brain waves that can be plugged into an Android smartphone and a software application and enables us to understand our brains better. 25 | 26 | Our brains communicate through neurotransmitters and their activity emits electricity. The neuroheadset measures that electricity on the skin of the forehead and the software processes the signal so that it can translated into a visual or auditory representation. The data that can be collected can be analysed to identify mental health, stress, relaxation and even diseases like Alzheimer. 27 | 28 | Current devices in the medical industry are usually not accessible by doctors due to their high pricing. They are also complicated to use. The idea of the device is to integrate it into a headband and focus and focus on signals that can be obtained through the frontal lobe. 29 | 30 | A difference to existing projects like OpenBCI is that it will not be necessary to 3D print large headsets. Instead we are focusing on creating a device that collects as much data as possible through the forehead. To achieve this goal we are using high-grade sensors and flexible electronics. 31 | 32 | ## Setup 33 | 34 | * 1007 data rate 35 | * external crystal 36 | * continuous conversion mode 37 | * 4 analog inputs, 2 bipolar channels 38 | 39 | ```c 40 | AD7173.set_channel_config(CH0, true, SETUP0, AIN8, AIN9); 41 | AD7173.set_channel_config(CH1, true, SETUP0, AIN10, AIN11); 42 | AD7173.set_setup_config(SETUP0, BIPOLAR); 43 | AD7173.set_filter_config(FILTER0, SPS_1007); 44 | AD7173.set_adc_mode_config(CONTINUOUS_CONVERSION_MODE, EXTERNAL_CRYSTAL); 45 | ``` 46 | 47 | ## License 48 | 49 | This development of the files in this project are licensed under the Apache License 2.0 license. Some older files are under a Creative Commons license, other specific licenses are mentioned in the respective files. A copy of the [LICENSE Agreement](LICENSE) is to be present along with the source code. To obtain the software under a different license, please contact FOSSASIA or the relevant contributors. 50 | -------------------------------------------------------------------------------- /definitions.h: -------------------------------------------------------------------------------- 1 | #ifndef ____definitions__ 2 | #define ____definitions__ 3 | 4 | 5 | /* registers */ 6 | typedef enum { 7 | /* other ADC registers */ 8 | COMMS_REG = 0x00, 9 | STATUS_REG = 0x00, 10 | ADCMODE_REG = 0x01, 11 | IFMODE_REG = 0x02, 12 | REGCHECK_REG = 0x03, 13 | DATA_REG = 0x04, 14 | GPIOCON_REG = 0x06, 15 | ID_REG = 0x07, 16 | /* ADC channel registers */ 17 | CH0 = 0x10, 18 | CH1 = 0x11, 19 | CH2 = 0x12, 20 | CH3 = 0x13, 21 | CH4 = 0x14, 22 | CH5 = 0x15, 23 | CH6 = 0x16, 24 | CH7 = 0x17, 25 | CH8 = 0x18, 26 | CH9 = 0x19, 27 | CH10 = 0x1A, 28 | CH11 = 0x1B, 29 | CH12 = 0x1C, 30 | CH13 = 0x1D, 31 | CH14 = 0x1E, 32 | CH15 = 0x1F, 33 | /* ADC setup config register */ 34 | SETUP0 = 0x20, 35 | SETUP1 = 0x21, 36 | SETUP2 = 0x22, 37 | SETUP3 = 0x23, 38 | SETUP4 = 0x24, 39 | SETUP5 = 0x25, 40 | SETUP6 = 0x26, 41 | SETUP7 = 0x27, 42 | /* ADC filter config registers */ 43 | FILTER0 = 0x28, 44 | FILTER1 = 0x29, 45 | FILTER2 = 0x2A, 46 | FILTER3 = 0x2B, 47 | FILTER4 = 0x2C, 48 | FILTER5 = 0x2D, 49 | FILTER6 = 0x2E, 50 | FILTER7 = 0x2F, 51 | /* ADC offset registers */ 52 | OFFSET0 = 0x30, 53 | OFFSET1 = 0x31, 54 | OFFSET2 = 0x32, 55 | OFFSET3 = 0x33, 56 | OFFSET4 = 0x34, 57 | OFFSET5 = 0x35, 58 | OFFSET6 = 0x36, 59 | OFFSET7 = 0x37, 60 | /* ADC gain registers */ 61 | GAIN0 = 0x38, 62 | GAIN1 = 0x39, 63 | GAIN2 = 0x3A, 64 | GAIN3 = 0x3B, 65 | GAIN4 = 0x3C, 66 | GAIN5 = 0x3D, 67 | GAIN6 = 0x3E, 68 | GAIN7 = 0x3F 69 | } adc7173_register_t; 70 | 71 | /* ADC analog inputs */ 72 | typedef enum { 73 | AIN0 = 0x00, 74 | AIN1 = 0x01, 75 | AIN2 = 0x02, 76 | AIN3 = 0x03, 77 | AIN4 = 0x04, 78 | AIN5 = 0x05, 79 | AIN6 = 0x06, 80 | AIN7 = 0x07, 81 | AIN8 = 0x08, 82 | AIN9 = 0x09, 83 | AIN10 = 0x0A, 84 | AIN11 = 0x0B, 85 | AIN12 = 0x0C, 86 | AIN13 = 0x0D, 87 | AIN14 = 0x0E, 88 | AIN15 = 0x0F, 89 | AIN16 = 0x10, 90 | /* other ADC analog inputs */ 91 | TEMP_SENSOR_POS = 0x11, 92 | TEMP_SENSOR_NEG = 0x12, 93 | REF_POS = 0x15, 94 | REF_NEG = 0x16 95 | } analog_input_t; 96 | 97 | /* ADC filter data rates (samples per second) */ 98 | /* some are are rounded down, the data rates are for sinc5 + sinc1 */ 99 | typedef enum { 100 | SPS_31250 = 0x00, 101 | SPS_15625 = 0x06, 102 | SPS_10417 = 0x07, 103 | SPS_5208 = 0x08, 104 | SPS_2597 = 0x09, 105 | SPS_1007 = 0x0A, 106 | SPS_503 = 0x0B, 107 | SPS_381 = 0x0C, 108 | SPS_200 = 0x0D, 109 | SPS_100 = 0x0E, 110 | SPS_59 = 0x0F, 111 | SPS_49 = 0x10, 112 | SPS_20 = 0x11, 113 | SPS_16 = 0x12, 114 | SPS_10 = 0x13, 115 | SPS_5 = 0x14, 116 | SPS_2 = 0x15, 117 | SPS_1 = 0x16 118 | } data_rate_t; 119 | 120 | /* ADC setup coding modes */ 121 | typedef enum { 122 | UNIPOLAR = 0x00, 123 | BIPOLAR = 0x01 124 | } coding_mode_t; 125 | 126 | /* ADC data conversion modes */ 127 | typedef enum { 128 | CONTINUOUS_CONVERSION_MODE = 0x00, 129 | SINGLE_CONVERSION_MODE = 0x01, 130 | CONTINUOUS_READ_MODE 131 | } data_mode_t; 132 | 133 | /* clock mode */ 134 | /* 135 | 00 Internal oscillator 136 | 01 Internal oscillator output on XTAL2/CLKIO pin 137 | 10 External clock input on XTAL2/CLKIO pin 138 | 11 External crystal on XTAL1 and XTAL2/CLKIO pins 139 | */ 140 | typedef enum { 141 | INTERNAL_CLOCK = 0x00, 142 | INTERNAL_CLOCK_OUTPUT = 0x01, 143 | EXTERNAL_CLOCK_INPUT = 0x02, 144 | EXTERNAL_CRYSTAL = 0x03 145 | } clock_mode_t; 146 | 147 | #endif -------------------------------------------------------------------------------- /examples/Basic/Basic.ino: -------------------------------------------------------------------------------- 1 | /* 2 | ================================================= 3 | example to configure and get data from AD7173 ADC 4 | ================================================= 5 | */ 6 | #include 7 | 8 | void setup() { 9 | /* initiate serial communication */ 10 | Serial.begin(230400); 11 | 12 | /* initialize SPI connection to the ADC */ 13 | AD7173.init(); 14 | 15 | /* sync the ADC */ 16 | AD7173.sync(); 17 | 18 | /* reset the ADC registers to default */ 19 | AD7173.reset(); 20 | 21 | /* check if the ID register of the ADC is valid */ 22 | if (AD7173.is_valid_id()) Serial.println("AD7173 ID is valid"); 23 | else Serial.println("AD7173 ID is invalid"); 24 | 25 | /* set ADC input channel configuration */ 26 | /* enable channel 0 and channel 1 and connect each to 2 analog inputs for bipolar input */ 27 | /* CH0 - CH15 */ 28 | /* true/false to enable/disable channel */ 29 | /* SETUP0 - SETUP7 */ 30 | /* AIN0 - AIN16 */ 31 | AD7173.set_channel_config(CH0, true, SETUP0, AIN0, AIN1); 32 | AD7173.set_channel_config(CH1, true, SETUP0, AIN2, AIN3); 33 | 34 | /* set the ADC SETUP0 coding mode to BIPLOAR output */ 35 | /* SETUP0 - SETUP7 */ 36 | /* BIPOLAR, UNIPOLAR */ 37 | AD7173.set_setup_config(SETUP0, BIPOLAR); 38 | 39 | /* set ADC OFFSET0 offset value */ 40 | /* OFFSET0 - OFFSET7 */ 41 | AD7173.set_offset_config(OFFSET0, 0); 42 | 43 | /* set the ADC FILTER0 ac_rejection to false and samplingrate to 1007 Hz */ 44 | /* FILTER0 - FILTER7 */ 45 | /* SPS_1, SPS_2, SPS_5, SPS_10, SPS_16, SPS_20, SPS_49, SPS_59, SPS_100, SPS_200 */ 46 | /* SPS_381, SPS_503, SPS_1007, SPS_2597, SPS_5208, SPS_10417, SPS_15625, SPS_31250 */ 47 | AD7173.set_filter_config(FILTER0, SPS_1007); 48 | 49 | /* 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 */ 53 | /* INTERNAL_CLOCK, INTERNAL_CLOCK_OUTPUT, EXTERNAL_CLOCK_INPUT, EXTERNAL_CRYSTAL */ 54 | AD7173.set_adc_mode_config(CONTINUOUS_CONVERSION_MODE, INTERNAL_CLOCK); 55 | 56 | /* enable/disable CONTINUOUS_READ_MODE and appending STATUS register to data */ 57 | /* to exit CONTINUOUS_READ_MODE use AD7173.reset(); */ 58 | /* AD7173.reset(); returns all registers to default state, so everything has to be setup again */ 59 | AD7173.set_interface_mode_config(false, true); 60 | 61 | /* wait for ADC */ 62 | delay(10); 63 | } 64 | 65 | /* ADC conversion data and STATUS register */ 66 | byte data[4]; 67 | 68 | void loop() { 69 | /* when ADC conversion is finished */ 70 | if (DATA_READY) { 71 | /* get ADC conversion result */ 72 | AD7173.get_data(data); 73 | 74 | /* send result via serial */ 75 | Serial.print(data[0], HEX); 76 | Serial.print(data[1], HEX); 77 | Serial.println(data[2], HEX); 78 | Serial.println(data[3], HEX); 79 | delay(100); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map AD7173 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | AD7173 KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | init KEYWORD2 16 | reset KEYWORD2 17 | sync KEYWORD2 18 | get_data KEYWORD2 19 | is_valid_id KEYWORD2 20 | set_setup_config KEYWORD2 21 | set_offset_config KEYWORD2 22 | set_filter_config KEYWORD2 23 | set_channel_config KEYWORD2 24 | set_gain_registers KEYWORD2 25 | set_adc_mode_config KEYWORD2 26 | get_current_data_channel KEYWORD2 27 | set_interface_mode_config KEYWORD2 28 | 29 | ####################################### 30 | # Constants (LITERAL1) 31 | ####################################### 32 | 33 | CH0 LITERAL1 34 | CH1 LITERAL1 35 | CH2 LITERAL1 36 | CH3 LITERAL1 37 | CH4 LITERAL1 38 | CH5 LITERAL1 39 | CH6 LITERAL1 40 | CH7 LITERAL1 41 | CH8 LITERAL1 42 | CH9 LITERAL1 43 | CH10 LITERAL1 44 | CH11 LITERAL1 45 | CH12 LITERAL1 46 | CH13 LITERAL1 47 | CH14 LITERAL1 48 | CH15 LITERAL1 49 | 50 | AIN0 LITERAL1 51 | AIN1 LITERAL1 52 | AIN2 LITERAL1 53 | AIN3 LITERAL1 54 | AIN4 LITERAL1 55 | AIN5 LITERAL1 56 | AIN6 LITERAL1 57 | AIN7 LITERAL1 58 | AIN8 LITERAL1 59 | AIN9 LITERAL1 60 | AIN10 LITERAL1 61 | AIN11 LITERAL1 62 | AIN12 LITERAL1 63 | AIN13 LITERAL1 64 | AIN14 LITERAL1 65 | AIN15 LITERAL1 66 | AIN16 LITERAL1 67 | REF_POS LITERAL1 68 | REF_NEG LITERAL1 69 | TEMP_SENSOR_POS LITERAL1 70 | TEMP_SENSOR_NEG LITERAL1 71 | 72 | SPS_1 LITERAL1 73 | SPS_2 LITERAL1 74 | SPS_5 LITERAL1 75 | SPS_10 LITERAL1 76 | SPS_16 LITERAL1 77 | SPS_20 LITERAL1 78 | SPS_49 LITERAL1 79 | SPS_59 LITERAL1 80 | SPS_100 LITERAL1 81 | SPS_200 LITERAL1 82 | SPS_381 LITERAL1 83 | SPS_503 LITERAL1 84 | SPS_1007 LITERAL1 85 | SPS_2597 LITERAL1 86 | SPS_5208 LITERAL1 87 | SPS_10417 LITERAL1 88 | SPS_15625 LITERAL1 89 | SPS_31250 LITERAL1 90 | 91 | FILTER0 LITERAL1 92 | FILTER1 LITERAL1 93 | FILTER2 LITERAL1 94 | FILTER3 LITERAL1 95 | FILTER4 LITERAL1 96 | FILTER5 LITERAL1 97 | FILTER6 LITERAL1 98 | FILTER7 LITERAL1 99 | 100 | SETUP0 LITERAL1 101 | SETUP1 LITERAL1 102 | SETUP2 LITERAL1 103 | SETUP3 LITERAL1 104 | SETUP4 LITERAL1 105 | SETUP5 LITERAL1 106 | SETUP6 LITERAL1 107 | SETUP7 LITERAL1 108 | 109 | OFFSET0 LITERAL1 110 | OFFSET1 LITERAL1 111 | OFFSET2 LITERAL1 112 | OFFSET3 LITERAL1 113 | OFFSET4 LITERAL1 114 | OFFSET5 LITERAL1 115 | OFFSET6 LITERAL1 116 | OFFSET7 LITERAL1 117 | 118 | DATA_READY LITERAL1 119 | 120 | BIPOLAR LITERAL1 121 | UNIPOLAR LITERAL1 122 | 123 | INTERNAL_CLOCK LITERAL1 124 | EXTERNAL_CRYSTAL LITERAL1 125 | EXTERNAL_CLOCK_INPUT LITERAL1 126 | INTERNAL_CLOCK_OUTPUT LITERAL1 127 | 128 | CONTINUOUS_READ_MODE LITERAL1 129 | SINGLE_CONVERSION_MODE LITERAL1 130 | CONTINUOUS_CONVERSION_MODE LITERAL1 -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=AD7173 2 | version=0.4 3 | author=Silver Kuusik 4 | maintainer=Silver Kuusik 5 | sentence=Arduino library for Analog Devices AD7173 analog digital converter 6 | 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. 7 | category=Communication 8 | url=https://github.com/brain-duino/AD7173-Arduino 9 | architectures=* 10 | --------------------------------------------------------------------------------