Stamp Math - Tracy Allen help
Porter
Posts: 9
Tracy I pulled this off an earler post dealing with Stamp integer math.
***
The LTC1298 uses the power supplyy as its reference, so 5 volts is divided into 4096 steps of 1.2207 volts. When you see a reading of 1580 steps, that means the input voltage is,
V = 1580 * 1.2207 = 1.929
On the Stamp, you do that with the */ operator
milllivolts = AD */ 3125
DEBUG DEC millivolts/10, ".", DEC1 millivolts
***
I'm testing a battery output with·a variable voltage·between 16.5 down to 10.5 volts through a voltge divider. (3.9k + 1.0K both 1%).· This give me an output that is feed to a·ltc1298 (like the above post)·only I'm referencing a 4.1 persision voltage regulator so I should get about 1mv per count but it's not quite that good.
Long story short help me understand how you got the number 3125 in the above set of equation and how the */ operator works.
Thanks in advance····
***
The LTC1298 uses the power supplyy as its reference, so 5 volts is divided into 4096 steps of 1.2207 volts. When you see a reading of 1580 steps, that means the input voltage is,
V = 1580 * 1.2207 = 1.929
On the Stamp, you do that with the */ operator
milllivolts = AD */ 3125
DEBUG DEC millivolts/10, ".", DEC1 millivolts
***
I'm testing a battery output with·a variable voltage·between 16.5 down to 10.5 volts through a voltge divider. (3.9k + 1.0K both 1%).· This give me an output that is feed to a·ltc1298 (like the above post)·only I'm referencing a 4.1 persision voltage regulator so I should get about 1mv per count but it's not quite that good.
Long story short help me understand how you got the number 3125 in the above set of equation and how the */ operator works.
Thanks in advance····
Comments
3.14159 x 256 = 804 (remember the Stamp only uses integers)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Here is the fractional approximation as you might write it in 6th grade math class: 3125/256 = 12207/1000 = 1.2207 * 10.
Actually, 3125/256 is 12.20703125, but that's close enough, don't you think? The Stamp works this internally by multiplying by 3125 and then shifting the result right by 8 bits (which is the same as dividing by 256). Computers are very fast at shifting bits, whereas long division in general is quite time consuming.
If you feed a known voltage into your circuit, you will get a value from the LTC1298. Say you feed in known 10.00 volts, and the ADC count output read by the Stamp happens to be 2041 counts (out of 4096).
You want to display the number 10.00. Here is the math: 1000 = multiplier/256 * 2041. Solve for multiplier. multiplier = 1000 * 256 / 2041 = 125.43, which you round off to 125, or to 1254 or 12543.
Then from the ADC, 2041 */ 125 = 996 close, but not too great, or 2041 */ 1254 = 9997. Or 2041 */ 12543 = 10001.
You see how the precision improves as you use more digits? The last one gives you plenty to work with to round off very accurately.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Maybe you don't need the precision. 9997 rounds off to 10.0 volts:
There _are_ a couple of ways to get a little more precision, if you need it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Post Edited (Tracy Allen) : 2/21/2006 7:35:20 PM GMT