Shop OBEX P1 Docs P2 Docs Learn Events
Division Solution — Parallax Forums

Division Solution

Michael NieceMichael Niece Posts: 2
edited 2006-10-14 02:25 in BASIC Stamp
Okay, I've read through several pages people have linked to, and read the manuals on overcoming 32-bit division.· But somehow my brain just won't accept the logic.· So could someone help break down the formula/result for this?· My desired·answer is a PWM number, and it could range from -1024 to 1024.· I have a formula for getting that number (based on an input number that represents a pulse from an R/C receiver).

PWM = ((PulseWidthus / 2.44us) - 615) * 6

The us is microseconds.· PulseWidthus is the microseconds for the pulse width.· For servos, that's 1500 when it's not moving.· Logically, the result number for a non-moving servo would generate a PWM of zero (or at least·close to it).· I've tried breaking down the formula so it can be done within 16 bits but I can't seem to get the numbers working the right way.· I know what·the range of servo pulses are, and what the resulting PWM should be:

Servo pulses: 1000us·to 2000us
Resulting PWM: -1024·to 1024

-Michael

Comments

  • BeanBean Posts: 8,129
    edited 2006-10-13 13:58
    Michael,
    Your formula would convert to:

    PWM = PulseWidthus * 2.459016393 - 3690

    To do the "* 2.45916393" part you need to use the */ operator. You take your value * 256; then round it; they use */.

    So PWM = (PulseWidthus */ 630) - 3690

    Or you could do better by using ** here you take your value * 65536 (but it must be less than 1) so we can do...

    PWM = (PulseWidthuS + PulseWidthus + PulseWidthus * 0.459016363) -3690

    PWM = (PulseWidthus + PulseWidthus + PulseWidthus ** 30082) -3690

    I hope this helps,
    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    Don't mistake experience for intelligence. And vis-vera.
    ·
  • Michael NieceMichael Niece Posts: 2
    edited 2006-10-13 17:50
    Thanks for the quick reply.· But where did you get the 2.459016393 and 3690 numbers from?· I don't understand how you came to those numbers.· I don't mean to be difficult but once I see the flow of how the numbers should be prepared it will click.· Thanks.

    -Michael
  • BeanBean Posts: 8,129
    edited 2006-10-14 02:25
    I don't remember what the names of the transforms, but here is what I did...

    PWM = ((PulseWidthus / 2.44us) - 615) * 6

    PWM=((PulseWidthus / 2.44) * 6) - (615 * 6)

    PWM=((PulseWidthus / 2.44) * 6 - 3690

    PWM=(PulseWidth / (2.44 / 6)) - 3690

    PWM=PulseWidthus / 0.4066666 - 3690

    PWM=PulseWidth * (1 / 0.4066666) - 3690

    PWM=PulseWidthus * 2.459016393 - 3690

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    Don't mistake experience for intelligence. And vis-vera.
    ·
Sign In or Register to comment.