Hi Magnus,
Using the "**" and "*/" operators you can do it a little faster. The "**" operator does an "invisible" division by 65536 and the "*/" does the same with 256. It's basically the same thing as Melanie showed you but she used a denominator of 1000. Since WORD(16bits = 65536) is the biggest number allowed by PBP, we can use "**" for constants ranging from 1 to 0 (65535 / 65536). "*/" gives a range from 256 to 0 (65535 / 256).
Applying this to your equation t=(clk*0.27)*3.6.
0,27 * 65536 = 17694,72. Round off to 17695.
3,6 * 256 = 921,6. Round off to 922.
Now the equation can be written as......
t=clk ** 17695 */ 922
Not much faster since we're still using two multiplications, we also have some rounding off errors. We should ofcourse do 0,27*3,6 before (just like Mel did). 0,27 * 3,6 = 0,972 this is less than 1, we should use "**". The magic number will be 0,972 * 65536 = 63701. The equation will now look like......
t=clk ** 63701
As you can see we have now done away with the DIV32 completely. Should be faster......lots......
Tacey Allen has a nice page with loads of goodies.....
http://www.emesys.com/BS2index.htm
/Ingvar
Bookmarks