For one of my electronics projects I am using an EEPROM chip that holds up to 512k bits of information, arranged in 8-bit (1 Byte) address registers. Multiply 512 x 1024 and divide by 8 and you'll get 65,536 Bytes.
Using 8 bits I can store a binary value from 0 to 255 in any one of those 65,536 address registers.
However, the values I'm interested in storing are not 8-bit but 10-bit. These 10-bit values are voltage samples taken from an Analog-to-Digital converter inside a microcontroller.
What I'm doing now is to use two addresses to store the 10-bit samples, like so:
This allows me to store 32,768 10-bit samples, but I can see there is a lot of wasted space.
Ideally I would like to use every bit of available memory storage and store the samples in sequential form like this:
In order to randomly store or read one of those 10-bit samples I am wondering if there is a way to calculate the start and end memory and bit positions for any given sample.
Example: sample 12 start address: 13 start byte: 6
sorry, samples I counted from 1 and bit and memory addresses from 0
Obviously every sample always overlaps two memory addresses but I can't figure out how to apply the modulus to this problem and/or whether I need additional arithmetic to work it out.
To me it looks like there are two or maybe three moduluses (-ii?) that apply here, one of size 8 to get the bit positions and one of size 5 as the bits repeat on the same position after 5 address locations. Or do I need to do a mod 10 because it's ending on an odd address?
I've tried several things in a spreadsheet but I cannot seem to get a sequence that fits the addresses.
Some of my calculations went something like:
- sample * 1.2 - round up to whole number - add one if number from step 1 and 2 are the same - modulus(10) of the previous step - hope the result is the memory address of this sample
I better end my embarrassing attempt here..
What I'm after are functions (for lack of a better word) that can do this:
Once I know at what address and bit the sample starts I should be able to work out where the 10 bit sample stops.
I know beggers can't be choosers but the solution that works the fastest (in terms of processor steps) would be the clear winner.
EDIT: added 'and divide by 8' in the first paragraph for better clarity.