Need help convert small SPIN code to PASM.
tripp
Posts: 52
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
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
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).
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.
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.