Hint: Variable has been eliminated by optimizer???

General discussion on mikroBasic for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Fritzables
Posts: 61
Joined: 07 Jun 2008 13:20
Location: Brisbane AUSTRALIA

Hint: Variable has been eliminated by optimizer???

#1 Post by Fritzables » 10 Jul 2009 09:35

I am becoming more familiar with using the DS18S20 Temp Sensor and using the example code found in the Help file under 1-Wire:

Code: Select all

program TEMPRETURE

' Set TEMP_RESOLUTION to the corresponding resolution of your DS18x20 sensoras
'  18S20as 9  (default setting can be 9,10,11,or 12)
'  18B20as 12
const TEMP_RESOLUTION as byte = 12

dim
  j as byte
  temp as word
  text as string[8]            ' "000.0000"

sub procedure Read_Temperature()
  Ow_Reset(PORTF,6)            ' Onewire reset signal
  Ow_Write(PORTF,6,0xCC)       ' Issue command SKIP_ROM
  Ow_Write(PORTF,6,0x44)       ' Issue command CONVERT_T
  Delay_us(120)

  Ow_Reset(PORTF,6)
  Ow_Write(PORTF,6,0xCC)       ' Issue command SKIP_ROM
  Ow_Write(PORTF,6,0xBE)       ' Issue command READ_SCRATCHPAD
  Delay_ms(400)

  j    = OW_Read(PORTF,6)     ' Get temperature LSB
  temp = OW_Read(PORTF,6)     ' Get temperature MSB
  temp = temp << 8
  temp = temp + j             ' Form the 2byte variable
end sub

sub procedure Write_Temp(dim temp2write as word)
  const
    RES_SHIFT as byte = TEMP_RESOLUTION - 8
  dim
    temp_whole as byte
    temp_fraction as word

  if ((temp and 0x8000) > 0) then
     text[0] = "-"
     temp2write = (not temp2write) + 1
  end if

  temp_whole = temp2write >> RES_SHIFT
  if (temp_whole div 100) then
     text[0] = temp_whole div 100  + 48
  end if

  text[1] =(temp_whole div 10) mod 10 + 48
  text[2] = temp_whole mod 10 + 48

  temp_fraction = temp2write << (4-RES_SHIFT)
  temp_fraction = temp_fraction and 0x000F
  temp_fraction = temp_fraction * 625
  text[4] =  temp_fraction div 1000 + 48
  text[5] = (temp_fraction div 100) mod 10 + 48
  text[6] = (temp_fraction div 10)  mod 10 + 48
  text[7] =  temp_fraction mod 10 + 48

  Lcd_Out(2,1,text)
  UART1_Write_Text(text)
end sub


' ----Main----
main:

  text   = "000.0000"
  ADPCFG = $FFFF

  Lcd_Init_EasydsPIC4()
  Lcd_Cmd(LCD_CLEAR)
  Lcd_Cmd(LCD_CURSOR_OFF)
  Lcd_Out(1,1,"Temperature:")
  
  UART1_INIT(9600)

  '--- main loop
  while TRUE
    Read_Temperature()
    Write_Temp(temp)
    Delay_ms(1000)
  wend

end.
When I Build the project then program the chip, the end result is a temprature reading that is one decimal point out: for example, instead of seeing the expected 025.625 degrees C - I see 002.5625 degrees C.

When I built the project, under Messages there is:

35:5 H-11 Hint: Variable 'temp_fraction (Write_Temp)' has been eliminated by optimizer

Which is: temp_fraction as word on line 35.

I suspect that as it's been eliminated by the optimizer that it's causing the decimal point to be in the wrong place.

How to I prevent the Optimizer from taking such action??

Fritzables :(

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#2 Post by p.erasmus » 11 Jul 2009 08:57

Fritzables

Please report this issue at the mE support desk directly as
I also had this problem and I think it is some problem with the
optimizer ,this way the compiler developers get to know the problem and
can look into it

Best regards
p.erasmus
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

Fritzables
Posts: 61
Joined: 07 Jun 2008 13:20
Location: Brisbane AUSTRALIA

#3 Post by Fritzables » 11 Jul 2009 10:02

G'Day p.erasmus,

OK, I have done so and will let ya know how I go.

Fritzables.

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#4 Post by p.erasmus » 11 Jul 2009 19:06

Fritables

Great Thank you
Regards
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

User avatar
mileta.miletic
mikroElektronika team
Posts: 493
Joined: 05 Jun 2009 14:46
Location: Belgrade, Serbia
Contact:

#5 Post by mileta.miletic » 13 Jul 2009 16:45

Hi,

It is not optimizer issue. Like it says in example set TEMP_RESOLUTION to the corresponding resolution of your DS18x20 sensors:
18S20as 9 (default setting can be 9,10,11,or 12)
18B20as 12.
In the help example it is set on 12 for 18B20, you probably have 18S20, just change it to 9.
Regards,
Mileta

p.erasmus
Posts: 3391
Joined: 05 Mar 2009 10:28

#6 Post by p.erasmus » 13 Jul 2009 17:59

Hi Mileta

Thanks for your reply however I had this happen to me where a variable
is removed in a PID loop
that has nothing to do with the Temp sensor defaults or am I mistaken somehow

Regards
P.Erasmus
P.Erasmus
Saratov,Russia
--------------------------------------------------------------

Post Reply

Return to “mikroBasic for dsPIC30/33 and PIC24 General”