PDA

View Full Version : Number conversion to support PWM period specification


Brian Huff
09-05-05, 01:35 AM
I need some help on understanding how to convert values in between various number formats. First I will try to explain what I am trying to do and hopefully that will make the rest of this message easier to understand.

I want to scale a PWM value by multiplying it by some factor. For example lets say I have two motors diving each side of a skid steer device. The mechanical and sensor systems on each side of the vehicle do not match. For the same commanded PWM pulse width value the left track
of the vehicle moves faster than the right track. I want to scale-up the PWM pulse width value I send to the right motor in an effort to keep up with the left motor. The factor is going to have to be a real value (i.e. 1.237). I want to multiply this factor value by the DECIMAL PWM pulse width commanded value, say 40000. I am assuming that the motion control commands included in IsoMax versions 0.65 and later use a 16-bit input value to specify the PWM pulse width commanded value. I can use the S>F operators to get the 40000 into the floating point stack. I can then use the F* operator to multiply this value by 1.237E0. What I have not been able to do is convert the Floating Point value back into a form that can be used as an input to the "PWMA0 PWM-UPDATE" function. I think I am missing something pretty basic here. Any help is welcome.

Brian Huff

ngkdc
09-05-05, 08:15 AM
F>D
DROP

works for me

RMDumse
09-05-05, 10:00 AM
Yes, that's right. F>D converts a 32-bit float to a 32-bit integer, and the DROP converts the double 32-bit integer to a single 16-bit integer. As long as the "information" in a a single 16-bit integer, there's no loss. However, if you have a large decimal component (digits to the right of the decimal point) you will loose some precision there. But with 16-bits to encode the PWM value, there's plenty of precision for motion control.