Shop OBEX P1 Docs P2 Docs Learn Events
I forget — Parallax Forums

I forget

NewzedNewzed Posts: 2,503
edited 2008-01-06 21:29 in BASIC Stamp
I forget - what is the procedure for using 65535 to improve the resolution you get with the· */ operator?

Sid

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Yesterday is history, tomorrow is a mystery, and today is a gift.

That is why they call it the present.

Don't have VGA?
Newzed@aol.com
·

Comments

  • Tracy AllenTracy Allen Posts: 6,667
    edited 2008-01-05 22:52
    Hi Sid, Happy new year!

    You can use ** instead of */ to improve the resolution, because the implied denominator is one part in 65536 instead of one part in 256. Say you want to multiply a variable x times 3.141593.

    Using */ you would use y = x */ 804, because 804/256 is the closest approximation with that denominator of 2^8. Suppose x=10000. Then
    y = x */ 804
    will equal 31406, which is 10 less than the most correct answer, which is 31416. You could use
    y = x */ 805.
    which equals 31445, 29 units too high.

    With ** instead, you would use, y = (x * 3) + (x ** 9280). That is because 9280/65536 is the closest approximation to 0.141593 with the 2^16 denominator. Again with x=10000,
    y = (x * 3) + (x ** 9280)
    comes out to 31416, as desired. It will be at most one unit off of the correct answer due to roundoff.

    Sid, does that answer your question?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • NewzedNewzed Posts: 2,503
    edited 2008-01-05 23:00
    Thanks a lot, Tracy.· Could you simplify that a bit for me?· I have my ADC reading the wiper of a pot across 5V, and I get 2317.· I want to modify the raw reading of 2317 so that my Stamp displays 497.· How would I write that - I··think I understand but I want to be sure.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • NewzedNewzed Posts: 2,503
    edited 2008-01-05 23:13
    Never mind, Tracy - I've got it.· Thanks a million.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
  • Tracy AllenTracy Allen Posts: 6,667
    edited 2008-01-06 21:01
    Yes,
    y = x ** 14058
    


    will give y=497 when x = 2317.
    Is that what you have?
    Note that it could be better, as that calculation is losing significant figures. You could also do
    y = x ** 28116 * 5
    DEBUG DEC y/10, ".", DEC1 y
    


    and that would print out 497.0 and progress by units of 0.5 as x changes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • NewzedNewzed Posts: 2,503
    edited 2008-01-06 21:29
    Tracy, that works even better!· Thanks again.

    Sid

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Yesterday is history, tomorrow is a mystery, and today is a gift.

    That is why they call it the present.

    Don't have VGA?
    Newzed@aol.com
    ·
Sign In or Register to comment.