Shop OBEX P1 Docs P2 Docs Learn Events
Measure PWM — Parallax Forums

Measure PWM

Travis M. BestTravis M. Best Posts: 9
edited 2010-01-04 20:35 in Propeller 1
Is their a easy to input a 5v signal and measure the pulse width using a propeller????

Thanks
Travis

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-01-04 15:37
    Sure, limit the current into the Propeller pin using a 2.2K resistor, then use one of the counters to measure the pulse width. The attached program measures a high-going pulse in another cog so that you don't have to wait around for the pulse to arrive; when it does the measurement will be made and written to a hub variable.
  • Brian CarpenterBrian Carpenter Posts: 728
    edited 2010-01-04 15:43
    Thanks Jonny Mac

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    It's Only A Stupid Question If You Have Not Googled It First!!
  • kwinnkwinn Posts: 8,697
    edited 2010-01-04 15:44
    Yes.
    Put a series resistor (3K3 to 4K7) between the prop pin and the signal source.
    Use waitpeq or waitpne to wait for a signal transition on the pin and store the value of cnt in a register.
    Use waitpeq or waitpne to wait for another signal transition and store the value of cnt in another register.
    Subtract the first cnt value from the second to get the number of clock cycles between the two transitions.
    Multiply by the period of the clock to get the pulse width.
  • Travis M. BestTravis M. Best Posts: 9
    edited 2010-01-04 15:45
    Can you also measure a Low going pulse?
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-01-04 16:00
    JonnyMac, am I correct that the program you posted measures the low and high parts of the pulse? That is from going low until going low again.

    John Abshier
  • JonnyMacJonnyMac Posts: 9,208
    edited 2010-01-04 18:08
    It only measures the high desired part of the signal, using the low undesired portion for counter and hub activities. It was designed to work like the BASIC Stamp PULSIN function looking for a high pulse.

    [noparse][[/noparse]Edit] I've attached an update that measures a high- or low-going pulses. The init() method includes a mode parameter (0 for low, 1 for high).

    Post Edited (JonnyMac) : 1/4/2010 7:52:26 PM GMT
  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-01-04 20:35
    Disregard my question, I think I understand now.

    John Abshier
Sign In or Register to comment.