Problems with Division Result = 0.0000000 when debugging
Posted: Sat Apr 01, 2006 2:20 am
Hi all,
I have following problem: the division does not work. The result is always 0. I have a ICD2 module with the testboard. Connecting,and debugging is working, I can set breakpoints... but always 0!
The value from adc is greater than 0. Do I have to include something like <math.h>? I tried this but doesn´t work
Here my short program:
#include<16F877.h>
#device adc=10
long PULSWEITE_LOW;
long PULSWEITE_HIGH;
long DIFFERENZ;
You have to tell the compiler to do floating point division.
In your code it's doing integer division, so that explains why you get 0.
The compiler will do floating point math if at least one of the numbers
is floating point in the division equation. So you should make the "255"
into a floating point number as shown below in bold:
Quote:
TEILER = 255.0 / DIFFERENZ;
Guest
Posted: Sat Apr 01, 2006 4:19 am
Jipieee, yes this works! Such a simple error- a huge fault
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum