Shop OBEX P1 Docs P2 Docs Learn Events
speedometer — Parallax Forums

speedometer

marclamarcla Posts: 19
edited 2008-02-21 21:26 in Propeller 1
Hello!

How do i measure the time betvin two pulses.
it's goning to be used in a speedometer and the sensor gives one pulse per each rotation.
The speead never goes faster then 50kmh (30mph).



/Martin
Sweden

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-02-21 20:22
    You wait for the beginning of the first pulse with WAITPNE or WAITPEQ, then save the value of CNT in a variable.

    You then wait for the beginning of the second pulse, then subtract the saved value from CNT to get the time difference in system clock time (12.5ns for an 80MHz system clock).

    Look in the manual for descriptions of WAITPNE, WAITPEQ, and CNT.
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2008-02-21 20:22
    You can setup the counters to measure the time a pulse lasts. The BS2_Functions library has functions for PULSIN or FREQIN to measure the length of a pulse or the frequency of a signal in case that helps too. For the down and dirty method of setting things up yourself, check out the counters chapter of the PEK downloads.

    You can also use the WAITPNE and WAITPEQ to instructions to wait for the transitions:
    Wait for pin to go high
    record cnt value
    wait for pin to go low
    record new cnt value
    subtract the 2 values to determine speed.

    This relies on Spin though, and can suffer from some delay in spin whereas the counters don't.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    SelmaWare Solutions - StampPlot GUI for controllers, XBee and Propeller Application Boards

    Southern Illinois University Carbondale, Electronic Systems Technologies

    American Technical Educator's Assoc. Conference·- April, Biloxi, MS. -- PROPELLER WORKSHOP!
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2008-02-21 20:28
    Propeller Articles, Software, and Documentation Downloads

    Counters:


    www.parallax.com/tabid/442/Default.aspx

    Post Edited (Bob Lawrence (VE1RLL)) : 2/21/2008 9:24:54 PM GMT
  • deSilvadeSilva Posts: 2,967
    edited 2008-02-21 21:03
    Martin Hebel said...
    ...Wait for pin to go high
    record cnt value
    wait for pin to go low
    record new cnt value
    subtract the 2 values to determine speed.

    This relies on Spin though, and can suffer from some delay in spin whereas the counters don't

    The inaccuracy caused by SPIN is generally overestimated. When using such a SYMMETRIC design as Martin gives here, all SPIN delays will compensate and the result will be AS PRECISE AS WITH COUNTERS!!
  • dfletchdfletch Posts: 165
    edited 2008-02-21 21:26
    I've been meaning to update it, but you could try the frequency meter which takes samples, averages, and then dumps the result to a term. It's very primitive, but I think it does what you're asking for:

    obex.parallax.com/objects/256/

    There's a slightly newer version of this in the VGA learning driver (search this forum for it if you want that). I'll try to get a new rev up soon, but my evenings have been filled trying to get a graphics object working for that driver smile.gif

    Cheers,

    --fletch
Sign In or Register to comment.