Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Suggestions for interrupt safe fast buffering approach

  1. #1

    Suggestions for interrupt safe fast buffering approach

    This relates to a data capture and streaming application, where at its fastest (currently) a combination of ADC results, time stamp, encoder count and input byte are written to a buffer in the ADC data ready ISR.

    Total number of bytes per sample is 18 (could go up to 30) so 2.3 to 3.2Mbytes / second.

    In the streaming mode, this is read from the buffer (currently a circular one) and streamed out either a UART or UDP over ethernet.

    All is well until I get to 128ksps and then my current queue seems to be falling apart. I am using a nice queue library from here:

    It seems as though I should fall back to a simplified lower overhead (ie faster) and interrupt safe buffering approach.

    Should I stick with a circular buffer approach or a very simple ping pong two linear buffer pattern?

    Any other suggestions?

  2. #2
    Senior Member
    Join Date
    Oct 2016
    If it works up to 128ksps, it seems more likely that the buffer is overflowing than the buffer logic for some reason fails at that value. Can you make the buffer larger? Does CircularBuffer::write return an error if the buffer is full, and if so, are you checking for that error?

    I have used the ring buffer in SdFat\src\Ringbuf.h to do something similar up to 8 MB/sec.

  3. #3
    I've determined that at the 128ksps rate, it is basically running out of time for all processes to complete adequately and all hell brakes loose.

    I added the head and tail indexes to the stream and could see that strangely the tail index was not incrementing reliably but somehow the data was still being pulled from the queue and added to the output stream....At some point during the stream the tail index stops incrementing at all and then data starts to be lost in the stream.

    Until I can reduce the time taken by the ISR I don't think I can run up to that rate. Currently max reliable rate seems to be 85ksps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts