Exact match. Not showing close matches.
PICList
Thread
'[PIC]: Scaling numbers'
2001\11\24@144018
by
Josh Koffman

Hi all. Just as a quick aside, I hate the American holidays...the list
slows down too much. I hate it when people go tend to their "real
lives".
Anyway, I have a question about scaling. Basically what I want to do is
to have a few (832 maybe) registers with 8 bit values in them. Then,
based on another 8 bit value I want to scale them. Basically, the second
register becomes a percentage multiplication factor. So if I have a
value of d'204' in the first register, and a value of d'128' in the
second (50%), after the operation I want a result of d'102' (half of the
original value). It can be in a second register. At first I though of
just using multiplication routines, but I can't figure how to multiply
by less than 1 (ie 0.5). I had a flash that maybe this could all be
accomplished by shifting bits, but I don't know how. Any pointers to
info would be great!
Thanks,
Josh Koffman

A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
Douglas Adams

http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
2001\11\24@153512
by
jim
Yep, just shift right one place and you effectivley divide by two.
Regards,
` Jim
{Original Message removed}
2001\11\24@155626
by
Dave Mumert
Hi
Basically you want to multiply your number by 102 and then divide it by 256.
y = (x * % byte)/256
An 8 bit by 8 bit multiply would give you a 16 bit answer. You can divide
by 256 by just using the high byte and discarding the low byte.
204 * 128 == 26112 (6600 Hex) 66 hex is 102 decimal.
MChip has some multiply routines on their site.
Dave
{Original Message removed}
2001\11\24@161914
by
Jinx
> > just using multiplication routines, but I can't figure how to multiply
> > by less than 1 (ie 0.5). I had a flash that maybe this could all be
> > accomplished by shifting bits, but I don't know how. Any pointers to
> > info would be great!
I can't get through to the site (?!?) at the moment but I'm pretty sure
percentages are dealt with in the maths section of http://www.piclist.com
I know it's come up a couple of times in the mail group and think
routines were posted
Basically what you do is not think of the multiplier as a fraction. Do
the multiplication anyway (to get a 16 or 24 bit result), then calculate
how many significant places you want to keep. Use shifts or base10
divisions to get the result into the correct decade for the true answer

http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
2001\11\24@182846
by
Scott Dattalo

On Sat, 24 Nov 2001, Josh Koffman wrote:
> Hi all. Just as a quick aside, I hate the American holidays...the list
> slows down too much. I hate it when people go tend to their "real
> lives".
>
> Anyway, I have a question about scaling. Basically what I want to do is
> to have a few (832 maybe) registers with 8 bit values in them. Then,
> based on another 8 bit value I want to scale them. Basically, the second
> register becomes a percentage multiplication factor. So if I have a
> value of d'204' in the first register, and a value of d'128' in the
> second (50%), after the operation I want a result of d'102' (half of the
> original value). It can be in a second register. At first I though of
> just using multiplication routines, but I can't figure how to multiply
> by less than 1 (ie 0.5). I had a flash that maybe this could all be
> accomplished by shifting bits, but I don't know how. Any pointers to
> info would be great!
In general, if you wish to multiply by a "fraction" you'll need to convert
it into a format suitable for the PIC. Suppose your fraction is:
f = X/Y
and you want to multiply some register by f. If you only are interested in
8bits of precision then you can convert f into a fraction of 256:
X b
 = 
Y 256
or,
b = 256 * X / Y
Note that b is number between 0 and 255 and can be fed into any 8bit
multiplication routine. After the multiplication, you can divide the
product by 256 and you'll have your answer. Of course, "division" by 256
is trivial.
Often time you know before hand the value of Y. Thus you can precompute
the 256/Y factor. However, if not done carefully you can inadvertantly
throw away precision. For example, if Y is 10 then 256/Y is 25.6. What do
you do with that .6? Well it depends...
If you want to see an optimized "scaling" routine used to convert numbers
into percentages, then look here:
http://www.piclist.com/techref/microchip/math/scale/8bxpercent.htm
Scott

http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
2001\11\24@213257
by
Kathy Quinlan
Josh,
When you have finished the lighting desk ( I am guessing this is what you
are doing from the questions) please post it, as lots of designs these days
are for PC controlled, and some of us love faders still :o)
Basically what you do is multiply the two numbers, which gives a 17 bit
result and then use the top 8 bits, if you want to make life easier, just
subtract 1 from one of the numbers and multiply, then it will always be a 16
bit result.
Hope this helps,
Regards,
Kat.
____________________________________________________________________________
/"\ ASCII Ribbon Campaign  K.A.Q. Electronics
\ /  NO HTML/RTF in email  Software and Electronic Engineering
X  NO Word docs in email  Perth Western Australia
/ \  Ph +61 419 923 731
____________________________________________________________________________
{Original Message removed}
2001\11\26@190326
by
Andrew Warren
Kathy Quinlan <spam_OUTPICLISTTakeThisOuTmitvma.mit.edu> wrote:
> Basically what you do is multiply the two [8bit] numbers, which
> gives a 17 bit result and then use the top 8 bits, if you want to
> make life easier, just subtract 1 from one of the numbers and
> multiply, then it will always be a 16 bit result.
Kat:
There's no need to subtract 1 from either number before the
multiplication; the product of two 8bit numbers ALWAYS fits in 16
bits.
Andy
=== Andrew Warren  .....aiwKILLspam@spam@cypress.com
=== Principal Design Engineer
=== Cypress Semiconductor Corporation
===
=== Opinions expressed above do not
=== necessarily represent those of
=== Cypress Semiconductor Corporation

http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservKILLspammitvma.mit.edu with SET PICList DIGEST in the body
2001\11\26@202127
by
Kathy Quinlan
brain fart
sorry guys, max number for 8 bits is 255 not 256 (should stop doing all
nighters or drink more coffee)
Regards,
Kat.
____________________________________________________________________________
/"\ ASCII Ribbon Campaign  K.A.Q. Electronics
\ /  NO HTML/RTF in email  Software and Electronic Engineering
X  NO Word docs in email  Perth Western Australia
/ \  Ph +61 419 923 731
____________________________________________________________________________
{Original Message removed}
More... (looser matching)
 Last day of these posts
 In 2001
, 2002 only
 Today
 New search...