Math questions
Archiver
Posts: 46,084
I am new to this stamp math. I am trying to calculate voltage through
a 0831 A/D so that I can read out to 2 decimals: (251 = 13.99volts)
I know that if I can get:
2,510,000/1794 I can get 1399
and can display it as:
serout LCD,n9600,[noparse][[/noparse]I,voltPos,dec X/100,".",dec2 X]
to get 13.99, but how does stamp math accomplish this without going
over 65535? I'm sure many people have built stamp volt meters but I
am having a ball trying to make my own. Any hardware and code for
other volt meters are appreciated. Thanks in advance. Dan
PS. Has anyone come up with PocketPC/WinCE Stamp software yet?
a 0831 A/D so that I can read out to 2 decimals: (251 = 13.99volts)
I know that if I can get:
2,510,000/1794 I can get 1399
and can display it as:
serout LCD,n9600,[noparse][[/noparse]I,voltPos,dec X/100,".",dec2 X]
to get 13.99, but how does stamp math accomplish this without going
over 65535? I'm sure many people have built stamp volt meters but I
am having a ball trying to make my own. Any hardware and code for
other volt meters are appreciated. Thanks in advance. Dan
PS. Has anyone come up with PocketPC/WinCE Stamp software yet?
Comments
> voltage through a 0831 A/D so that I can read out to
> 2 decimals: (251 = 13.99volts) I know that if I can get:
> 2,510,000/1794 I can get 1399
> and can display it as:
> serout LCD,n9600,[noparse][[/noparse]I,voltPos,dec X/100,".",dec2 X]
> to get 13.99, but how does stamp math accomplish this
> without going over 65535? I'm sure many people have
> built stamp volt meters but I am having a ball trying
> to make my own. Any hardware and code for other
> volt meters are appreciated. Thanks in advance. Dan
Hi Dan,
One way to compute this on the BS2 is:
X = X */ 1427
which gives X=1399 out for X=251 in.
*/ in effect approximates the fraction, 1399/251~=1427/256.
regards,
-- Tracy Allen
Electronically Monitored Ecosystems
http://www.emesystems.com/BS2index.htm <-- more BS2 math stuff.
You have to play around with factoring and approximations:
2510000/1794=(627500*2*2)/(897*2)
cancel one of the 2s
=(627500*2)/897
=(62750*10*2)/897
now approximate 897 almost=900
=(62750*10*2)/900
=(62750*10*2)/(90*10)
cancel the 10s
=(62750*2)/90
=(62750*2)/(45*2)
cancel the 2s
=62750/45 within 0.3% of correct, will fit stamp math limit.
So instead of (X*10000)/1794, use
(X*250)/45
Bruce Reynolds has a voltmeter app at his site using the 0831 with BS2 code
to read the A/D.
http://www.rentron.com/Volt-Meter.htm
Good luck,
Ray McArthur
> I know that if I can get:
> 2,510,000/1794 I can get 1399
> and can display it as:
> serout LCD,n9600,[noparse][[/noparse]I,voltPos,dec X/100,".",dec2 X]
> to get 13.99, but how does stamp math accomplish this without going
> over 65535? I'm sure many people have built stamp volt meters but I
> am having a ball trying to make my own. Any hardware and code for
> other volt meters are appreciated. Thanks in advance. Dan
I wasn't familiar with this operator... your approximation is within 0.01%!
One more thing I learned from this list.
Ray McArthur
> One way to compute this on the BS2 is:
>
> X = X */ 1427
>
> which gives X=1399 out for X=251 in.
>
> */ in effect approximates the fraction, 1399/251~=1427/256.
devised a very simple script to accomplish both the B2D and D2B conversions
for the BS2. The BS1 should be even simpler as I don't believe you need the
definition statements at the top of the attached script. However, you may
need to "mess" with the "debug" statements as the syntax is different
between the BS1 and BS2.