Shop OBEX P1 Docs P2 Docs Learn Events
Can the debug window ? — Parallax Forums

Can the debug window ?

ArchiverArchiver Posts: 46,084
edited 2001-03-26 19:38 in General Discussion
Hi, I was wondering how to get the debug window to receive floating or
at least decimals with their fractional part to at least tenth point?

example; if 16/12 = 1.33......

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-03-26 03:55
    That depends on what you are doing. Suppose you read an A/D count that is 8
    bits on a 5V reference. That is about .0195V per count, right? So suppose
    instead of computing:

    v = count * .0195 (which we can't do), we write:

    v = count * 195 (which we can do)

    Now the units are actually in .001V so for 4.5V you'd get about 230 counts.
    So v = 230 * 195 = 44850 (ok for 16 bits).

    You want to .1V, so we can round like this:

    v = (v+500)/1000 { that will give us 45)

    So how do you display this properly? Easy:

    Debug dec v/10, ".", v//10

    This works out nicely because it is only one digit. More digits takes more
    work. Why? What if you didn't round, but instead wrote:

    dec v/10000, ".", v//10000

    That would work in this case, giving you 4.4850. But what if the answer were
    40500? Then you'd get 4.500 instead of 4.0500. Not insurmountable, but
    something you have to watch for.

    Another answer is to use a PAK-I or PAK-II to do real 32-bit floating point
    math with the Stamp. See http://www.al-williams.com/awce/pak1.htm and
    http://www.al-williams.com/awce/doclib.htm

    Regards,

    Al Williams
    AWC
    * Expand your Stamp I/O: http://www.al-williams.com/awce/pak3.htm



    >
    Original Message
    > From: SAN CHRISTOPHER POISSON [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=Kq5pwI22dsSg_CDGNGIXiXHiNtHjhBE73KWluzsM6SB-Orhn3I-1_GkYjBSHm8M4ZHAWd1W_0z4]sp71@s...[/url
    > Sent: Sunday, March 25, 2001 8:40 PM
    > To: basicstamps@yahoogroups.com
    > Subject: [noparse][[/noparse]basicstamps] Can the debug window ?
    >
    >
    > Hi, I was wondering how to get the debug window to receive floating or
    > at least decimals with their fractional part to at least tenth point?
    >
    > example; if 16/12 = 1.33......
    >
    >
    >
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-03-26 04:30
    Bloody hell Al, you are good !!!
    Chris
    Original Message
    From: Al Williams <alw@a...>
    To: <basicstamps@yahoogroups.com>
    Sent: Monday, March 26, 2001 10:55 AM
    Subject: RE: [noparse][[/noparse]basicstamps] Can the debug window ?


    > That depends on what you are doing. Suppose you read an A/D count that is
    8
    > bits on a 5V reference. That is about .0195V per count, right? So suppose
    > instead of computing:
    >
    > v = count * .0195 (which we can't do), we write:
    >
    > v = count * 195 (which we can do)
    >
    > Now the units are actually in .001V so for 4.5V you'd get about 230
    counts.
    > So v = 230 * 195 = 44850 (ok for 16 bits).
    >
    > You want to .1V, so we can round like this:
    >
    > v = (v+500)/1000 { that will give us 45)
    >
    > So how do you display this properly? Easy:
    >
    > Debug dec v/10, ".", v//10
    >
    > This works out nicely because it is only one digit. More digits takes more
    > work. Why? What if you didn't round, but instead wrote:
    >
    > dec v/10000, ".", v//10000
    >
    > That would work in this case, giving you 4.4850. But what if the answer
    were
    > 40500? Then you'd get 4.500 instead of 4.0500. Not insurmountable, but
    > something you have to watch for.
    >
    > Another answer is to use a PAK-I or PAK-II to do real 32-bit floating
    point
    > math with the Stamp. See http://www.al-williams.com/awce/pak1.htm and
    > http://www.al-williams.com/awce/doclib.htm
    >
    > Regards,
    >
    > Al Williams
    > AWC
    > * Expand your Stamp I/O: http://www.al-williams.com/awce/pak3.htm
    >
    >
    >
    > >
    Original Message
    > > From: SAN CHRISTOPHER POISSON [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=_17LzDotaG_dXC6I3Ay4oZhsHROeTpPpJkVShTDPwWtcgFwEW97krYnXeDBEZxNiVMSaENK-oQ]sp71@s...[/url
    > > Sent: Sunday, March 25, 2001 8:40 PM
    > > To: basicstamps@yahoogroups.com
    > > Subject: [noparse][[/noparse]basicstamps] Can the debug window ?
    > >
    > >
    > > Hi, I was wondering how to get the debug window to receive floating or
    > > at least decimals with their fractional part to at least tenth point?
    > >
    > > example; if 16/12 = 1.33......
    > >
    > >
    > >
    > >
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    http://docs.yahoo.com/info/terms/
    > >
    >
    >
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
    >
    >
  • ArchiverArchiver Posts: 46,084
    edited 2001-03-26 19:38
    Al Williams

    >dec v/10000, ".", v//10000
    >
    >That would work in this case, giving you 4.4850. But what if the answer were
    >40500? Then you'd get 4.500 instead of 4.0500. Not insurmountable, but
    >something you have to watch for.

    Or use

    debug dec v/10000,".",dec4 v

    The decN modifier always picks the N least significant digits.

    I have a little writeup on this subject (including negative numbers)
    at this URL:


    http://www.emesys.com/BS2math4.htm#Displaydecimal

    -- Tracy Allen
Sign In or Register to comment.