avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] cast from float to int problem


From: Magnus . Petterson
Subject: [avr-gcc-list] cast from float to int problem
Date: Tue, 3 Apr 2001 13:17:08 +0200

Hi
I have got a problem when moving from gcc version "2.95.2 19991024
(release)" to "2.97 20010108 (experimental)".
I have a routine that should count pulses and make a calculation from how
many of them that where high, see code below. When compiling with the old
version the temp2 (unsigned char) variable gets the value 90 as expected
but when using the newer one I get 0. The temp (float) value gets the same
value in both cases (although I don't know how to read out the real value
from the memory). I have tested this in the simulator version 3.22.
Any ideas?

Thanks Magnus

volatile uint_16 high,i;
volatile float temp;
volatile uint_8 temp2;
// Measure temp on sensor 0
uint_8 Measure0(void)
{
     high = 0;
     // for (i=0;i<0xfffe;i++)
     // {
          // high += (inp(PORTB) & 0x1);
     // }
     high = 17890; // TEST 90 degrees
     temp = ((float)high)/308.0098 + 31.9149 + 0.5; // 0.5 for round
     temp2 = (uint_8)temp;
     return temp2;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]