On Fri, 1 Feb 2002, Edson Brusque wrote: > Hello Harold, > > > See http://www.piclist.org/techref/microchip/math/scale/index.htm > > Good stuff there! > > as you also work with lighting, you got what I need. :) > > But it seens to me that those routines aren't exactly what I need. > > I have two values let's say that one is the CHANNEL and other is the > MASTER as in the lighting consoles. Both values can be anywhere from zero to > 255 and the result is 8 bits also, from 0-255. > > The expression "RESULT = (CHANNEL * MASTER) / 255" is perfect. The > problem is that the execution time is very long. > > Some examples : > X Y X*Y /255 /256 > 0 255 0 0 0 > 48 47 2256 8 8 > 200 199 39800 156 155 > 210 210 44100 172 172 > 220 221 48620 190 189 > 230 230 52900 207 206 > 255 255 65025 255 254 > > If someone tell me a very fast way to make this I'll be eternally > grateful. note 65025 = 0xfe01 Call that res_hi:res_lo follow your 8X8 multiplication routine with: btfsc res_hi_,7 incf res_hi,F and you'll be very close. There may be a few instances where this fails... This is the hint I mentioned in the other post: 1/255 = 1/256 + 1/256^2 + 1/256^3 + ... If you want to have more accuracy than what the two instructions provide you could do this: movf res_lo,w addwf res_hi,w andlw 0x80 skpc skpz incf res_hi,f That should be pretty accurate. Scott -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads