Bascially yes. It uses the DMA to countinuously read n_samples into the buffer and it also uses the STM32 ability to manage double buffer mode. This means that the data gets written into one buffer, once this buffer is full, the next batch goes into the second buffer. This enables you to process the data from the first buffer while the second buffer ist filled. Make sure that the second buffer is large enough to hold two sample sizes.
Hi @pebbert999 and everyone else! I just made an amend to the current documentation regarding adc.begin() and what the parameters actually mean (see PR).
n_samples is the number of samples we want to acquire from the ADC, stored in a buffer (SampleBuffer). If we set this to e.g. 32, we have 32 samples in the buffer, which can be accessed via buffer[number]. This number is not limited to 32 by the way, I have tested with a 1000 samples in a single buffer.
Here's an example:
......
adc1.begin(AN_RESOLUTION_16, 16000, 32, 64); //initialize the ADC
......
SampleBuffer buf = adc.read(); //create buffer and store ADC values
Serial.println(buf[0]); //prints out first value from the buffer
Serial.println(buf[1]); //prints out second value from the buffer
n_buffer is the amount of free buffers available in a "buffer pool". When we read data, we take the available buffer, read it, and then place it back in the buffer pool. So it does not need to be twice the size of the samples.
Thank you for the clarification. So this is a little bit different from the original double buffering as described by ST (from where I had drawn my assumptions).
Hi @ksoderby, thanks for the explanation. What happens if you have multiple inputs/channels mapped to the same ADC. ADC Dual Mode seems to suggest that buf1[0] is the value of the first channel while buf1[1] is the value of the second channel. What about buf1.timestamp() in this case is this the timestamp of the start of the acquisition and what would the delay between the different channels be?
Thanks in advance
Best
J