evaluation error

Beta Testing discussion on mikroBasic PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
peterverkaik
Posts: 174
Joined: 31 Aug 2009 22:44

evaluation error

#1 Post by peterverkaik » 14 Dec 2009 21:08

Here is a sub that compiles ok with dsPIC Basic but not
with dsPIC Basic Pro

Code: Select all

sub procedure Timer1Int org $1A
  'This subroutine executes every 10msec (T1 period)
  if freeze = false then
    if runtime = fadetime then
      red.start = red.target
      red.target = ptr^
      inc(ptr)
      'we shift RGB value 22 bits to left (2 bits for RGB to RGB1024, 20 bits for fraction)
      '$FF becomes $3FC00000, b31 signbit, b30 clear so a possible overflow does not alter signbit
      red.target = red.target << 22
      green.start = green.target
      green.target = ptr^
      inc(ptr)
      green.target = green.target << 22
      blue.start = blue.target
      blue.target = ptr^
      inc(ptr)
      blue.target = blue.target << 22
      white.start = white.target
      white.target = ptr^
      inc(ptr)
      white.target = white.target << 22
      fadetime = ptr^ '100msec units, max 255
      inc(ptr)
      fadetime = fadetime * 10 '10msec units, max 2550
      fadetime = fadetime * multiplier 'total 10msec units, max 40800, multiplier is 1,2,4,8,16
      if fadetime = 0 then 'failsafe to prevent div by zero
        fadetime = 10
      end if
      if (ptr = ((LoopPtr[currentLoop]+LoopLength[currentLoop]))) then
        ptr = LoopPtr[currentLoop]
      end if
      red.addvalue = (red.target-red.start)/fadetime 'signed division
      green.addvalue = (green.target-green.start)/fadetime
      blue.addvalue = (blue.target-blue.start)/fadetime
      white.addvalue = (white.target-white.start)/fadetime
      runtime = 0
    else
      red.start = red.start + red.addvalue
'      if red.start < 0 then
'        red.start = 0
'      end if
'      if red.start > $3FC00000 then
'        red.start = $3FC00000
'      end if
      green.start = green.start + green.addvalue
'      if green.start < 0 then
'        green.start = 0
'      end if
'      if green.start > $3FC00000 then
'        green.start = $3FC00000
'      end if
      blue.start = blue.start + blue.addvalue
'      if blue.start < 0 then
'        blue.start = 0
'      end if
'      if blue.start > $3FC00000 then
'        blue.start = $3FC00000
'      end if
      white.start = white.start + white.addvalue
'      if white.start < 0 then
'        white.start = 0
'      end if
'      if white.start > $3FC00000 then
'        white.start = $3FC00000
'      end if
      runtime = runtime + 1
    end if
    'shift 20 bits to right to obtain RGB1024 value
    PWM_Set_Duty(RGB1024_duty[red.start >> 20], 1)
    Pwm_Set_Duty(RGB1024_duty[green.start >> 20], 2)
    Pwm_Set_Duty(RGB1024_duty[blue.start >> 20], 3)
    whiteLED_duty = RGB1024_duty[white.start >> 20]
  end if
  IFS0 = IFS0 AND $FFF7 'Clear T1IF
end sub
The offending line is
if (ptr = ((LoopPtr[currentLoop]+LoopLength[currentLoop]))) then
If I change it to if ptr = 0 then
the compilation succeeds

The error messages are
315 304 Syntax error: Expected "Compile time know constant" but "?T40" found RGBWSv0_01p.mbas
315 304 Syntax error: Expected "else" but "then" found RGBWSv0_01p.mbas
316 304 Syntax error: Expected "end" but "=" found RGBWSv0_01p.mbas
316 304 Syntax error: Expected "if" but "LoopPtr" found RGBWSv0_01p.mbas
316 304 Syntax error: Expected "else" but "[" found RGBWSv0_01p.mbas
316 304 Syntax error: Expected "end" but "]" found RGBWSv0_01p.mbas
317 304 Syntax error: Expected "if" but "end" found RGBWSv0_01p.mbas
319 304 Syntax error: Expected "end" but "green" found RGBWSv0_01p.mbas
319 304 Syntax error: Expected "sub" but "." found RGBWSv0_01p.mbas
319 304 Syntax error: Expected "end" but "addvalue" found RGBWSv0_01p.mbas
319 304 Syntax error: Expected "." but "=" found RGBWSv0_01p.mbas

regards peter

User avatar
nikola.kostic
mikroElektronika team
Posts: 433
Joined: 11 Aug 2009 12:12

#2 Post by nikola.kostic » 15 Dec 2009 10:25

Please provide complete code which compiles in older version of the compiler or create a support ticket and attach complete problematic project archived in zip or rar format and we will inspect it.
http://www.mikroe.com/en/support/

peterverkaik
Posts: 174
Joined: 31 Aug 2009 22:44

#3 Post by peterverkaik » 15 Dec 2009 11:23

I have removed most code while still producing the error.

Code: Select all

'For 20MHz resonator
'HS/2 w/PLL 8x   FOSC = (20MHz)/2*8 = 80MHz

program RGBWS

'********************************************************
'* Declarations (globals):
'********************************************************

const DefaultLoop as byte[5] = (
         255,        255,       255,       0,         10  'each entry defines color target
)

const RedLoop as byte[5] = (
           0,          0,         0,       0,         10
)

const TotalLoops = 2
const LoopLength as word[TotalLoops] = (5,5)

' variables declarations
'dim ...
dim LoopPtr as longint[TotalLoops]
dim ptr as ^byte
dim currentLoop as word

'********************************************************
'* Program body:
'********************************************************
main:
  LoopPtr[0] = @DefaultLoop
  LoopPtr[1] = @RedLoop
  currentLoop = 0
  ptr = LoopPtr[currentLoop]

  if ptr = ((LoopPtr[currentLoop]+LoopLength[currentLoop])) then
    ptr = LoopPtr[currentLoop]
  end if
  while true
  wend
end.
The error is slightly different
31 1018 Warning: Suspicious pointer conversion RGBWSv0_01p.mbas
32 1018 Warning: Suspicious pointer conversion RGBWSv0_01p.mbas
34 1012 Warning: Implicit typecast of integral value to pointer RGBWSv0_01p.mbas
36 304 Syntax error: Expected "Compile time know constant" but "?T24" found RGBWSv0_01p.mbas
36 304 Syntax error: Expected "end" but "then" found RGBWSv0_01p.mbas
37 304 Syntax error: Expected "." but "ptr" found RGBWSv0_01p.mbas
0 102 Finished (with errors): 15 dec 2009, 11:15:21 RGBWSv0_01p.mbpds

regards peter

User avatar
nikola.kostic
mikroElektronika team
Posts: 433
Joined: 11 Aug 2009 12:12

#4 Post by nikola.kostic » 16 Dec 2009 12:05

You need to cast ptr pointer to word. This is new in PRO compiler and it had to be introduced because there were some problems with pointer arithmetic previously. You would do it like this:

Code: Select all

...
if word(ptr) = ((LoopPtr[currentLoop]+LoopLength[currentLoop])) then
    ptr = LoopPtr[currentLoop]
  end if
...

peterverkaik
Posts: 174
Joined: 31 Aug 2009 22:44

#5 Post by peterverkaik » 16 Dec 2009 15:04

Thanks, that works.

regards peter

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

#6 Post by janni » 17 Dec 2009 15:24

It should also be possible now to use typecasting to pointer types (works in mP), so there's another solution:

Code: Select all

... 
  if ptr = ^byte((LoopPtr[currentLoop]+LoopLength[currentLoop])) then 
    ptr = ^byte(LoopPtr[currentLoop])
  end if 
... 
that does not require knowledge of the internal representation of pointer to byte.

Post Reply

Return to “mikroBasic PRO for dsPIC30/33 and PIC24 Beta Testing”