Shop OBEX P1 Docs P2 Docs Learn Events
Impluse counter — Parallax Forums

Impluse counter

RenesisRenesis Posts: 4
edited 2011-05-15 14:42 in Propeller 1
Hello!

I would like to count impluse on port 14 (about 1 KHz), not measure frequency.

I wrote this PUB:

if ina[14]
sz1:=1
if sz2==0
x=x+1
sz2:=1


if not ina[14]
sz1:=0
sz2:=0


X variable is the counter. This is working, but too slow.

I tried with the registers (CTR.FRQ and PHS), but that was too fast :)
When the Propeller got az impulse, that mode counted 2 or 3 times.


CTRA:=%0_01010_000_0000_0000_000000_000_001110
FRQA:=1
PHSA:=0


I prefer the first, but i can not speed it up.

Do you have any idea?

Thank for your help.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-05-14 16:15
    Renesis, welcome to the forum!

    attachment.php?attachmentid=78421&d=1297987572

    -Phil
  • Mike GreenMike Green Posts: 23,101
    edited 2011-05-14 16:23
    What do you mean by "an impulse"? Do you mean a positive-going edge ( 0 -> 1 )? Do you mean a positive-going pulse of a certain minimum width? First you have to communicate what you want and need. You say you want to count these. Do you want to count them in a specific period of time? Do you want just to make the count available for display or some other purpose? All of this has to be defined before there's a discussion of ways to do it.
  • RaymanRayman Posts: 14,877
    edited 2011-05-15 13:03
    I think I'd do "waitpe" to wait for the pin to go high, then do a "waitpne" to wait for it to go low, increment the count, then repeat...
  • RenesisRenesis Posts: 4
    edited 2011-05-15 14:03
    Thank you!
  • RenesisRenesis Posts: 4
    edited 2011-05-15 14:22
    Thank for your reply. Yes, I mean positive-going edge. This is a distance meter (Hall transmitter) in a car. I would like to measure the trip. This transmitter send 1600 signal on every 100 m.
  • RenesisRenesis Posts: 4
    edited 2011-05-15 14:42
    Thank you! I will try this.
Sign In or Register to comment.