Measureing time of a pulse in usec

If doesn't fit into any other category ....
Marv
Posts: 26
Joined: Mon Feb 08, 2021 6:09 pm
Been thanked: 1 time

Re: Measureing time of a pulse in usec

Post by Marv »

I am just looking for a way to measure a pulse of 10 usec or more. I some times need to measure the on time of a single pulse. For instance measuring the echo from a transmitting device.
Marv
Posts: 26
Joined: Mon Feb 08, 2021 6:09 pm
Been thanked: 1 time

Re: Measureing time of a pulse in usec

Post by Marv »

I am having trouble with RMT function I don"t quite understand how to interpret a single pulse, and be able to record the time of the pulse.
I tried the example in the help file but that would not detect the pulse. The pulse I am using is a 20usec pulse from a PWM signal. Maybee the time in usec is to fast for software to measure.
User avatar
cicciocb
Site Admin
Posts: 2626
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 549 times
Been thanked: 1861 times
Contact:

Re: Measureing time of a pulse in usec

Post by cicciocb »

and the pulse is positive or negative ?
and what is the time between each pulse?
Marv
Posts: 26
Joined: Mon Feb 08, 2021 6:09 pm
Been thanked: 1 time

Re: Measureing time of a pulse in usec

Post by Marv »

pulse can be 10 usec to 10 mili sec and pulse is positive
User avatar
cicciocb
Site Admin
Posts: 2626
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 549 times
Been thanked: 1861 times
Contact:

Re: Measureing time of a pulse in usec

Post by cicciocb »

Ok, but what is the time between the pulses?
Marv
Posts: 26
Joined: Mon Feb 08, 2021 6:09 pm
Been thanked: 1 time

Re: Measureing time of a pulse in usec

Post by Marv »

There would be 100 milisec between measurement of pulse
User avatar
cicciocb
Site Admin
Posts: 2626
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 549 times
Been thanked: 1861 times
Contact:

Re: Measureing time of a pulse in usec

Post by cicciocb »

I think it's hard to handle pulses each 100msec.

You can measure with the RMT but you'll not have enough time for other actions.

In fact, what you plan to do after each pulse?
User avatar
cicciocb
Site Admin
Posts: 2626
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 549 times
Been thanked: 1861 times
Contact:

Re: Measureing time of a pulse in usec

Post by cicciocb »

Ok, seen your fast reactivity :) , I'll show you a demo code on how you can get the width of the pulse.

This example runs on an ESP32-S3 and use a PWM as generator.
The signal generated is at 10Hz so 100msec between pulses.

The signal is sent on the pin 39 and the input is on the pin 40.
Simply connect these 2 pins together, eventually checking with an oscilloscope in parallel.
A onInfrared event is generated automatically when the pulse is received.

You can set the width in usec and you'll see the corresponding value measured and printed by the RMT

Important : use print and not wlog, in particular if you print at high rate

Code: [Local Link Removed for Guests]

'RMT demo used to determine the width of a pulse
'the pulse is generated with the PWM
'computes the nb corresponding to the width of the signal
'freq : 10Hz
'resolution : 14 bits = 16384
width = 250 ' microseconds
n = cint(width/100000*16384)
pwm.setup 39, 1, n, 10, 14

rmt.Setup_RX 4, 40, 80, 1, 0, 1, 100, 12000 ' max width of the pulse 12000 usec = 12 msec
dim rx(64)
onInfrared doRMT

wait

doRMT:
t = millis
rmt.decode rx()
print "RMT", ubound(rx()), millis-t
res=0
for z=0 to ubound(rx())
  print z, rx(z,0), rx(z,1), rx(z,2), rx(z,3)
next z
return
Marv
Posts: 26
Joined: Mon Feb 08, 2021 6:09 pm
Been thanked: 1 time

Re: Measureing time of a pulse in usec

Post by Marv »

cicciocb that works I can use that for what I need.
Thank you!!
I have another problem with version 1.70.3 that i get this response continually when reading data
it is not only this program but every program I run
01/12/2024 12:01:07 -> Program Stopped
01/12/2024 12:01:34 => Connection Lost
01/12/2024 12:01:36 => Connection ON
01/12/2024 12:02:04 => Connection Lost
01/12/2024 12:02:04 => Connection ON
01/12/2024 12:02:19 => Connection Lost
01/12/2024 12:02:23 => Connection ON
01/12/2024 12:02:29 => Connection Lost
01/12/2024 12:02:32 => Connection ON
01/12/2024 12:02:33 -> Program Running
492
Data 1.7
Data 1.7
01/12/2024 12:02:39 => Connection Lost
01/12/2024 12:02:41 => Connection ON
Data 1.7
Data 1.7
Data 1.7
I did not have this problem with lower installed firmware
could this be a problem or is it my hardware?
User avatar
cicciocb
Site Admin
Posts: 2626
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 549 times
Been thanked: 1861 times
Contact:

Re: Measureing time of a pulse in usec

Post by cicciocb »

Have you refreshed your web page? (F5)
Post Reply