I am sampling 3 sensors using the ADC peripheral, clocking it once every 15us to sample the 3 sensors (3us acquisition time + 2us processing = 5us per channel).
I use the easy DMA in double buffer to sample 402 samples and interrupt me so i can process them and prepare the DMA next buffer (interrupt every 402*15/3=2100us).
In the interrupt context, I copy the buffer into a continuous big buffer and to excel and this is what i see:
when i stop the adc sampling and start it again (vertical spike above), i sometimes have a glitch that looks as if one sample is missed and i thus get channel 2 instead of 1 as shown in the above image. The vertical spike seen in the image is just a marker i add to the debug software buffer to mark where i re-enabled adc sampling.
The image above contains ~6 concatenated buffers (each buffer holds 402 samples = 134 samples from each of the 3).
Following is the code i use:
In the code i have '#if 0' in line 131 commenting out the bit of code that causes the glitch problem.
When i remove it i see no glitches.
In the blocked code shuts down the ADc in order to save power.
It blocked code is art of code within the ADC interrupt that is trigered when someone set 'flag_stop_sampling' to 1 in order to stop ADC sampling.
My point is - if i disable the ADC peripheral (as i do) in between samples and later on wake it up again and re configure the entire logic - how come i see glitches of channels in my buffer.
My target was to make my software implementation to do the sampling regardless of softdevice and other tasks interrupts.