Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 21st February 2008, 03:41 AM   #1
Question Adding 8 Times a 10bit Number

Hi I want to add a 10 bit number 8 times & place them in two bytes.

Ex:345 X 8 = 2760

Does anybody have any math routine for that I searched in piclist but I couldn't find such a one.
Suraj143 is offline  
Old 21st February 2008, 03:55 AM   #2
Default

You can use the RLF instruction.
Code:
;put 345 into Acc
	movlw	low .345
	movwf	AccLo
	movlw	high .345
	movwf	AccHi
;now multiply by 8
	bcf	STATUS,C	;gets shifted into bit 0 of AccLo
	rlf	AccLo,f
	rlf	AccHi,f		;*2
	bcf	STATUS,C
	rlf	AccLo,f	
	rlf	AccHi,f		;*4
	bcf	STATUS,C
	rlf	AccLo,f	
	rlf	AccHi,f		;*8
;AccHi/AccLo now contain 2760.
HTH

Mike.
Pommie is online now  
Old 21st February 2008, 04:02 AM   #3
Default

Hi Mike Thanks for your input I'm wondering how can I use this for 16F PICs the maximum value it can hold is 255.

Thanks
Suraj143 is offline  
Old 21st February 2008, 04:12 AM   #4
Default

The code I posted is for 16F Pics. By combining two bytes the maximum value becomes 65535.

Mike.
Pommie is online now  
Old 21st February 2008, 04:33 AM   #5
Default

Hi thanks mike !

But i have a small question.

When I multiply 345 X 2 = 690
1010110010 That is correct

But when I double this 690 it will be = 1380
10101100100

Can you tell how this bit0 will be get set in the AccHi register.
Suraj143 is offline  
Old 21st February 2008, 04:57 AM   #6
Default

An RFL instruction moves all bits left one place. The bottom bit gets the value that was in the carry flag and the top bit gets placed in the carry flag.

Can you answer your question now?

Mike.
Pommie is online now  
Old 21st February 2008, 04:59 AM   #7
Default

I have attached the number pattern the green cell is my problem how will it be set?
Attached Thumbnails
Adding 8 Times a 10bit Number-8-times.jpg  
Suraj143 is offline  
Old 21st February 2008, 05:21 AM   #8
Default

Via the carry bit.

Mike.
Pommie is online now  
Old 21st February 2008, 05:28 AM   #9
Default

Hi mike after reading lot of times now I got understood. I got what I was expected.

What I’m doing with your routine?

I’m going to sample my AD value 8 times & going to divide by 8 to get the average.

Thank you very much mike
Suraj143 is offline  
Old 21st February 2008, 05:30 AM   #10
Default

I just got a point. The bottom bit gets the carry bit value after the instruction completed I believe.
Ex after the RLF completed the bottom bit will get sets.

Now I understood

thanks again mike.
Suraj143 is offline  
Old 21st February 2008, 05:31 AM   #11
Default

To divide by 8 you need to use RRF.

Mike.
Pommie is online now  
Old 21st February 2008, 05:32 AM   #12
Default

Quote:
Originally Posted by Pommie
To divide by 8 you need to use RRF.

Mike.
Oh yes why not
Thanks for that.
Suraj143 is offline  
Reply

Tags
10bit, adding, number, times

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Circuit to count number of times phone is picked up Megamox General Electronics Chat 22 4th December 2005 06:07 PM
Random number generator joe_1 Micro Controllers 3 9th May 2004 11:04 AM
Need help with random number generator themikestar Electronic Projects Design/Ideas/Reviews 0 30th September 2003 11:18 AM
need help with random number generator themikestar Electronic Projects Design/Ideas/Reviews 5 22nd July 2003 02:31 PM
Pulse to binary Number waqar Micro Controllers 0 16th May 2003 11:35 AM



All times are GMT. The time now is 12:34 AM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker