Hi, I'm doing a project where I will be trying to data log multiple channels of analog input voltages and converting them to a digital signal with an ADC. I will be using several channels (at least six, if it's possible I might go all the way up to 24). the required conditions are ~10kHz sampling rate, hopefully 12 bit resolution or higher, and the ability to write the information to a card or usb stick as the data logging will take place away from a computer. the signals will also probably need amplifying (a gain of ~128 is probably the minimum I'd like to go for).
Now the question is how to choose the right ADC. I've heard that on an arduino only SPI and I2C can be used. I am very new to using arduinos so please bear with me.
Does adding an external ADC mean that it is much more difficult to code the data logging than if using the standard arduino ADC?
Does anyone know of the best ADC to use? I've been looking on RS and farnell etc. but the problem is I can't find a way of searching for the right gain amplification and I'm not entirely sure what will actually work with an arduino.
As for using multiple channels, say there was a 40kHz ADC that was 4 channel, does that mean I could use 1 channel at 40kHz or 4 channels at 10kHz?
As I'm doing multiple channels, what is the minimum number of microcontrollers I can get away with using (how many channels is maximum to 1 microcontroller)? For this the write speed may be a limiting factor, or the number of attachable ADCs to the microcontroller, I don't know.
Help with this project would be greatly appreciated.
There are several ADC architectures. Due to the complexity and the need for precisely matched components, all but the most specialized ADCs are implemented as integrated circuits (ICs). Check this link: https://www.ramelectronics.net/analog-digital.aspx
The number of channels you can do is extremely dependent on the hardware and A/D structure you chose. This will be one of determining factors of the micro controller choice. If you look at the Maxim Integrated MAX11261 Delta-Sigma ADC you can do 6 channels at 24 Bits and has a I2C interface. I have no idea of what the voltage range you are checking but this can run Gains of 1, 2, 4, 8, 16, 32, 64, 128. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil
ard_newbie:
What's the amount of data(number of Bytes) you are going to log from, say, 12 ADC channels ?
The amount of data is calculated as follows: 10kHz sample rate, 12 bit (1.5byte) per sample --> 15kB per second per channel. 4 channels --> 60kB/s. This needs to be done for 20 seconds at a time before being able to write to card as writing to a memory card is too slow to get the 10kHz, (at the moment the idea is that the data will be stored on the ram, if you have better ideas please let me know). 20 * 60kB = 1.2MB. If there is some sort of ram or something that you could add to an arduino or a really high performance microcontroller I think that would do the job. I'm willing to pay more money if it means I can get this data recorded well.
Use a Teensy3.6 to sample your signals and then send the sample data through either I2C, SPI, or Serial to a Teensy3.5 (or 3.6) for datalogging on a micro SD.
The Teensy 3.X series are extremely powerful, Arduino compatible boards, with built-in SD card readers
gilshultz:
There are several ADC architectures. Due to the complexity and the need for precisely matched components, all but the most specialized ADCs are implemented as integrated circuits (ICs). Check this link: https://www.ramelectronics.net/analog-digital.aspx
The number of channels you can do is extremely dependent on the hardware and A/D structure you chose. This will be one of determining factors of the micro controller choice. If you look at the Maxim Integrated MAX11261 Delta-Sigma ADC you can do 6 channels at 24 Bits and has a I2C interface. I have no idea of what the voltage range you are checking but this can run Gains of 1, 2, 4, 8, 16, 32, 64, 128. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil
I read the article, it was informative, although primarily about sound. I've looked into the matter more and I think the limiting issue will actually be recording the data rather than the ADC itself. Thanks for the ADC you posted though, it looks like it might work well. The issue is writing to a memory card slows the sampling rate down so I may have to store memory on the processor and dump it in chunks onto the card.
If there is a way to add ram to quickly store data or possibly getting a more powerful micro-controller that just has a lot more memory on the processor these may be possible options. or if there is some built in SSD type storage that could store data fast enough that could also work. Do you know which of these would be the best option?
Something else is FPGAs (field programmable grid arrays) which seem like they may be able to do the job well but also seem really complicated for an Arduino beginner, I'm looking into the MKR Vidor 4000 but it doesn't appear to have analog input ports (although I could probably get an external ADC).
If you have any experience with any of these pointing me in the right direction could be really helpful!
Power_Broker:
Use a Teensy3.6 to sample your signals and then send the sample data through either I2C, SPI, or Serial to a Teensy3.5 (or 3.6) for datalogging on a micro SD.
The Teensy 3.X series are extremely powerful, Arduino compatible boards, with built-in SD card readers
the teensy 3.6 has 256k of RAM and 1M (I guess 1MB(?)) of flash. 1Mb might just be enough to store between dumps to the SD card (reading directly to the SD card probably won't be able to handle a 10kHz sample speed). attaching and ADC to the teensy may then be a possible option. Thanks for the heads up, and let me know if anything in this paragraph is incorrect.
Edit: I think the teensy 4.0 has 1Mb ram and 2Mb flash which is even bettter: Teensy® 4.0
when they say K or M do they mean Kb and Mb? noob question I guess but important nonetheless
Can't go wrong with a Teensy 4.0, but since the sd-card reader is native to the Teensy 3.X boards, it's actually a very fast connection. Idk, the boards are relatively inexpensive - I suggest testing them out yourself.
If you go with a Teensy, there is no need for an external ADC. It would be faster to use the native ADC (16bit btw)
Since your target is 24 ADC, and conversion periods of at least 20 seconds, you could:
Use 2 arduino DUE (each one has 12 ADC, ~ $12 each board), connect the 2 boards together via one of their 5 hardware serial if you need some synchronization, trigger conversions at 10 KHz for each ADC channel (12 * 10 KHz is wayyy under the max of 1 Msps), use a PDC DMA to store ADC conversions into a collection of e.g. 1KB buffers (SRAM size is 96 KB), in parallel store the previous buffer into a USB high speed stick connected to the Native USB port of the DUE (USB 2.0 high speed).
You can find example sketches in the DUE sub forum for ADC DMA conversions.
To be sure that the write speed to the USB stick is correct, you might test with this library:
This library provides an example sketch to test its functions from user entries on serial monitor.
Note that data logging can be done too in Flash (512 KB) with the DueFlashStorage library.
Power_Broker:
Can't go wrong with a Teensy 4.0, but since the sd-card reader is native to the Teensy 3.X boards, it's actually a very fast connection. Idk, the boards are relatively inexpensive - I suggest testing them out yourself.
If you go with a Teensy, there is no need for an external ADC. It would be faster to use the native ADC (16bit btw)
Thanks so much for sharing info on this, very helpful, teensys are looking like they may be my microcontroller of choice at this stage. One issue with both the teensy 3.X and 4.0 is that they only have 2ADC ports, not 4 or more, so I'd be buying several of them, but that's not much of an issue if they all work. are you confident it could write a 12bit 10kHz sample rate to card as an arduino uno with a sheild was no way near?
I think even if that fails though storing it on the flash memory of the processor RAM and dumping it would be fine for 20 seconds at a time.
Another important thing is getting a gain of the signal, I'd like at least a gain of 100, is there some sort of amplifier for the teensy ADC ports?
It may be that getting an external ADC with several channels and a built in PGA (programmable gain amplifier) with an I2C or SPI interface and attaching it to the teensy is the best way forward, what are your thoughts? (It may be harder to programme and I'm a noob?)
Since your target is 24 ADC, and conversion periods of at least 20 seconds, you could:
Use 2 arduino DUE (each one has 12 ADC, ~ $12 each board), connect the 2 boards together via one of their 5 hardware serial if you need some synchronization, trigger conversions at 10 KHz for each ADC channel (12 * 10 KHz is wayyy under the max of 1 Msps), use a PDC DMA to store ADC conversions into a collection of e.g. 1KB buffers (SRAM size is 96 KB), in parallel store the previous buffer into a USB high speed stick connected to the Native USB port of the DUE (USB 2.0 high speed).
You can find example sketches in the DUE sub forum for ADC DMA conversions.
To be sure that the write speed to the USB stick is correct, you might test with this library:
This library provides an example sketch to test its functions from user entries on serial monitor.
Note that data logging can be done too in Flash (512 KB) with the DueFlashStorage library.
If I were to do 12 channels per Arduino Due that would be 15kBx12 = 180kB/s. now this may be exposing my complete lack of expertise in hardware etc. but when trying 5 ADC channels on an Uno the max rate was ~1.5kHz, and if it was being written to a card it was ~500Hz, and it seems that it was the card reader which was the bottleneck.
The Due has 512kB of flash memory which isn't enough to store 20 seconds of 10kHz 12 bit data. if writing to a card is even close to what it was like on the uno, it's far too slow. I could try writing to a USB stick rather than a card but would it really be that much faster? seeing as the store on the cpu and then dump option doesn't seem possible, writing to an SD card/USB stick seems like it won't be fast enough.
If any of my reasoning is faulty please point it out as this seems like a potential elegant solution if it works but at the moment it doesn't seem possible for my application.
Power_Broker:
Can't go wrong with a Teensy 4.0, but since the sd-card reader is native to the Teensy 3.X boards, it's actually a very fast connection. Idk, the boards are relatively inexpensive - I suggest testing them out yourself.
If you go with a Teensy, there is no need for an external ADC. It would be faster to use the native ADC (16bit btw)
This option is looking like it is almost working. the only thing is having a enough storage to store data at the rapid rate. If I want over 1Mb of data stored at a time (i.e more than the ram of a teensy) before dumping to an SD card (unless the sd card can store data at 10kHz or more) I'm not sure what to do. It might be possible to store data to the 2Mb of flash but I'm not sure how to do that easily on devices using the processors that have the architechture that teensys have.
I did a rapid test with a USB high speed stick connected to the Native USB port of a DUE and functions f_write()/f_read() shows a write speed of ~186 KBytes/s.
I tested a sketch by writing a buffer of 1024 uint16_t. I start a micros() timer just before writing (File is already opened), I stop the timer just after f_write() (and before f_close()).
More in depth testing should be necessary to optimize writing steps, but: 8 ADC channels * 20 KBytes (2 bytes per 12-bit sample) = 160 KBytes/s.
Edit: I tried with another USB high speed stcik, and this time, with the same test, I get the rate of 680 KBytes/s, something more coherent with a High Speed Bulk Out transfer!!!
It seems very promising...remains to know what the difference between those 2 USB sticks (maybe the pre-formating ?).
ard_newbie:
I did a rapid test with a USB high speed stick connected to the Native USB port of a DUE and functions f_write()/f_read() shows a write speed of ~186 KBytes/s.
I tested a sketch by writing a buffer of 1024 uint16_t. I start a micros() timer just before writing (File is already opened), I stop the timer just after f_write() (and before f_close()).
More in depth testing should be necessary to optimize writing steps, but: 8 ADC channels * 20 KBytes (2 bytes per 12-bit sample) = 160 KBytes/s.
Edit: I tried with another USB high speed stcik, and this time, with the same test, I get the rate of 680 KBytes/s, something more coherent with a High Speed Bulk Out transfer!!!
It seems very promising...remains to know what the difference between those 2 USB sticks (maybe the pre-formating ?).
Thanks for doing the tests! that's looking good. An important point, which I'm not sure if the code you tried tests is that when operating at 10kHz, one is writing one voltage reading, storing it on the memory stick, then doing another reading, then storing that on the memory stick I think. So then it's not just the read/write speed as it has to read, write, record rather than just keeping a file open and streaming into it a load of data.
If I am mistaken in my understanding just point it out. Could this literally write the 12 bit voltage values straight to the memory stick without an issue?
Again thanks for you help and even trying stuff out on your own Arduino to help me though
I did my "rapid" test by filling a uint16_t Buffer of 1024 items with dummy values, hence no need to wait for ADC conversions, then I store these values. In a real sketch, ADC conversions would be 100% handled thru a PDC DMA. That means ADC conversions are handled in parallel of data storing in the USB stick (nearly no need of CPU clocks for ADC conversions).
It's time for you to test by yourself, there's a learning curve !
Buy a DUE plus an USB OTG cable to connect a USB stick to tha Native USB port, find a good quality USB high speed stick. select FAT32 format for the USB stick (if not already done, do that from your PC).
Search in the DUE sub forum an example sketch for ADC conversions with a PDC DMA.
ard_newbie:
I did my "rapid" test by filling a uint16_t Buffer of 1024 items with dummy values, hence no need to wait for ADC conversions, then I store these values. In a real sketch, ADC conversions would be 100% handled thru a PDC DMA. That means ADC conversions are handled in parallel of data storing in the USB stick (nearly no need of CPU clocks for ADC conversions).
It's time for you to test by yourself, there's a learning curve !
Buy a DUE plus an USB OTG cable to connect a USB stick to tha Native USB port, find a good quality USB high speed stick. select FAT32 format for the USB stick (if not already done, do that from your PC).
Search in the DUE sub forum an example sketch for ADC conversions with a PDC DMA.
Yes, it's time to start trying things out, thanks for the help so far. One thing I didn't get a reply about was the gain of the signal. The ADC signals should have a gain of hopefully at least 128, preferably 500+.