Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Newbie in PIC - Multiplication and Division

Status
Not open for further replies.

devonsc

Advanced Member level 4
Joined
Nov 30, 2004
Messages
115
Helped
2
Reputation
4
Reaction score
1
Trophy points
1,298
Activity points
1,931
example multiply pic assembler

Hi there, again, me and my "lousy" questions regarding PIC microcontroller.

I would like to ask about programming a multiplication and division in PIC. I've come across reading materials as well as opinions from the smart ones that it can be done using various ways. Please correct me if I'm wrong:

a.) Through repeated addition and subtraction - Slow but it seems to be easy to me :)
b.) Through look-up tables - Fast but take up a lot of memory?
c.) Through somekind of shifting method? - I've read about this but really don't quite understand how it can be done.

I was thinking to do the following:

I'm trying to write a PWM code in PIC that varies according to an analogue input which I will feed the PIC through the ADC module. I was thinking to have the PIC to perform some calculation based on this analogue input and changes the my CCPR1L and CCP1CON value for the PWM. Any advice? Any guidance is very much needed. Thanks in advance.

By the way, I still don't quite understand how do I store a 10-bit value. I was trying to store the 2 LSB of my calculation result, bit-0 and bit-1 on a location to have it stored in CCP1CON later and the others on another location to have it stored in CCPR1L later. Is this possible? Help very much needed. Thanks in advance.
 

pic instruction for multiplication 2 number

devonsc said:
I would like to ask about programming a multiplication and division in PIC.
Hop over to piclist. They have a pretty good selection of example code to implement a host of mathematical functions.

devonsc said:
b.) Through look-up tables - Fast but take up a lot of memory?
You can use a PIC18. Most of them have hardware multipliers.

devonsc said:
c.) Through somekind of shifting method? - I've read about this but really don't quite understand how it can be done.
It's quite simple really.
When you do a shift-left (<<), you multiply the value by 2.
When you do a shift-right (>>), you divide the value by 2.
In PIC, each of these operations take ony 2 instructions, so they are VERY fast.
You can play around with the values. So if you want a x3 multiplier, you go
y = (x<<1) + x

devonsc said:
By the way, I still don't quite understand how do I store a 10-bit value. I was trying to store the 2 LSB of my calculation result, bit-0 and bit-1 on a location to have it stored in CCP1CON later and the others on another location to have it stored in CCPR1L later. Is this possible? Help very much needed. Thanks in advance.
Usually we store the 8 LSB as a byte, and the 2 MSB as another byte.
 
multiplication using pic assembly language

Thanks checkmate, I'll try piclist.

By the way, I do understand what you mean by LSB as a byte and the other 2 MSB as another byte but I don't have any idea on how should I do the storing....(still thinking on how to do it "???")

Slow learner here...
 

pic c float division

Salam,

Look also to EPE Jan-2005 issue.
It has good "32 bit signed integer maths for pic" article.

SphinX
 

how to do division using pic

this book touches this subject
 

asm pic division

Hi, thanks to all, I've understand how to perform multiplication. By the way, ilker? Is it true that the book is only for C programming? i've not downloaded that book but it by looking at the contents, it seems that it is for C language. Sorry for not making myself clear, I'm actually using assembly language for the PIC for my program.

By the way, now I have problem understanding doing multiplication in which the number involves decimal point. It seems that I have to consider the decimal point in my multiplication as I'm doing this calculation to set-up my PWM signal.

Help really needed...
 

multiplication in assembly pic

Hi there, do you guys mind giving me guide on the following matters?

a.) Can anyone pls provide me the 'routine' or 'library' to do multiplication/division/addision/substraction in assembly language?

b) Can anyone pls adivse how to represent floating point number in assembly language?

Thanks in advance...
 

pic newbie

Here you'll find both fixed and floating point code in one kit:
**broken link removed**

/Rambo
 

multiplication pic

Shifting method...
It is same as you present number as a sum of 2^n factors, which is suitable for microcontroller operations.
For example if you need to multiply some number with 100 it is same if you multiply with (64+32+4). This can be be easily realized with shifting (faster than 100x add)
(shl 6 + shl 5 + shl 2)
You dont need to transform 100 manuallly into 64+32+4, because that information is already contained in number binary representation as 1 at place 6, 5, and 2.
100 dec= 01100100 bin
So you have to read bits of one number, and if is at some place 1 you have to shift another operand for amount of bit position. At the end you just have to add all shifted results.
 

pic18 32-bit multiplication

ilker said:
this book touches this subject

-> topic does not exist?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top