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
Measure time between signals with MCPWM capture
-
- Posts: 1
- Joined: Thu Feb 21, 2019 4:18 pm
Re: Measure time between signals with MCPWM capture
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
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
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
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
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
-
- Posts: 118
- Joined: Tue Jun 26, 2018 3:09 am
Re: Measure time between signals with MCPWM capture
Hi, I think you can using PCNT to do this, you can read the pulse count every 10 milliseconds.
wookooho
Re: Measure time between signals with MCPWM capture
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.
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.
- jgustavoam
- Posts: 165
- Joined: Thu Feb 01, 2018 2:43 pm
- Location: Belo Horizonte , Brazil
- Contact:
Re: Measure time between signals with MCPWM capture
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
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
Retired IBM Brasil
Electronic hobbyist since 1976.
Electronic hobbyist since 1976.
Who is online
Users browsing this forum: chegewara, W3C [Validator] and 75 guests