This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Using ring buffer to store 16 bits ADC data

Ring buffer operates on uint8_t , but I would like to use ring buffer to store 16 bits ADC data.  What is the simplest  solution?

Converting 16 bits data into 8 bits, store the data into ring buffer, get data back from ring buffer and then convert the data back to 16 bits, seems like a lot of work.

Is it possible to modify the ring buffer to use 16 bits instead of 8 bit for data storage?   Is it simpler to just write a simple ring buffer;  do you have an example?

I just need a simple ring buffer to store certain amount of ADC data before I process the data.   A simple buffer would not work.

Parents
  • Hello,

    Converting 16 bits data into 8 bits, store the data into ring buffer, get data back from ring buffer and then convert the data back to 16 bits, seems like a lot of work.

    That depends, how advanced do you need the buffer? The simplest implementation of a ring buffer takes a very short time to implement, and there are multiple implementations and guides written about this.
    However, typecasting the 16 bit data to two 8 bit ones, and having the ring buffer skip twice the memory distance, also shouldnt take too long to implement - but this will also warrant some testing of the modified library, to check that the modification did you break anything else.

    Is it possible to modify the ring buffer to use 16 bits instead of 8 bit for data storage?   Is it simpler to just write a simple ring buffer;  do you have an example?

    You could of course modify the ring buffer library, but you would need to test and verify that you changes makes sense and achieve the desired functionality without breaking the library in any other unexpected way. Its hard for me to gauge which of these will be the best for you, since I neither know the required ring-buffer functionality, nor your programming skill level and familiarity with the existing library.

    I just need a simple ring buffer to store certain amount of ADC data before I process the data.   A simple buffer would not work.

    Please elaborate on what you mean by this, do you need a simple ring buffer or not?
    If you just need a simple ring buffer I would suggest making your own implementation of this, as this saves you the time it takes to get into the existing library's source code, and testing of the modified version.

    Please do not hesitate to ask if any part of my answer is unclear, or if you have any other issues or questions!

    Best regards,
    Karl

Reply
  • Hello,

    Converting 16 bits data into 8 bits, store the data into ring buffer, get data back from ring buffer and then convert the data back to 16 bits, seems like a lot of work.

    That depends, how advanced do you need the buffer? The simplest implementation of a ring buffer takes a very short time to implement, and there are multiple implementations and guides written about this.
    However, typecasting the 16 bit data to two 8 bit ones, and having the ring buffer skip twice the memory distance, also shouldnt take too long to implement - but this will also warrant some testing of the modified library, to check that the modification did you break anything else.

    Is it possible to modify the ring buffer to use 16 bits instead of 8 bit for data storage?   Is it simpler to just write a simple ring buffer;  do you have an example?

    You could of course modify the ring buffer library, but you would need to test and verify that you changes makes sense and achieve the desired functionality without breaking the library in any other unexpected way. Its hard for me to gauge which of these will be the best for you, since I neither know the required ring-buffer functionality, nor your programming skill level and familiarity with the existing library.

    I just need a simple ring buffer to store certain amount of ADC data before I process the data.   A simple buffer would not work.

    Please elaborate on what you mean by this, do you need a simple ring buffer or not?
    If you just need a simple ring buffer I would suggest making your own implementation of this, as this saves you the time it takes to get into the existing library's source code, and testing of the modified version.

    Please do not hesitate to ask if any part of my answer is unclear, or if you have any other issues or questions!

    Best regards,
    Karl

Children
No Data
Related