• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C arrays, etc

Colt45

Lifer
I'm working on a little project that involves a 10bit ADC.

I want to take the adc value and then read the output value off an array.. simple enough.


but... I don't need the 10bit accuracy. a 1KB array is kind of excessive when 100B would be accurate enough. (not to mention I've only got 8KB of ROM)

so would the best way of doing this?
I was thinking to take the ADC input, divide by 10 and then read that off a 102 byte array?
Or is there an easier way?

I'm not terribly good at this so any ideas would be good 🙂

or is there a short way of writing an array with duplicate values? i.e. values 0 - 20 (out of 1024) are all 0xFF or something like that.

thanks
 
Yeah, do what Dave said, shift right by few bits. Each bit will divide the total by two, so shifting right by 1 will give you 512 values, by 2 gives you 256, by three gives you 128, and by 4 give you 64.

value >>= 1; // or 2, 3, or 4
 
Sounds good - I really should have thought of that.
I guess I did post it at 3 AM. 😉

thanks guys.
 
Back
Top