Can I use a 10 bit data type for ADC storage?

warpigs330

Active member
I have a project where I am recording the value of an analog input, Ideally the recording buffer would be as long as possible. Since the max reliable precision of the ADCs is 10 bit the extra 6 bits of an int is unused space. Is there a way to create an array of 10 bit data types? I am still pretty new to programming for imbedded systems, so haven't previously come up on these type of design considerations.
 
Yes, kind of. You could create a recording buffer as an array of 8 bit types (i.e. uint8_t) and then use some functions to write or read (push or pop) 10 bit data from that array. So, it's not natively a 10 bit type and it will take some work on your end to read and write 10 bit data to the array, but your end-goal (saving recording buffer space) is possible.
 
Sure, you could pack four 10 bit samples into every five bytes. But consider other approaches - like a teensy 4.1 or a larger sd card.
 
If you use an array of uint8_t for the top 8 bits, and pack the remaining bits into a subsiduary array you allow
faster operations on the 8 MSBs of the data, which might sometimes be useful.

Often for sampled data there is very strong correlation between successive values, meaning a compact coding based on
differences may be possible. This is strongly dependent on the nature of the specific time series involved.
 
It is likely that in the end it will be perfectly fine to use 16bit ints. My prototype uses ints and the recording buffers are long enough and high resolution enough for me to not run to the end of the buffers, or notice stepping. More just seems like an interesting problem to try and solve than is necessary to solve. I am also interested in the very small cheap end of microcontrollers where this type of thing is more necessary. I learned about uint8_t and 16_t and naively hoped that you could just make an int of any size.

I have been using the 4.0 but will likely use the 4.1 in the finished version just to be able to save to the SD card and recall on powerup.
 
Back
Top