Page 1 of 1

Measure time between signals with MCPWM capture

Posted: Mon Feb 18, 2019 9:52 pm
by lkiss10
Hello,

I am working on an RPM measure program, using Hall sensor input. How can I measure time between signals with the MCPWM capture function without using CPU time? The doc says this hardware unit is able to do it: "The hardware is able to detect the input signal’s edge and measure time between signals. ". However it makes only one timestamp for the last signal. Then the CPU has to run a task at every signal to store it in a value, before the next timestamp overwrites it. If the frequency of the signal is high, it is a high load for the CPU.

The unit should make timestamps for the last 2 signals, then when I need (more rare then the signal e.g. in every 0.1sec), I would take the actual 2 values, and calculate the different. Or it should calculate the signal different directly, and I would just take the value. Is it possible somehow?

Thanks

Laszlo

Re: Measure time between signals with MCPWM capture

Posted: Thu Feb 21, 2019 5:51 pm
by SimonMasters
Here is some discussion on the Hall sensor from elsewhere on this forum
Read all the comments. I shows where the Hall Effect is maximal.
viewtopic.php?t=4963
You will see it says the esp32's Hall sensor is jumpy, but stable when averaged.
Someone should change the HallRead() code to make it average more than one actual measurement.

What follows is general advice, not specific to RPM measurement.
I would say that you need to determine the time interval, t, in seconds, microseconds or milliseconds over which you want a difference measurement. At t1 take a number of measurements and get an average (you might ignore "outliers" to get a more stable average), this all needs to be all in a loop, with a very short or no delay() statement, and can be run quickly, so the time taken to measure 50 values (t50 << t). You will have to test how stable the result is...especially if your rpms are high and/or the device vibrates, but I'd wager that unless your device is in (or inducing) a rapidly flucuating magnetic field, you will be able to achieve an average of many "measurements" quite quickly. Don't print them out - that takes time - handle the math in the code. Then at t2 (i.e. t1 + t) take another measurement. Then compare the results in code, reporting exceptions.
I'm planning to use the Hall Sensor as a "software fuse" and need to measure real current in Amps. Of course it will need calibrating.
I don't want current to exceed a specific value, and I want the IO pin to trigger fast, so my approach is going to be to use a dedicated esp32 for the purpose of measuring an average current every 10-100ms with it "tripping" if the next reading exceeds an absolute threshold, or if the difference between two readings indicates the threshold is approaching. Since my relay takes several milliseconds to actually move time frames shorter than that are academic.

In the case of using the Hall Effect to measure a [high] RPM device, I guess you might be less interested in averages of measurement values but more the average time interval between sucessive "peaks" and "troughs" from a single HallRead() and time() function.
Could you
1. Establish average time to take N readings, calculating in real time average(), max() and min() measurements.
2 . Review the output using MeanMeasurement, MaxMeasurement and MinMeasurement to get a "Threshold change point", that is a measurement value that is halfway between MeanMeasurement and MaxMeasurement
3. Count HallRead() events (in real time) that are more than this threshold and, when this count is exceeded, trigger a measurement of T2
4. Possibly adjust the number of readings in line with the speed of the device, i.e. increase or decrease N to synch the readings and machine

Re: Measure time between signals with MCPWM capture

Posted: Fri Feb 22, 2019 7:42 am
by WiFive
He's not talking about the internal hall sensor but an external one that is mounted on a motor shaft.

Re: Measure time between signals with MCPWM capture

Posted: Mon Feb 25, 2019 7:13 pm
by lkiss10
Hi,

SimonMaster, thank for the explanation, but WiFive has right. I connect an external Hall sensor from a shaft. Its RPM is between 3000-5500 1/min, and has one magnet. So I would like to measure the time between the signals. I plan to use this ESP for a PID control as well, and I am afraid the too many interrupts will destroy the control process.
I am using now the example code, and I have another issue. It shows sometimes strange values. E.g. the terminal show 10-20 values around 3000 (what is correct), then one 12 000, and again 10-20 pcs 3000 around. I can filter out the unrealistic values, but first I would find our what makes the problem. Do you have any idea?

Thanks

Laszlo

Re: Measure time between signals with MCPWM capture

Posted: Mon Mar 04, 2019 1:33 pm
by ESP_houwenxiang
Hi, I think you can using PCNT to do this, you can read the pulse count every 10 milliseconds.

Re: Measure time between signals with MCPWM capture

Posted: Tue Feb 15, 2022 2:33 am
by chukitoes
Reviving an old topic, but as I'm currently looking into the Capture Module myself and reading the ESP32 Technical Reference Manual, this problem of using only one Hall sensor to measure the instantaneous RPM from a motor can be solved by attaching the GPIO Input pin to 2 separate Capture signals, one for the rising edge and the other for the falling edge and then comparing their last value.

Check https://www.espressif.com/sites/default ... ual_en.pdf Section 16.3.4 Capture Submodule.

It says "... Multiple capture channels can be sourced from the same PAD input, while prescaling for each channel can be set differently. ..."

That's just my preliminary guess, though. So if anyone with more knowledge of the MCPWM module could verify this, it'd be much appreciated.

Re: Measure time between signals with MCPWM capture

Posted: Sat Feb 19, 2022 8:44 pm
by jgustavoam
Hi,
You can adapt this program to measure RPM. High precision measurement!

Best Frequency Meter ever made with ESP32 - awesome!
viewtopic.php?f=19&t=17018