> On Tue, 28 Sep 1999 11:43:13 +0100 Michael Rigby-Jones
> <
.....mrjonesKILLspam
@spam@NORTELNETWORKS.COM> writes:
> >These are 8 bit values right? This is pretty simple, you need to
> >steal a
> >multiply routine from somewhere that does 8bit * 8bit with a 16 bit
> >result.
> >The Microchip routine is attached (no flames please...it's tiny) The
> >idea
> >is:
> >
> >C = (A*B)/256
> >
> >The 256 number is handy as no division is actually needed, you just
> >take the
> >most significant byte of the 16 bit result.
> >
> >Hope this is of some use.
> >
> >
> >Mike Rigby-Jones
> >
>
> I'm not sure if this is what the original poster wanted, but IF it is,
> it's similar to some code I wrote to have a grand master control in a
> lighting control system control the outputs of the A/D values from the
> original channel pots.
> There we have individual channel pots giving A/D values from 0 to 255
> (0x00 to 0xff). The master pot gives the same result. We want the
> master pot to scale the channel pots. Turns out simple enough...
>
> Out = Chan * Master/255
>
> Note that it's divided by 255, not 256. Otherwise, if both channel an
d
> master were 255, we'd get 254 as an output, when we want 255.
> Dividing by 255 is certainly not as easy as dividing by 256 (throwing
> away the bottom 8 bits). Perhaps with rounding that would work (divide
> by 256 and if bit 7 of the remainder is 1, increment the result). What I
> did was to check bit 7 of the master pot value. If it's 1, I added 1 to
> the result of the divide by 256. Works great!