making a 10-bit value from 2, 8-bit values
TC
Posts: 1,019
Hello all,
Sorry if this question is very simple, I am out of time to try and figure it out myself... And trust me, I dont like it.
The part I am working with has registers that store the calibration data for 8 sensor inputs. Each sensor has a 10-bit value for the calibration value that is split between 2, 8-bit registers. Does anyone have a easy way to combine 2, 8-bit values? I have included the part's register map to show what I am working with. From my own thinking I would shift the values to get what I wanted. But I dont know for sure.
Thanks
TC
[img][/img]
Sorry if this question is very simple, I am out of time to try and figure it out myself... And trust me, I dont like it.
The part I am working with has registers that store the calibration data for 8 sensor inputs. Each sensor has a 10-bit value for the calibration value that is split between 2, 8-bit registers. Does anyone have a easy way to combine 2, 8-bit values? I have included the part's register map to show what I am working with. From my own thinking I would shift the values to get what I wanted. But I dont know for sure.
Thanks
TC
[img][/img]
Comments
EDIT ... just saw the table. Weird layout! I would mask off the unwanted bits of the least-significant register (the mask pattern depends on which sensor is being used), shift the most significant byte left by 2 bits, then combine.
is this what you mean?
I am using SPIN
It is defiantly a weird layout, that is why I am getting overwhelmed on the best way to do it. I figured they would of put bits 7..0 in one register, and bits 8..9 in another. That would make my life a little easier.
That very well could be the reason. I just found out exactly what the registers are for. They are the value of the base capacitance.
quote from application note I just found
The note doesn't say anything about the 2 LSB in the other registers. I am assuming they are not needed. If it is the case, this is as easy as doing...
(8-bit value* 196) / 100
so ($E5 * 196) / 100) = 448 if I add a "." I would have 44.8
Thank you. I will have to try it out when I have the chance later on.
I find that when I'm under pressure, coding in the most obvious way is the cleanest -- as above. The table could be easily reconstructed from this code. BTW, I time tested it against another version (not so obvious) -- both run between 150-200us (with test code for read_reg); speed of the code above dependent on the channel that is selected.
Here's the not-so-obvious code:
I always like to read your code. You should teach people how to do it.
Enjoy!
Mike
At least now, I have a lot more time to figure out the best option. The next possible chance to show off the tech would be around December.
Thank you everyone for all your help.
Your column had more to do with my decision than any other consideration.
In fact, your column is pretty much the only reason I subscribe to the magazine as well. There is also DipTrace, and then DipTrace introduced me to Bay Area Circuits, and the list goes on. Your writings did all that.
I have used what I have learned from you and turned it into food on my table. You have given me a gift which, try as I may, I couldn't possibly repay.
If you ever find yourself feeling underappreciated, you aren't.
As honestly as I can say it, THANK YOU, and by all means, keep on Spinning (and winning) :-)
[/SAPPYCRAP]
I sincerely appreciate the kind comments, but we've kind of gone off track here with TC's thread. It is my great pleasure to write for N&V, and to share my experiences here. TC often posts interesting questions -- as in this thread -- and I enjoy developing ideas that may be useful because doing so helps me become a better programmer.
It took a second for that to register, and it made me chuckle.