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

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

  1. #1
    Junior Member
    Join Date
    Oct 2020
    Posts
    14

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

    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.

  2. #2
    Senior Member brtaylor's Avatar
    Join Date
    Mar 2016
    Location
    Portland, OR
    Posts
    642
    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.

  3. #3
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    846
    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.

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    918
    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.

  5. #5
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,574
    Which Teensy are you going to use? How long a recording do you want?

    Pete

  6. #6
    Junior Member
    Join Date
    Oct 2020
    Posts
    14
    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.

Posting Permissions

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