While Loop problem using PIC12F683

Status
Not open for further replies.

ahmedabosriaa

Newbie level 5
Joined
Nov 26, 2012
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,337
Hi guys

I have a problem, hope to find help here

This is a simple program to let (B1= High) if (set = 8.1)
Unfortunately it doesn't work BUT it works only if we replaced the condition to (set<5.4 OR set<2.7).
So, could anyone tell me what is the problem.




 

I presume your code works according to C language specification. The problem is solely about understanding the nature of floating point numbers. Other than integer and fixed point numbers, they involve a rounding error. In the present case, matching 8.1 is missed by a very small difference. You can visualize by printing the numbers with full resolution.

But there's a simple solution: Never test for equality with float numbers, because it possibly never happens.

By the way, it seem pretty stupid to use float or even double (not actually supported by your compiler and casted to real, I guess) with a tiny PIC12F.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…