Shop OBEX P1 Docs P2 Docs Learn Events
Scaling values — Parallax Forums

Scaling values

blueiceblueice Posts: 12
edited 2005-01-20 14:42 in BASIC Stamp
Hello,
I'm getting a value varying from 0 to 180...and i need to get it to correspond to 1100 to 120...
0 must correspond to 1100...

according to this link:
http://forums.parallax.com/showthread.php?p=519918
Jon Williams said...
Since you're getting 0 - 255 now (I don't have a part to test so I will have to go with your assertion -- though it doesn't match the data sheet), you can use a simple equation to get your desired output range from the pot's span.

You want 0 - 255 to become 330 to 1230 ... so try this mx+b equation:

adc = adc */ $388 + 330

How does it work? Well, your output range has a span of 900, so you divide that by 255 (max pot value)·to get the slope (3.5294 -- the 'm' in mx + b). We can use the */ operator to multiply by fractions (in increments of 1/256). To use */ you take your fractional value (3.5294) and multiply it by 256; you 903.5 -- round up to 904.· I like to convert to HEX as I can see the whole part in the upper byte, the fractional part in the lower byte.· 904 in hex is $388.· Of course, we have to add the minimum value; then we're done.


Using the above method i can get 0 to 180 to correspond to 120 -1100,but how do i do it the opposite way
ie 0-180 to 1100 to 120

Thank you for your time

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
**·ice**

Gerard Sequeira
Machinegrid.com·:: Robots at Work!!
Parallel Port Tutorials,
Autonomous Robots,
PIC16F84a Temperature Controller
·

Comments

  • steve_bsteve_b Posts: 1,563
    edited 2005-01-20 12:03
    I've run in to this in programming and couldn't think of a nice way to do it without a lookup table.

    That's not to say one of the guys doesn't have a good idea.

    BUT, what type of sensor is it?· Might it be possible to rearrange a circuit (if it's a passive type of device?!).

    You might try an inverting op-amp with a DC boost at the end?!



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-20 14:35
    It's easy: just subtract your original input from 180 before converting to the larger range.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • steve_bsteve_b Posts: 1,563
    edited 2005-01-20 14:38
    Hi Jon,

    How would the stamp handle the sign....or does it matter?· 180 - 0 = -180.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-20 14:39
    You misread my post -- I said subtract the input FROM 180. The value going to his scaling equation will never be negative.

    The new equation becomes:· scaleVal = ((180 - inputVal) */ $571) + 120

    The equation assumes that inputVal never exceeds 180.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA


    Post Edited (Jon Williams) : 1/20/2005 2:42:34 PM GMT
  • steve_bsteve_b Posts: 1,563
    edited 2005-01-20 14:42
    haha...sorry!

    Apparently I pressed too hard when I shaved my head this morning...must've taken some brain cells with it!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·

    Steve
    http://members.rogers.com/steve.brady
    "Inside each and every one of us is our one, true authentic swing. Something we was born with. Something that's ours and ours alone. Something that can't be learned... something that's got to be remembered."
Sign In or Register to comment.