Shop OBEX P1 Docs P2 Docs Learn Events
Converting to PASM — Parallax Forums

Converting to PASM

ThricThric Posts: 109
edited 2010-11-27 23:09 in Propeller 1
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]

Comments

  • HarleyHarley Posts: 997
    edited 2010-11-27 12:41
    Sounds like quite a challenge to bring someone up to speed to convert Spin to assembly language. Lots of 'hand-holding'.

    I'd suggest looking at a few programs which use COGNEW instructions in Spin. That's where the 'hooks' to PASM begin on initialization.
  • $WMc%$WMc% Posts: 1,884
    edited 2010-11-27 17:19
    Take a look at " bst "
    '
    http://www.fnarfbargle.com/bst/Latest/
  • hover1hover1 Posts: 1,929
    edited 2010-11-27 18:11
    $WMc% wrote: »

    Did you mean to refer to PropBasic which will compile into PASM?

    http://forums.parallax.com/showthread.php?t=118611

    Jim
  • AribaAriba Posts: 2,690
    edited 2010-11-27 23:09
    Instead of switching to PASM you can use the counters in the right modes.
    So you have a resolution of 12.5ns also with Spin.

    A possible solution (untested):
    PUB servo
      DIRA[11]~
      dira[12]~
      dira[13]~~
      dira[14]~~
      ctra := 0
      repeat
        y := PULSIN_Clk(11)
        x := PULSIN_Clk(12)
        pulsout(14,y)
        pulsout(13,x)
    
    PUB PULSIN_Clk(Pin) : Duration
      ctra := %01000<<26 | Pin    'POS DETECT
      frqa := 1
      waitpne(|<Pin,|<Pin,0)
      phsa := 0
      waitpeq(|<Pin,|<Pin,0)
      waitpne(|<Pin,|<Pin,0)
      Duration := phsa
      ctra := 0
    
    PUB PULSOUT(Pin,Duration)
      ctrb := %00100<<26 | Pin    'NCO
      frqb := 1
      phsb := -Duration           'pin=High
      repeat until phsb>0         'wait until Pin=Low
      ctrb := 0
    

    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
Sign In or Register to comment.