Shop OBEX P1 Docs P2 Docs Learn Events
Need help convert small SPIN code to PASM. — Parallax Forums

Need help convert small SPIN code to PASM.

tripptripp Posts: 52
edited 2010-08-18 07:43 in Propeller 1
Hi all.

I have a small SPIN code that is used for a missing pulse detection.
My problem is that this code is to slow.

I have not yet written a single line of PASM so i would be happy if i could get help.

I guess this is simple for all PASM masters here :)

And how much faster do you think this will be in PASM?

[code]
Lcnt := 0
Ltoggle := 0
CTRA := (%01010 << 26 ) | (%111 << 23) | (0 << 9) | (4) 'POSEDGE detector pin4
FRQA := 0 'stops counter
PHSA := 0 'zero counter
CTRB := (%00001 << 26 ) | (%111 << 23) | (0 << 9) | (4) 'Always count
FRQB := 0 'stops counter
PHSB := 0 'zero counter
'
FRQB := 1 'start counter
PulseCounter := 1
repeat
waitpne(%1 << 4, %1 << 4, 0) 'Wait for pin4 to be low
waitpeq(%1 << 4, %1 << 4, 0) 'Wait for pin4 to be high
Lcntold := Lcnt 'Store last counter value
Lcnt := PHSB 'Counter value afte one pulse
PHSB := 0
if Lcnt / 2 => Lcntold 'Found gap if = true (Compare pulse lengths)
PulseCounter := 1 'Starts the pule counter
outa[6] := $FF 'Toggle I/O Pin6
outa[5] := $FF 'Toggle I/O Pin5
Ltoggle := 1 'Mark missing pulse
else
PulseCounter++ 'If not missing pulse count one more pulse
if Ltoggle == 1 'Set pin6 low
Ltoggle := 0 'Toggle

Comments

  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2010-08-17 16:09
    PASM, from my experience, is about 300-600 times faster. It really depends on the commands being used.

    Wouldn't now be a great time to learn PASM? You have a fairly simple program to use as a model and a need for the speed (that's how I started).
  • Capt. QuirkCapt. Quirk Posts: 872
    edited 2010-08-18 00:37
    Is this your CPS data?

    If so, perhaps frequency counter.spin from AN001 may help. While you are in the :loop subroutine, you could test for the missing pulse?

    Bill M.
  • ericballericball Posts: 774
    edited 2010-08-18 07:43
    I wonder whether you might be able to achieve the desired result by using LOGIC !A mode and then when A goes checking high the time it spent low. If it's more than X system clock cycles a pulse didn't happen.
    Width := |<<30 ' stupidly big number for initialization
    FRQA := 0    'stops counter
    CTRA := (%10101 << 26 ) | (%111 << 23) | (0 << 9) | (4)    'LOGIC !A detector pin4   
    waitpeq(%1 << 4, %1 << 4, 0)  'Wait for pin4 to be high
    FRQA := 1   'start counter
    repeat
      PHSA := 0    'zero  counter
      waitpne(%1 << 4, %1 << 4, 0)  'Wait for pin4 to be low
      waitpeq(%1 << 4, %1 << 4, 0)  'Wait for pin4 to be high
      if PHSA > Width+Width>>2  ' if !A low for 25% longer than previous
        do stuff
      else
        Width := PHSA
        do other stuff
    

    The only time critical is the processing from waitpeq to waitpne. When you have the "do stuff" / "do other stuff" filled out then I can help translate it to PASM.
Sign In or Register to comment.