Ring Buffer Maximum Size

Hello, 

I'm reading about 700 values from an LSM6SDO gyro/accelerometers per second and need to store them, before sending them over bluetooth once where I store them is full. I briefly looked into flash storage, but it seems like ring buffers are the best way to go for my application. What is the best way to do this using ring buffers? Specifically, one question I had is how to use one (or multiple) ring buffers to store the most data possible. In my application, the amount of time that I can record data for will be dependent on the maximum amount of storage space I can use. I've looked through the ring buffer library, and it seems like one ring buffer can only hold 64 words worth of information. Does this mean I'll need to use more ring buffers? Any help you can provide would be greatly appreciated. I talk a little bit more about my specific application in this post. 

Thank you!

  • Hi,

    Thanks for inqurying with us about your application design questions. It is out of supporting scope but I want to share some of my through about your current chanelleges.

    1. You current data input is 700x64bit(double value)/s=448000bps, cosidering you are use BLE 2Mbps data rate. The system produced much more data than it can consume. You have to consider decrease data proudction rate or increase comsumer capability, otherwise, there is not so much meaning to use ring buffer, whcih only make sure you can will send latest data chunk per BLE date sending interval, but most of old is droped by ring buffer.

    2. I am not sure where you get the information, one ring buffer can only hold 64 words worth of information is not ture. The ring buffer size is only limited by the RAM size you can assign for ring buffer. Ring Buffers descrips the ring buffer usage. You can search 

    ring_buf_init in NCS code base to find serveral real ring buffer usage in samples.

    Thank you for inquiring about your application design questions. While this is outside our official support scope about specific application design, I’d like to share some thoughts regarding your current challenges:

    1. Data Input vs. Throughput
      Your current data input rate is calculated as 700 × 64 bits (double value) per second = 448,000 bps. Considering if you are using the BLE with the maxium 2 Mbps data rate, your system generates far more data than it can handle. To address this, you’ll need to either:

      • Decrease the data production rate, or
      • Increase the data consumer capability.
        Without making these adjustments, the ring buffer will primarily ensure that the latest data chunk is sent per BLE interval, but a significant amount of older data will be dropped.
    2. Ring Buffer Size Misconception
      The idea that a ring buffer can only hold 64 words of information is not accurate. The size of the ring buffer is determined solely by the amount of RAM allocated to it. For further details, you can refer to the Zephyr Ring Buffers documentation.

      You can also look for ring_buf_init in the NCS codebase to find examples of how ring buffers are used in various samples.

    I hope this helps provide clarity. Let me know if you need further assistance.

    Best regards,

    Charlie

     

  • Thank you for the response. I'm still not sure that this fully solves my issue. My plan is to use the maximum buffer size possible, wait until it is full, and then stop recording data and send what is in the buffer over bluetooth. The main question that I had was the best way to allocate the 'most' possible memory to the ring buffer (make it as large as possible so I can store more data). Also, you said the maximum data transfer rate was 2Mbps, which as far as I know is 2,000,000 bps. I don't really understand how my data rate (~448,000 bps) exceeds that. Some clarification might be helpful. Thank you again for the help!

    Also - I am using VSCode, C language, and the nRF52832 chip.

  • Hi,

    Apologies for the confusion in my previous message. I mentioned 2 Mbps, but I had kbps in mind due to another audio project I’m working on.

    While the actual throughput may be lower than the theoretical 2 Mbps, it should still be sufficient for your application. For more details on this topic, you can refer to

    Bluetooth 5 Speed: How to Achieve Maximum Throughput which explains deatails on this topic.

    I think next step you can refer the ring buffer sampels on NCS code base to have a try.

    Best regards,

    Charlie

  • No worries. I just want to clarify again - it isn't the speed of the bluetooth process I am interested in here, it is solely how to store the most data possible in RAM, whether that be through making multiple ring buffers or just one large one. I am still in confusion about this, but will continue to search other documentation.

  • connorshannon said:
    it is solely how to store the most data possible in RAM, whether that be through making multiple ring buffers or just one large one.

    I would recommend using a single ring buffer unless there are specific reasons to justify multiple buffers. If your goal is to store as much data as possible in RAM, you might want to consider using a chip like the nRF52840 instead of the nRF52832. The amount of ring buffers doesn’t significantly impact the storage capacity compared to the RAM availability.

    Best regards,

    Charlie

Related