Converting to PASM
Thric
Posts: 109
Could someone help me convert this spin program into PASM? What it does is that it stores an RC pulse clock value in a variable then sends that value back out. I can live with the resolution with using just two lines but i would like to get the control a little finer especially when I start using 4.
I'm trying to learn PASM but its currently over my head so if anyone trying to write the program could please tell me why you choose a certain instruction that would help alot.
Thanks
PUB servo
DIRA[11]~
dira[12]~
dira[13]~~
dira[14]~~
ctra := 0
repeat
y:=PULSIN_Clk(11)/80/2+1
x:=PULSIN_Clk(12)/80/2+1
pulsout(14,(y))
pulsout(13,(x))
PUB PULSIN_Clk(Pin) : Duration
ctra:=(%11010<<26)|(%001<<23)|(0<<9)|(PIN)
frqa:=1
waitpne(|<Pin,|<Pin,0)
phsa:=0
waitpeq(|<Pin,|<Pin,0)
waitpne(|<Pin,|<Pin,0)
Duration:=phsa
ctra:=0
PUB PULSOUT(Pin,Duration) | clkcycles
ClkCycles := (Duration*80*2-1250) #> 400
!outa[pin]
waitcnt(clkcycles + cnt)
!outa[pin]
I'm trying to learn PASM but its currently over my head so if anyone trying to write the program could please tell me why you choose a certain instruction that would help alot.
Thanks
PUB servo
DIRA[11]~
dira[12]~
dira[13]~~
dira[14]~~
ctra := 0
repeat
y:=PULSIN_Clk(11)/80/2+1
x:=PULSIN_Clk(12)/80/2+1
pulsout(14,(y))
pulsout(13,(x))
PUB PULSIN_Clk(Pin) : Duration
ctra:=(%11010<<26)|(%001<<23)|(0<<9)|(PIN)
frqa:=1
waitpne(|<Pin,|<Pin,0)
phsa:=0
waitpeq(|<Pin,|<Pin,0)
waitpne(|<Pin,|<Pin,0)
Duration:=phsa
ctra:=0
PUB PULSOUT(Pin,Duration) | clkcycles
ClkCycles := (Duration*80*2-1250) #> 400
!outa[pin]
waitcnt(clkcycles + cnt)
!outa[pin]
Comments
I'd suggest looking at a few programs which use COGNEW instructions in Spin. That's where the 'hooks' to PASM begin on initialization.
'
http://www.fnarfbargle.com/bst/Latest/
Did you mean to refer to PropBasic which will compile into PASM?
http://forums.parallax.com/showthread.php?t=118611
Jim
So you have a resolution of 12.5ns also with Spin.
A possible solution (untested):
Some explenations:
POS DETECT mode counts only when the Pin is high and stops adding FRQx to PHSx when the Pin is low. So you have measured the pulswidth very exact, also if Spin noticed the puls end with some delay.
NCO mode outputs Bit31 of PHSx at the Pin, so if you set PHSx to -Duration the Pin is set. Then PHSx counts up and when it reaches zero the Pin goes low immediatly, also if Spin has a bit longer to detect this.
Andy