Shop OBEX P1 Docs P2 Docs Learn Events
More about how to catch pulse edge time — Parallax Forums

More about how to catch pulse edge time

DukeDuke Posts: 21
edited 2005-06-23 05:37 in BASIC Stamp
Hello,

I'm using BS2P for time and pulse measuring works. I have posted some questions and have good answers but I still have·somes question.

How to write a program that measure the time of an edge, like a signal from button press


IN1··············· Button press

start
Point·········· |
··················

I know that pulsin cannot be use here because it can measure a period of changing High to Low and High again or same by High Level.

Now, I use a loop for measure like this

I=0
Loop:
······ Pause 1
·······I=I+1
······ IF IN1=0 THEN JUMP
GOTO LOOP

JUMP:
······ DEBUG DEG I,CR


By this program I can get the time in unit of 1ms.

Then how can I make a more fine measuring in micro sec
If I erase the line "Pause 1", How to convert the number of "I" to time value

Please help.

Duke..

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2005-06-23 01:38
    The PULSIN command was created for this sort of thing -- but it measures from the start of a pulse (when it goes low) to the end of the pulse (when it goes back high).

    I don't really understand what you are achieving with your command -- of what use is knowing how long it is from when you start sampling to when the signal goes low?

    In any event, there are tables of how long each command take to occur -- you can look at those and decide what the sample rate is of your code. Personally, I'd connect an output pin to my Ant8 logic analyzer, and read the times directly. You could use a second BS2 to read an output pulse, also.
  • DukeDuke Posts: 21
    edited 2005-06-23 01:54
    Thank you,

    That's very interesting. where can I find that table ?

    The purpose of this program is for finding the initial time that comes from a Photo Interrupter, I want to know
    how long does it takes after sending a signal to motor, while the begining position of Photo device cannot be fixed

    I really want a program like a stopwatch

    When I get the start pulse (not full pulse) I can add this with following pulse measured by pulsin.
    The button example is easy so I used it to explain the concept.

    Duke..
  • Tracy AllenTracy Allen Posts: 6,658
    edited 2005-06-23 04:59
    It may be that RRCTIME is what you are looking for, instead of PULSIN. Look at the manual at the description of the RCTIME command, where they show how to use it as a stopwatch to measure how long it takes for relay contacts to close after the relay is energized. That might be close to what you are trying to accomplish. The resolution of the command is 0.75 microsecond, but it times out after 0.05 second (49.151 ms) on the fast BS2p. If you need to measure an interval longer than that, you will have to do something with a program loop.

    A table of loop times is here... www.emesys.com/BS2speed.htm but you will have to adjust for the higher speed of the BS2p. Most of the times are for the original non-turbo BS2s. The BS2p is about 20% faster than the BS2sx.

    Timing loops:
    www.emesys.com/BS2speed.htm#longpulse

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • DukeDuke Posts: 21
    edited 2005-06-23 05:37
    Thank you for the link
    I'll try RCTIME command.
Sign In or Register to comment.