Hi All,

I have trouble with calculation mismatch. The following is the program .

////data type declaration//////

unsigned int edge1, edge2, edge3, ED21, ED31;

float freq1, freq2;

double prt, pulse, PRT,PULSE;

#define timer_freq 16000000

void main()

{

if(edge2 > edge1)

{

ED21 = edge2 - edge1;

freq1 = (float) timer_freq / (float) ED21;

pulse = (double) (1000000 / freq1) ;

}

if(edge3 > edge2)

{

ED31 = edge3 - edge1;

freq2 = (float) timer_freq / (float) ED31; ////(float) (float)

prt = (double) (1000000 / freq2) ;

}

}

The output of the program:(using UART)

ED21: +8002.00

freq1: +1999.50

pulse: +500.124

ED31: +16005.0

freq2: +999.687

prt: +1000.31

(The above is correct calculation)

ED21: +8002.00

freq1: +1999.50

pulse: +3595.56

ED31: +16005.0

freq2: +999.687

prt: +1000.31

(The above is wrong calculation)

The above calculation values are changing depends on the value of ED21, ED31. But the value of ED21 & ED31 are same. But the calculation gave different values. Which one make different calculation , please let me know...

Advance in thanks...