Shop OBEX P1 Docs P2 Docs Learn Events
waitpne/waitpeq issue — Parallax Forums

waitpne/waitpeq issue

JazzDJazzD Posts: 13
edited 2009-01-29 23:47 in Propeller 1
this is probably pretty easy but i havent found a solution yet: I'm measuring a frequency by sampling, just like the object that you find in the obex.

the method is pretty simple and uses WAITPNE to get the positive edge of the flank and WAITPEQ to get the negative. now if there is NO change in voltage/no signal on the pin it will simply block. What would be a simply way of getting a timeout into this assembler piece?

detector
  :mainloop             MOV :t1, par            ' get buffer pointer
                        MOV :lock, :t1          ' set lock pointer
                        ADD :t1, #4             ' offset for lock
   
                        WRLONG :one, :lock      ' assert waiting state
  :wait                 RDLONG :t2, :lock        
                        TJNZ :t2, #:wait        ' wait for clear

                        RDLONG [img]http://forums.parallax.com/images/smilies/tongue.gif[/img]in, :t1        ' set pin mask
                        ADD :t1, #4             ' offset for pin mask

                        MOV :ctr, #SAMPLESIZE   ' set counter
  :loop                 WAITPNE :zero, [img]http://forums.parallax.com/images/smilies/tongue.gif[/img]in     ' wait for pos edge
                        WAITPEQ :zero, [img]http://forums.parallax.com/images/smilies/tongue.gif[/img]in     ' wait for neg edge (pulse)
                        MOV :t2, cnt            ' capture time
                        WRLONG :t2, :t1         
                        ADD :t1, #4             ' next buffer position
                        DJNZ :ctr, #:loop       ' capture loop

                        JMP #:mainloop          ' main loop

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-29 20:32
    There is no way to put a timeout into a WAITPxx except by using another cog to either stop this one on a timeout or use an otherwise idle I/O pin to make a timeout trigger (wait for positive edge or timeout / wait for negative edge or timeout) and output a pulse on that idle I/O pin when a timeout occurs. It might make things easier to have two I/O pins available, one for a positive pulse and one for a negative pulse on a timeout. Your timeout routine could use a copy of the most recent CNT value (call it "startTime"). It would compute "CNT - startTime" and compare that to a timeout value.
  • mparkmpark Posts: 1,305
    edited 2009-01-29 23:47
    Phil Pilgrim posted a trick that might help: http://forums.parallax.com/showthread.php?p=575479
Sign In or Register to comment.