Measure Pulse width of PWM waveform



  • 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)


    but we are getting nothing [ ] 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.



  • @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.



  • @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.



Pycom on Twitter

Looks like your connection to Pycom Forum was lost, please wait while we try to reconnect.