Shop OBEX P1 Docs P2 Docs Learn Events
pulse width — Parallax Forums

pulse width

letontonletonton Posts: 9
edited 2007-03-31 18:47 in Propeller 1
hi
there is a manner to exactly measure a pulse width
(say, some milli seconds) ?

thanx
·

Comments

  • SkogsgurraSkogsgurra Posts: 231
    edited 2007-03-30 07:27
    An oscilloscope with cursors provides around 1 percent accuracy. A scope with automatic measurements usually a lot better. There are also multifunction frequency counters with that capability. They can give you at least ns resolution and .0001 percent accuracy. Often a lot better - but they are getting pricey then...
  • T ChapT Chap Posts: 4,209
    edited 2007-03-30 07:53
    Hi letonton

    Assuming you are referring to using the Propeller to measure the pulse widths, the answer is yes. Take a look at the App note on counters for the full details of how counters work. Also, to view an example object that measures pulse widths, look for the Memsic accelerometer object that Beau wrote. It takes PWM from both an X and Y axis and uses it as a tilt sensor. In the Memsic example, the tilt info obtained from the PWM can be displayed on a TV. You could study that object to see how the pulse widths are being measured.

    There are various counter modes, you would set a cog, set the PHSA to 0, and start counting at a Frequency when a high pulse is recieved, and on the pulse low, the counter can be stopped and the PHSA(acculator) can be used to determine the pulse width.

    Here are the various downloads for the Prop. For the counter info see AN001. For the Memsic object see The Propeller Object Exchange

    www.parallax.com/propeller/downloads.asp

    PS If you were just looking for general info on measuring pulse widths, the forum entitled The Sandbox would be appropriate for non-Propeller based topics.

    Post Edited (TChapman) : 3/30/2007 8:25:02 AM GMT
  • SkogsgurraSkogsgurra Posts: 231
    edited 2007-03-30 09:17
    Sorry, I thought you meant if you can verify pulses that the Prop generates. It was the other way round? Was it?
  • T ChapT Chap Posts: 4,209
    edited 2007-03-30 09:28
    It is not obvious what is meant. It would be easy to determine a pulse width out, as a pulse is usually relative to the clock .
  • letontonletonton Posts: 9
    edited 2007-03-30 11:44
    sorry Skogsgurra !
    i meant : measuring pulses by propeller
    TChapman :
    thank you very much for help !
  • letontonletonton Posts: 9
    edited 2007-03-31 15:05
    hi
    i still feel confused...even
    after a careful read of the AN001

    my need is quite simple : to put pulses on a input pin
    and check if they are or not 50 milliseconds long
    and then take proper decisions...


    thanx from a propeller beginner !
  • JohnBFJohnBF Posts: 107
    edited 2007-03-31 15:19
    I've been using another quick and dirty way to measure pulses and other things, using the PLX-DAQ download (the links to which seem to have disappeared from the parallax site, btw). I have two long variables: stopwatchstart and stopwatchend which I set equal to cnt just before and just after what I want to measure, and then use the Excel spreadsheet to do the arithmatic. E.g., at a clockspeed of 80,000,000 Hz, (stopwatchend - stopwatchstart) / 80,000 gives the duration in ms.

    /John
  • glentechglentech Posts: 35
    edited 2007-03-31 15:21
    I like to set another cog making a pulse and then feed the pulse to the input pin.· If you don't know how to do this you should be able to with a modification of the hello world led stuff in the lessons.· This is helpful also when you want to know how much overhead your spin or asm program may have.
  • SkogsgurraSkogsgurra Posts: 231
    edited 2007-03-31 16:10
    I also had a problem (many, actually) when I read the AN001. As always, you need to understand what you don't understand.

    First. I didn't understand that the counters are much more than counters. They are "conditionally incrementing accumulators" and a lot of other things. You could also call them "complex subsystems for manipulating time-dependent almost-anything".

    That does not help much, but it probably makes you aware that the AN001 needs careful study - like all complex systems.

    Second. I had to rename a few of the registers to understand what is going on. Take the CTRA, for instance. It is NOT Counter A. It is Control Register A. That was where I had my first problem. Much easier when that was sorted out.

    Third. The FRQ register is NOT where you read frequency - which one might assume. It is the register that holds the increment used to increment the counter every time the ACCUMULATE CONDITION is true. It does affect PWM frequency. That may be why it has got its name.

    Fourth. What is an ACCUMULATE CONDITION? Simple, it is any of the myriads (OK, not quite that many) conditions that makes the PHS increment (yes, we will come to the PHS later). And, as you can see from the block diagram in figure 1, it is incremented by adding PHS and FRQ together and store back in PHS (PHS := PHS + FRQ). The Accumulate Condition is true when the LOGIC block outputs TRUE on its Trigger output. You need to study that separately, table 2 is a good start.

    Fifth. The counter is the PHS register. Do not ask why it is called PHS (perhaps 'cause it has some phase information in one of the opmodes that I haven't yet understood?). So, reading PHS says what the result is.

    Sixth. The A and B pins exist for both A and B counter. Do not think (as I did) that A pin is for Counter A and B pin is for Counter B.

    Seventh. The block diagrams showing different modes are very helpful. They show only the parts that are involved in each mode and make understanding a lot easier.


    Good luck! Mastering the counters makes the Prop a couple of dimensions even more exciting.
  • T ChapT Chap Posts: 4,209
    edited 2007-03-31 18:47
    said...
    my need is quite simple : to put pulses on a input pin
    and check if they are or not 50 milliseconds long
    and then take proper decisions...

    First, are the pulses part of a PWM signal, so that you need a decision on every potential variance <> 50ms? Do you need a decision for every pulse both greater than and less that 50ms?

    To check the pulse width, make decisions, and act on the decision in Spin requires some time, what degree of accuracy do you need? If the tolerance is very tight, it probably is a job to be done with assembly. If you want some ideas in Spin, lets first get a better idea of what you are trying to do.

    Relative to an 80mhz clock, 1 ms = 80_000 clock pulses right(80_000_000/1000)? Correct me if I am wrong on any of this anyone. A crude idea that comes to mind for testing 1 ms

    
    PUB INIT
       dira[noparse][[/noparse] 0] := 1    'set your Pulse in pin to pin P0
       dira[noparse][[/noparse] 1] := 0     'set Apin to output P1, may not be used in this example
       CTRA := %00100 << 26 + 1   set Apin to  P1
       frqa := 0      '  no accumulation yet
       PHSA := 0    '  not required, but illustrates that PHSA will start counting at 0 
    
    
    PUB TestPulseWidth
      Repeat
        Frqa := 0      ' set to no accumulation
        PHSA := 0    '  reset PHSA to 0
        Waitpeq (%1, %1, 0)  'wait for P1 to equal 1, this is your pulse to test
        FRQA := 1    'starts the CTRA counting from 0
        Waitpeq (%0, %1, 0)  'wait for P0 to equal 0, your pulse is finished, set FRQA stop counting next
        Frqa := 0      '  stop the accumulation
        TestResult    'or do a Return PHSA, and let the caller do the TestResult using the returned value
    
    PUB TestResult
        If PHSA :> 80000      '  was the count > 1 ms,  some tolerance will need to be built in to this number
           'do this
        If PHSA :< 80000      ' was the count< 1 ms, some tolerance will need to be built in to this number
           'do this
    
    



    Disclaimer: This can be done much more accurately in assembly, this will not produce precise results, but gives you a general idea of how it could be done. Hopefully someone else can point out even more cleaner ways of doing this even in Spin.


    Here is a thread that had some good discussion of counters that may help some:

    http://forums.parallax.com/showthread.php?p=631767

    Post Edited (TChapman) : 3/31/2007 7:58:34 PM GMT
Sign In or Register to comment.