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.

How to handle fractional numbers in pic 18 ?

Status
Not open for further replies.

engr.waqas

Full Member level 3
Joined
Jul 21, 2009
Messages
174
Helped
13
Reputation
26
Reaction score
10
Trophy points
1,298
Location
karachi,Pakistan
Activity points
2,357
+pic use scaling to multiply integers

How to handle fractional numbers in pic 18 as it does not have float variable type supported.
 

arthur0

Full Member level 2
Joined
Nov 28, 2003
Messages
131
Helped
49
Reputation
98
Reaction score
36
Trophy points
1,308
Location
Stockholm, Sweden
Activity points
1,218
Hi,

The idea is to multiply all your fractional constants with a scaling factor (powers of 10 to the desired precision), and do all computations on integers. In the last computational step you can scale back the result by a corresponding division (giving you the integral part of the result) and modulus (which gives the decimals, in case you want those too).
You can ensure a proper rounding by adding half of the scaling factor before scaling back the result.
Just make sure your intermediate results don't overflow your chosen data types.

See my answer . You can surely adapt that example to your case.

Arthur
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top