How to translate SPIN to PropBASIC
Hi, Guys.
I try to translate from spin to pbas.
But no good.
I want your sdvise, please.
And pbas is more complex than spin.
Can does sin.pbas modify more simple?
sin.spin
sin.pbas
Post Edited (caskaz) : 3/14/2010 11:54:19 AM GMT
I try to translate from spin to pbas.
But no good.
I want your sdvise, please.
And pbas is more complex than spin.
Can does sin.pbas modify more simple?
sin.spin
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB main | sine, degree, dT, T, w
sine := $e000
ctra := %00110 << 26 + 0
dira[noparse][[/noparse]0] := 1
dT := clkfreq/10000 '10770
T := cnt
repeat
repeat degree from 0 to 8190 ' [noparse][[/noparse]0 - 360]degree
w := $7ff & degree
case degree & $1000
0: '1st or 2nd quadrant
case degree & $800
0:
frqa := word[noparse][[/noparse]sine + (w << 1)] << 15 + $7fffffff '1st quadrant
other:
frqa := word[noparse][[/noparse]$f001 - (w << 1)] << 15 + $7fffffff '2nd quadrant'
other:
case degree & $800
0:
frqa := -(word[noparse][[/noparse]sine + (w << 1)] << 15) + $7fffffff '3rd quadrant
other:
frqa := -(word[noparse][[/noparse]$f001 - (w << 1)] << 15) + $7fffffff '4th quadrant
waitcnt(T += dT)
sin.pbas
DEVICE P8X32A, XTAL1, PLL16X
XIN 5_000_000
top con $e000
bottom con $f001
P0 pin 0 output
wave var long
dT var long
T var long
degree var long
w var long
addr var long
data1 var long
data2 var long
check1 var long
check2 var long
sin_data1 var long
sin_data2 var long
sin func 3
Start:
' user start-up code
countera 48,P0
dT = 80_000_000/10000
T = cnt
Main:
' Main program code goes here
do
for degree = 1 to 8190
w = $7ff & degree
check1 = degree & $1000
check2 = degree & $800
sin_data1 = sin top, w, 1
sin_data2 = sin bottom, w, 0
if check1 = 0 then
if check2 = 0 then
frqa = sin_data1 << 15 + $7fffffff <--- error INVALID NUMBER OF PARAMETERS" "
else
frqa = sin_data2 << 15 + $7fffffff <--- error INVALID NUMBER OF PARAMETERS" "
endif
else
if check2 = 0 then
frqa = -(sin_data1 << 15) + $7fffffff <--- error INVALID NUMBER OF PARAMETERS" "
else
frqa = -(sin_data2 << 15) + $7fffffff <--- error INVALID NUMBER OF PARAMETERS" "
endif
endif
waitcnt T,dt
next
loop
GOTO Main
END
func sin
getaddr __param1, addr <--- error INVALID "PARAMETERS"
if __param3 = 1 then
addr = addr + (__param2 << 1) <--- error INVALID NUMBER OF PARAMETERS" "
else
addr = addr - (__param2 << 1) <--- error INVALID NUMBER OF PARAMETERS" "
endif
rdword addr, data1
return data1
endfunc
Post Edited (caskaz) : 3/14/2010 11:54:19 AM GMT

Comments
you can do only one operation in one line.
not: a= a+b+c
but: a=a+b (or: inc a,b)
inc a,c
Have fun, Christof
I modified.
frqa = sin_data1 << 15
frqa = frqa + $7fffffff
I deleted 4 erros.
There are still 3 erro of "func sin."
It works.
But after about 53seconds, sin-wave is output on P0(RC cuicuit out).
Why after about 53seconds?
Where is incorrect code?
DEVICE P8X32A, XTAL1, PLL16X XIN 5_000_000 top con $e000 bottom con $f001 P0 pin 0 output dT var long T var long degree var long w var long addr var long read_data var long check1 var long check2 var long sin_data var long sin func 3 Start: ' user start-up code countera 48,P0 dT = 80_000_000/500000 T = cnt Main: ' Main program code goes here do for degree = 1 to 8190 w = $7ff & degree check1 = degree & $1000 check2 = degree & $800 if check1 = 0 then if check2 = 0 then sin_data = sin top, w, 1 frqa = sin_data + $7fffffff else sin_data = sin bottom, w, 0 frqa = sin_data + $7fffffff endif else if check2 = 0 then sin_data = sin top, w, 1 frqa = -sin_data + $7fffffff else sin_data = sin bottom, w, 0 frqa = -sin_data + $7fffffff endif endif waitcnt T,dt next loop GOTO Main END func sin if __param3 = 1 then __param2 = __param2 << 1 addr = __param1 + __param2 else __param2 = __param2 << 1 addr = __param1 - __param2 endif rdword addr, read_data read_data = read_data << 15 return read_data endfuncIt takes about 16msec on 1-cycle. When dT exceed 160ticks,sin-wave don't output.
In case of SPIN, it takes about 800msec on 1-cycle.
In case of assembler, it takkes about 9msec on 1-cycle.
PropBASIC is fast.
I changed to "T = cnt + dT".
It fine works.