A discussion group for the PICMicro microcontroller. Also called the Microchip PIC, this list is dedicated to the use and abuse of this fine, simple, microcontroller. Close to topic posts are welcome, ie. general electronics.
|
O.K. But remember: Im using the PIC16F84A.. Best Regards > Date: Fri, 30 Jul 2004 16:14:33 -0000 > From: "Phil" <> > Subject: Re: RE. RE. RE. etc. MAKING SOFT COUNTERS > > multiply and divide by 10 is trivial with BCD. Mul/div by 2 is > pretty simple. Mul by 5 is mul 10/div 2. Div 5 is mul 2/div 10. > > I still don't get why there is an undercurrent of "BCD is bad". For > some applications like this one, its the perfect data structure. -- Germán Hernández C. |
|
|
|
O.K. But remember: Im using the PIC16F84A.. Best Regards > Date: Fri, 30 Jul 2004 16:14:33 -0000 > From: "Phil" <> > Subject: Re: RE. RE. RE. etc. MAKING SOFT COUNTERS > > multiply and divide by 10 is trivial with BCD. Mul/div by 2 is > pretty simple. Mul by 5 is mul 10/div 2. Div 5 is mul 2/div 10. > > I still don't get why there is an undercurrent of "BCD is bad". For > some applications like this one, its the perfect data structure. -- Germán Hernández C. |
|
|
|
I didn't forget - my point is still quite valid. Though, you really should be using something more modern like a 16F628A but you've heard that before... --- In , "German Enred" <german@e...> wrote: > O.K. But remember: Im using the PIC16F84A.. > > Best Regards > > Date: Fri, 30 Jul 2004 16:14:33 -0000 > > From: "Phil" <phil1960us@y...> > > Subject: Re: RE. RE. RE. etc. MAKING SOFT COUNTERS > > > > multiply and divide by 10 is trivial with BCD. Mul/div by 2 is > > pretty simple. Mul by 5 is mul 10/div 2. Div 5 is mul 2/div 10. > > > > I still don't get why there is an undercurrent of "BCD is bad". For > > some applications like this one, its the perfect data structure. > > -- > Germán Hernández C. |
|
But keep in mind that it doesn't really matter if you are using a 16F84A or an x86 -- these are relatively simple operations. Multiply by 10 is simply a matter of shifting all the digits one BCD digit and putting a 0 in the least significant digit. Multiply and divide by two are a single bit shift operation just like in binary but you must fix-up the value afterword like you do with addition and subtraction. These are special cases of multiply/divide that are very easy to handle on *any* processor. I think Phil pointed them out to remind everyone that not all multiply/divide routines are difficult. Thus if your app can work with the constraints of using only these special case multiply/divide operations and there are some benefits from using BCD then the fact that you need some multiply/divide ability should not be a deterant. --Scott --- In , "German Enred" <german@e...> wrote: > O.K. But remember: Im using the PIC16F84A.. > > Best Regards > > Date: Fri, 30 Jul 2004 16:14:33 -0000 > > From: "Phil" <phil1960us@y...> > > Subject: Re: RE. RE. RE. etc. MAKING SOFT COUNTERS > > > > multiply and divide by 10 is trivial with BCD. Mul/div by 2 is > > pretty simple. Mul by 5 is mul 10/div 2. Div 5 is mul 2/div 10. > > > > I still don't get why there is an undercurrent of "BCD is bad". For > > some applications like this one, its the perfect data structure. > > -- > Germán Hernández C. |
|
|
|
FYI,
Multiplying by 10 is pretty simple…
Y=X<<1 + X<<3; //This is same as Y=X*2 + X*8 which is the same as Y=X*(2+8) = X*10;
Regards, Trampas
-----Original Message-----
But keep in mind that it
doesn't really matter if you
are using a |
|
|
|
if we are talking BCD (which I believe we are), then. as was pointed out earlier, its at most shifting the value by a byte or nibble. no need to monkey with anything else. Now, for binary, you are right. However, you have to handle the fact that the result needs to fit into twice the bits (8 bit multiplicands, 16 bit result). Your intermediate results need to be double the bits as well. --- In , "Trampas" <tstern@n...> wrote: > FYI, > > Multiplying by 10 is pretty simple… > > Y=X<<1 + X<<3; //This is same as Y=X*2 + X*8 which is the same as Y=X*(2+8) > = X*10; > > Regards, > > Trampas > -----Original Message----- > From: Scott Lee [mailto:midl_man@y...] > Sent: Sunday, August 01, 2004 11:21 AM > To: > Subject: [piclist] Re: ..SOFT COUNTERS > > But keep in mind that it doesn't really matter if you are using a > 16F84A or an x86 -- these are relatively simple operations. > > Multiply by 10 is simply a matter of shifting all the digits one BCD > digit and putting a 0 in the least significant digit. Multiply and > divide by two are a single bit shift operation just like in binary but > you must fix-up the value afterword like you do with addition and > subtraction. > > These are special cases of multiply/divide that are very easy to > handle on *any* processor. I think Phil pointed them out to remind > everyone that not all multiply/divide routines are difficult. Thus if > your app can work with the constraints of using only these special > case multiply/divide operations and there are some benefits from using > BCD then the fact that you need some multiply/divide ability should > not be a deterant. > > --Scott > > --- In , "German Enred" <german@e...> wrote: > > > > > > O.K. But remember: Im using the PIC16F84A.. > > > > Best Regards > > > > > > > Date: Fri, 30 Jul 2004 16:14:33 -0000 > > > From: "Phil" <phil1960us@y...> > > > Subject: Re: RE. RE. RE. etc. MAKING SOFT COUNTERS > > > > > > multiply and divide by 10 is trivial with BCD. Mul/div by 2 is > > > pretty simple. Mul by 5 is mul 10/div 2. Div 5 is mul 2/div > 10. > > > > > > I still don't get why there is an undercurrent of "BCD is bad". > For > > > some applications like this one, its the perfect data structure. > > > > -- > > Germán Hernández C. > > to unsubscribe, go to http://www.yahoogroups.com and follow the instructions > > > Yahoo! Groups Sponsor > > ADVERTISEMENT <http://us.ard.yahoo.com/SIG=129h4hjuh/M=295196.4901138.6071305.300117 6/D=gr > oups/S=1706554205:HM/EXP=1091460092/A=2128215/R=0/SIG=10se96mf6/*http: /compa > nion.yahoo.com> click here > > <http://us.adserver.yahoo.com/l? M=295196.4901138.6071305.3001176/D=groups/S= > :HM/A=2128215/rand=242291181 > > _____ > > > Service. |
|
|
|
Technically speaking the result needs to be log2(10) bigger than the multiplicand. So that would mean if the multiplicand is 8 bits you would need 12bit result. However if the multiplicand is 4 bits then your results will be 8 bits.
But you are correct in assuming that most people would use a 16 bit result for 8 bit multiplicands, the same as I was correct in assuming most people would realize it was for binary and also assuming most people would know they need more bits in the result.
Regards, Trampas
-----Original Message-----
if we are talking BCD
(which I believe we are), then.
as was pointed |