adding fractions and decimals
Archiver
Posts: 46,084
Hi all,
I would like to know how to add fractions and decimals in BASIC Stamp
programs. anyone have any ideas?
I would like to know how to add fractions and decimals in BASIC Stamp
programs. anyone have any ideas?
Comments
> I would like to know how to add fractions and decimals in BASIC Stamp
> programs. anyone have any ideas?
When it comes to Math + Stamps - you can't beat Tracy Allens' web site:
http://www.emesystems.com/BS2index.htm
Regards,
-Bruce
webmaster@r...
http://www.rentron.com
information. In fact, I've burned out pages off the printer from that
site. However, I wasn't able to find any information on adding
fractions or decimal values.
--- In basicstamps@y..., <webmaster@r...> wrote:
> > Hi all,
> > I would like to know how to add fractions and decimals in BASIC
Stamp
> > programs. anyone have any ideas?
>
> When it comes to Math + Stamps - you can't beat Tracy Allens' web
site:
> http://www.emesystems.com/BS2index.htm
>
> Regards,
>
> -Bruce
> webmaster@r...
> http://www.rentron.com
Suppose you have a number, say fron an ADC, that is 746. You know 746 is
really 74.6 degrees but Stamp won't handle decimels.
So you write
AD1 = 746
temp = AD1
temp = AD1/10 'this gives you 76 degrees but you've lost the decimal
Then you write
serout 0, N9600, [noparse][[/noparse]dec temp,".", dec1 AD1,cr]
Screen will display 74.6
OK??
Sid
1) Scale your numbers to a fixed decimal point. For example, instead of
storing 0-32767, you could store from 0 to 3276.7.
2) Work with rational numbers (pi is 22/7 so pi*r = 22*r/7).
3) If you have a constant denominator, you can imply it instead of
storing it. For example, suppose you have a sensor that pulses on every
1/4 of a rotation. You could count "quarters" and then when you get 4
"quarters", zero the quarter counter and increment the unit counter.
4) Get a PAK-I, PAK-II, or PAK-IX.
http://www.al-williams.com/awce/pak1.htm
These work very well with the Stamps and give you floating point
calculations, extra I/O, memory, and even A/D (with the PAK-IX).
Regards,
Al Williams
AWC
* Floating point A/D
http://www.al-williams.com/awce/pak9.htm
>
Original Message
> From: rpsu279@y... [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=upVjSIlKV5HmkeM1dBiOoxSQqulNVAXYOFyNjUXeZ-fwbNNef5AYc1OFwDSGIbpN-ElyJC94KK9z2nA]rpsu279@y...[/url
> Sent: Monday, November 19, 2001 10:49 AM
> To: basicstamps@yahoogroups.com
> Subject: [noparse][[/noparse]basicstamps] adding fractions and decimals
>
>
> Hi all,
> I would like to know how to add fractions and decimals in BASIC Stamp
> programs. anyone have any ideas?
>
>
> To UNSUBSCRIBE, just send mail to:
> basicstamps-unsubscribe@yahoogroups.com
> from the same email address that you subscribed. Text in the
> Subject and Body of the message will be ignored.
>
>
> Your use of Yahoo! Groups is subject to
> http://docs.yahoo.com/info/terms/
>
>information. In fact, I've burned out pages off the printer from that
>site. However, I wasn't able to find any information on adding
>fractions or decimal values.
> > Hi all,
> > I would like to know how to add fractions and decimals in BASIC
> > Stamp programs. anyone have any ideas?
> When it comes to Math + Stamps - you can't beat Tracy Allens' web
> site: http://www.emesystems.com/BS2index.htm
Hi RP,
Please give an example of what you want to do, with typical numerical
values, or the range of numerical values you expect. With the
integer math on the BS2, you pretty much have build the solutions to
problems one at a time. The stuff on my web site is just a tool kit.
-- best regards
Tracy Allen
electronically monitored ecosystems
http://www.emesystems.com
mailto:tracy@e...
I was trying to measure the pulse width on a BS2SX and trying to get
it in milliseconds.
' pLowT = 0
'redo:
' PULSIN 4, 0, pLow
' IF NOT pLow = 0 THEN complete
' pLowT = pLowT + 52 + 428/1000 '52.428 ms is the limit
' GOTO redo 'get a total time pulse is low
'complete:
' pLowT = pLowT + pLow * 8/10 * 1000
'BS2SX units are in 0.8 uS. multiply by 1000 to get ms.
' IF pLowT >= 0 and pLowT <= 350 THEN Bit_low
' IF pLowT > 350 and pLowT <=650 THEN Bit_high
' IF pLowT > 650 and pLowT <1000 THEN transition
I could change the line after complete to pLowT = pLowT + (pLow * 800)
but how about the statement of adding the 52.485 ms to the variable?
Thanks,
RP
--- In basicstamps@y..., Tracy Allen <tracy@e...> wrote:
> >There is no doubt that Tracy Allen's site is a great source of
> >information. In fact, I've burned out pages off the printer from
that
> >site. However, I wasn't able to find any information on adding
> >fractions or decimal values.
> > > Hi all,
> > > I would like to know how to add fractions and decimals in BASIC
> > > Stamp programs. anyone have any ideas?
> > When it comes to Math + Stamps - you can't beat Tracy Allens' web
> > site: http://www.emesystems.com/BS2index.htm
>
> Hi RP,
>
> Please give an example of what you want to do, with typical
numerical
> values, or the range of numerical values you expect. With the
> integer math on the BS2, you pretty much have build the solutions
to
> problems one at a time. The stuff on my web site is just a tool
kit.
>
> -- best regards
> Tracy Allen
> electronically monitored ecosystems
> http://www.emesystems.com
> mailto:tracy@e...
>I was trying to measure the pulse width on a BS2SX and trying to get
>it in milliseconds.
>
>' pLowT = 0
>'redo:
>' PULSIN 4, 0, pLow
>' IF NOT pLow = 0 THEN complete
>' pLowT = pLowT + 52 + 428/1000 '52.428 ms is the limit
>' GOTO redo 'get a total time pulse is low
>'complete:
>' pLowT = pLowT + pLow * 8/10 * 1000
> 'BS2SX units are in 0.8 uS. multiply by 1000 to get ms.
>' IF pLowT >= 0 and pLowT <= 350 THEN Bit_low
>' IF pLowT > 350 and pLowT <=650 THEN Bit_high
>' IF pLowT > 650 and pLowT <1000 THEN transition
>
>I could change the line after complete to pLowT = pLowT + (pLow * 800)
>but how about the statement of adding the 52.485 ms to the variable?
>
>Thanks,
>RP
> > Hi RP,
> >
> > Please give an example of what you want to do, with typical numerical
> > values, or the range of numerical values you expect. With the
> > integer math on the BS2, you pretty much have build the solutions to
> > problems one at a time. The stuff on my web site is just a tool kit.
>Hi,
>I am expecting pulse width values of 0.2 s, 0.8 s, or
>0.5 s. pLowT is the defined as the Total pulse width.
>pLow is the variable where the pulse length will be
>stored. If it gets 0, that means the limit was
>exceeded. Since I am working with a BS2SX, I have to
>add the limit before looping back. I hope this helps.
>
>RP
If I understand what you are trying to accomplish, there is a problem
with the PBASIC. As you know, the pulsin command cannot measure
pulse widths longer than 52.428 milliseconds (BS2SX). I appears that
your program is attempting to measure a long pulse width by looping
back in increments of 52.428 ms. But the pulsin command requires
both a starting edge and an ending edge. You cannot "accumulate" by
coming in the the middle of a long pulse. You might be able to get
this technique to work by using the RCtime command, which only needs
the ending edge.
waituntillow: ' hold here for start
if in4 then waituntillow
redo:
RCtime 4,0,pLow ' exits command when p4 goes high
' or 52.428 ms, whichever first
Another approach is to use a simple programmed timer loop. Examples at:
http://www.emesys.com/BS2speed.htm#longpulse
On the BS2SX, the resolution can be about than 0.35 milliseconds, and
cover a range from 0 to 22 seconds.
-- best regards
Tracy Allen
electronically monitored ecosystems
http://www.emesystems.com
mailto:tracy@e...