Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Measure Pulse width of PWM waveform

    Scheduled Pinned Locked Moved Discussion
    lopypulsepulse counterpwmfrequency
    3 Posts 2 Posters 1.5k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • shridattdudhatS Offline
      shridattdudhat
      last edited by

      We are trying to use nova dust sensor which gives a reading as pulse width with lopy.

      We wrote a simple code which is listed below to measure pulse width using pulses_get('P9', time).


      from machine import Pin
      from pycom import pulses_get
      from time import sleep_ms

      pin = Pin("G12", mode=Pin.IN)

      while True:

      data = pulses_get(pin, 100)
      print(data)
      sleep_ms(100)


      in output.

      Does anybody try to measure pulse width with any pycom devices?

      Please provide sample code to measure the pulse width of PWM signal.

      Shridatt Dudhat
      Power Electronics Imagineer, INDIA

      robert-hhR 1 Reply Last reply Reply Quote 0
      • robert-hhR Offline
        robert-hh @shridattdudhat
        last edited by

        @shridattdudhat The data sheets I found tells about a pulse perion of 1004 ms. The timeout given in pulses get is µs, so it should be set to a value like 1200000. But since pulses_get uses the RMT unit of the ESP32, and AFAIK this uses 15 bit registers for a pulse width, the maximum pulse length it can detect is about 32 ms.
        Therefore you shoud use a simple count loop ad detect the pulse with yourself by reading the GPIO input level. Alternativly you could use the serial ourput of the Dust sensor and connect it to UART2 or UART3. That seems far more reliable.

        1 Reply Last reply Reply Quote 1
        • shridattdudhatS Offline
          shridattdudhat
          last edited by

          @robert-hh said in Measure Pulse width of PWM waveform:

          UART2 or UART3

          hey, robert

          Thank you for reply,
          We will try UART for the same.

          Shridatt Dudhat
          Power Electronics Imagineer, INDIA

          1 Reply Last reply Reply Quote 1

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • 1 / 1
          • First post
            Last post

          Pycom on Twitter

          Pycom