Before explaining the steps I've taken to date, I'd like to first describe the technical scope of my challenge. In short, I would like to acquire data (ADC) at a rate of 250,000 kSps that is synchronized with a trigger that occurs every 10-40 Hz. Additionally, it is necessary to perform signal averaging on the data as the actual signal is quite noisy (typically a couple of hundred averages is needed) so I would like to average the readings from the respective data bins as defined by the trigger.
[TL : DR]
How to sample multiple ADCs continuously while simultaneously stream data through the USB?
From my experimentation using the links and discussions below, I gather that a single buffer collecting all of the data at 12-bit resolution is simply not possible and that a buffering approach may be best through a combination of PDB and DMA. However, this raises the question as to how to synchronize the buffer to the trigger especially if you need a circular/ring buffer to capture the data? Is there a way to tag/timestamp the values with respect to the trigger and still stream the information?
My initial thought was to simply acquire data on two channels with ADC0 sampling the input trigger and ADC1 sample the actual signal, send the data back to the PC, and fold the data appropriately using some other script based upon the rising edges recorded on the ADC0 channel. Is this a rational approach or is there a better option?
Digging through the forums the range of examples from tni have been extremely helpful: https://forum.pjrc.com/threads/43708-Teensy-3-6-Datalogging-at-10kHz In this example I can get the sampling rates needed but it is unclear to me how to trigger the byte stream back to the PC. My guess is that I need to detect when the buffer is full and transfer the last half before it is overwritten. This seems to be where I'm running into a lack of knowledge regarding how to trigger an interrupt and use a circular/ring buffer appropriately.
Other potential/partial solutions investigated:
[TL : DR]
How to sample multiple ADCs continuously while simultaneously stream data through the USB?
From my experimentation using the links and discussions below, I gather that a single buffer collecting all of the data at 12-bit resolution is simply not possible and that a buffering approach may be best through a combination of PDB and DMA. However, this raises the question as to how to synchronize the buffer to the trigger especially if you need a circular/ring buffer to capture the data? Is there a way to tag/timestamp the values with respect to the trigger and still stream the information?
My initial thought was to simply acquire data on two channels with ADC0 sampling the input trigger and ADC1 sample the actual signal, send the data back to the PC, and fold the data appropriately using some other script based upon the rising edges recorded on the ADC0 channel. Is this a rational approach or is there a better option?
Digging through the forums the range of examples from tni have been extremely helpful: https://forum.pjrc.com/threads/43708-Teensy-3-6-Datalogging-at-10kHz In this example I can get the sampling rates needed but it is unclear to me how to trigger the byte stream back to the PC. My guess is that I need to detect when the buffer is full and transfer the last half before it is overwritten. This seems to be where I'm running into a lack of knowledge regarding how to trigger an interrupt and use a circular/ring buffer appropriately.
Other potential/partial solutions investigated:
- https://github.com/tni/teensy-samples/blob/master/SdFatSDIO_low_latency_logger.ino -- I can get 100 kSps with this and two ADCs but the SD card is not ideal for my purposes (moreover, the data files are mondo).
- Other notable posts that are close but don't quite mesh the target problem: https://forum.pjrc.com/threads/48099-Data-logger-Again-and-again
- Greiman's contribution is great. Where I get lost is how to add a second channel and change the target from the SD card to the Serial port (then again, I'm not sure that will yield the desired outcome). (https://forum.pjrc.com/threads/4599...-for-FAT16-FAT32-exFAT/page2?highlight=151962)