cast from float to int problem

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi
I have go 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 running in 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;
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You might like to re-post this to avr-gcc-list@avr.jpk.co.nz
some of the avr-gcc development people monitor that list.