Division Solution
Michael Niece
Posts: 2
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
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
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
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.
·