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
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