Conversion to degrees help
Hi All,
I'm trying to convert a 10bit or 12bit word "position" to 0-360 degrees with 2 or 3 digits after the decimal point
I have this routine working for conversion to degrees without decimal point
anyone who can help me with this mathematics:
Scale = 1024 (might also be 4098 for 12bit)
dummy = position * 64
dummy = dummy *360
result_64 = DIV32 scale
degrees = result_64/64
thanks
Don't forget the "*/" and "**" operators.
OK, You want to scale a number by a constant factor. This is pretty easy using the "*/" and "**" operators. This way you can save some time since the calculations are pretty easy to do for the processor, no divisions only one multiplication. You can learn more about them here http://www.emesystems.com/BS2math1.htm . A short way of describing them is that "*/" makes an invisible division by 256 and "**" divides by 65536.
Older versions(pre 2.50) can only use WORD sized(16 bits) variables, meaning your result must be 65535 or less.
1024 to 360. Degrees = position */ 90 or Degrees = position ** 23040
1024 to 3600. Degrees = position */ 900
1024 to 36000. Degrees = position */ 9000
4096 to 360. Degrees = position ** 5760
4096 to 3600. Degrees = position */ 225 or Degrees = position ** 57600
4096 to 36000. Degrees = position */ 2250
If you have PBP2.50 you can have your result bigger than 16 bits. 360000 is then possible.
1024 to 360000. Degrees = position */ 90000
4096 to 360000. Degrees = position */ 22500
/Ingvar