Best Frequency Meter ever made with ESP32 - awesome!
- jgustavoam
- Posts: 164
- Joined: Thu Feb 01, 2018 2:43 pm
- Location: Belo Horizonte , Brazil
- Contact:
Re: Best Frequency Meter ever made with ESP32 - awesome!
ESP32 FREQUENCY METER - 2 CHANNELS - Version 3 - Checking out
Testing my old Crystal Oscillators - 20.000 MHz and 14.318180 MHz. Very Good!
Breadboards and long wires are susceptible to noise and can interfere with measurements. The ideal is to assemble the entire circuit on a printed circuit board and use shielded cables on the frequency meter inputs. But I will wait for other new implementations to the project.
The two outputs of oscillators 0 and 1 are not being used in this test.
Testing my old Crystal Oscillators - 20.000 MHz and 14.318180 MHz. Very Good!
Breadboards and long wires are susceptible to noise and can interfere with measurements. The ideal is to assemble the entire circuit on a printed circuit board and use shielded cables on the frequency meter inputs. But I will wait for other new implementations to the project.
The two outputs of oscillators 0 and 1 are not being used in this test.
Retired IBM Brasil
Electronic hobbyist since 1976.
Electronic hobbyist since 1976.
Re: Best Frequency Meter ever made with ESP32 - awesome!
Have you considered using the Capture Submodule of MCPWM module instead of the PCNT module? You can set the resolution down to 12.5ns (80MHz). There are 3 channels available, and they are fully hardware driven. An edge change on a GPIO causes the module to grab the current 32 bit timer value and store it in a register. Either edge polarity is supported. The timer is dedicated for the MCPWM module, so it's separate from all other timers. The interrupt doesn't need to be so fast because all it has to do is get the already latched value and subtract it from the last saved value to give you an exact time. The value being latched by hardware gets rid of jitter and lets you handle it anytime afterwards.
- jgustavoam
- Posts: 164
- Joined: Thu Feb 01, 2018 2:43 pm
- Location: Belo Horizonte , Brazil
- Contact:
Re: Best Frequency Meter ever made with ESP32 - awesome!
Hi OSCPUDEV,
We hadn't thought of this alternative of using the MCPWM peripheral in our project. Maybe at the time of the project's development, there wasn't much documentation available. But thanks for the tips!
We hadn't thought of this alternative of using the MCPWM peripheral in our project. Maybe at the time of the project's development, there wasn't much documentation available. But thanks for the tips!
Retired IBM Brasil
Electronic hobbyist since 1976.
Electronic hobbyist since 1976.
Re: Best Frequency Meter ever made with ESP32 - awesome!
Thanks a lot for this !!!
The meter was working well using the embedded oscillator, however when I tried to connect a function generator, I was ready 0 (when negative connected to the esp32 ground). After some research, someone had a similar issue and added a thermistor, I did the same and now it works.
Now I am trying to increase the sampling rate because I want to use this device for an overspeed protection for my miniature turbine engine. I only need to read up to 30 kHz so I don't need the full 40MHz capability.
The problem is, if I change the sampling_time from 1,000,000 to 100,000, or 10,000, or 1000.... the frequency read is affected (10, 100, 1000 times lower)
Exemple:
Simulated frequence: 12,600Hz
Sampling time: 1,000,000
Frequency read: 12,600Hz
Simulated frequence: 12,600Hz
Sampling time: 100,000
Frequency read: 1,260Hz
Anyone can help me on this??
Thanks in advance
Dave
The meter was working well using the embedded oscillator, however when I tried to connect a function generator, I was ready 0 (when negative connected to the esp32 ground). After some research, someone had a similar issue and added a thermistor, I did the same and now it works.
Now I am trying to increase the sampling rate because I want to use this device for an overspeed protection for my miniature turbine engine. I only need to read up to 30 kHz so I don't need the full 40MHz capability.
The problem is, if I change the sampling_time from 1,000,000 to 100,000, or 10,000, or 1000.... the frequency read is affected (10, 100, 1000 times lower)
Exemple:
Simulated frequence: 12,600Hz
Sampling time: 1,000,000
Frequency read: 12,600Hz
Simulated frequence: 12,600Hz
Sampling time: 100,000
Frequency read: 1,260Hz
Anyone can help me on this??
Thanks in advance
Dave
- jgustavoam
- Posts: 164
- Joined: Thu Feb 01, 2018 2:43 pm
- Location: Belo Horizonte , Brazil
- Contact:
Re: Best Frequency Meter ever made with ESP32 - awesome!
Hi DavyBoy,
First of all, this frequency meter only accepts digital signals up to 3.3V. Do not use analog signals directly. You will have to use a circuit to adapt analog signals. I may implement this in the future.
"Now I am trying to increase the sampling rate because I want to use this device for an overspeed protection for my miniature turbine engine. I only need to read up to 30 kHz so I don't need the full 40MHz capability."!
You don't need to change the sample rate to measure signals up to 30KHz. The accuracy of this frequency meter for this type of frequency is great!
What is your real need? To increase the frequency of measurements? For example - X measurements/second.
First of all, this frequency meter only accepts digital signals up to 3.3V. Do not use analog signals directly. You will have to use a circuit to adapt analog signals. I may implement this in the future.
"Now I am trying to increase the sampling rate because I want to use this device for an overspeed protection for my miniature turbine engine. I only need to read up to 30 kHz so I don't need the full 40MHz capability."!
You don't need to change the sample rate to measure signals up to 30KHz. The accuracy of this frequency meter for this type of frequency is great!
What is your real need? To increase the frequency of measurements? For example - X measurements/second.
Retired IBM Brasil
Electronic hobbyist since 1976.
Electronic hobbyist since 1976.
Re: Best Frequency Meter ever made with ESP32 - awesome!
Hi Gustavo,
First, thanks a lot for taking the time to answer, I really appreciate.
I just realized that you are living in Belo Horizonte, I have been there couple of time (as well as Rio), we have a turbine engine test cell at Pratt & Whitney do Brasil (at IAS).
I was trying to reduce the value at sample_time, but it was affecting the reading. I tried Anas's suggestion, to modify the calculation frequency=((pulses + (multpulses * overflow)) / 2.0) * 1e6/sample_time and it works as expected.
However, I'am still facing two issues:
- the more I increase the sampling rate (more and more sample within 1 second), the more the reading is unstable. I don't know if it is hardware limitation or it can be tweek by software.
- the reading is pretty stable using the internal oscillator, but when I connect a function generator (amplitude 3v), Positive to GPIO34 and negative to GND, I read 0. If I disconnect the negative, it bounce to 0 and something, when I keep the probe in my hand, I read unstable frequency. I added a thermistor and 10k resistors between the positive and GPIO34 (based on a similar issue someone else had) and it works now, but not as stable as with the oscillator. Any idea why I cannot connect my frequency generator directly to GPIO34 and GND? For information, I use a precise calibrator Beamex MC6.
Thanks a lot for your time
Dave
First, thanks a lot for taking the time to answer, I really appreciate.
I just realized that you are living in Belo Horizonte, I have been there couple of time (as well as Rio), we have a turbine engine test cell at Pratt & Whitney do Brasil (at IAS).
I was trying to reduce the value at sample_time, but it was affecting the reading. I tried Anas's suggestion, to modify the calculation frequency=((pulses + (multpulses * overflow)) / 2.0) * 1e6/sample_time and it works as expected.
However, I'am still facing two issues:
- the more I increase the sampling rate (more and more sample within 1 second), the more the reading is unstable. I don't know if it is hardware limitation or it can be tweek by software.
- the reading is pretty stable using the internal oscillator, but when I connect a function generator (amplitude 3v), Positive to GPIO34 and negative to GND, I read 0. If I disconnect the negative, it bounce to 0 and something, when I keep the probe in my hand, I read unstable frequency. I added a thermistor and 10k resistors between the positive and GPIO34 (based on a similar issue someone else had) and it works now, but not as stable as with the oscillator. Any idea why I cannot connect my frequency generator directly to GPIO34 and GND? For information, I use a precise calibrator Beamex MC6.
Thanks a lot for your time
Dave
- jgustavoam
- Posts: 164
- Joined: Thu Feb 01, 2018 2:43 pm
- Location: Belo Horizonte , Brazil
- Contact:
Re: Best Frequency Meter ever made with ESP32 - awesome!
Hi Davyboy,
The ESP32 frequency counter takes approximately 1 second (1 million microseconds) to make one measurement.
To modify the program for frequency measurements up to 50 KHz, make the following changes:
Calculation of frequency inside the void loop:
The count must be multiplied by 10 and divided by 2. Therefore multiplied by 5.
Some time is spent adjusting the oscillator frequency. If you are not going to use the ESP32 oscillator, remove this part of the program (inside void loop) :
Using the frequency generator with the Beamex MC6 (read the manual - page 26):
https://www.beamex.com/calibrators/beam ... #resources
- Adjust the amplitude to 3V. If it doesn't work, increase it to 4V.
- Select waveform - square
- Select Duty Cycle - 50%
- Configure the frequency (up to 50KHz)
I don't know what the output impedance of the Beamex is. Test it by inserting a 10 Kohm resistor between the generator output pins. And connect this output to the ESP32 Frequency Meter input.
I recommend that you measure the signal generated by this MC6 with an oscilloscope, to make sure it is correct.
See previous posts for a square waveform in scope.
The ESP32 frequency counter takes approximately 1 second (1 million microseconds) to make one measurement.
Code: Select all
uint32_t sample_time = 1000000; // Sample time of 1 second to count pulses
Code: Select all
uint32_t sample_time = 100000; // - Sample time of 0,1 second to count pulses
Code: Select all
frequency = (pulses + (multPulses * overflow)) * 5; // Calculation of frequency
Some time is spent adjusting the oscillator frequency. If you are not going to use the ESP32 oscillator, remove this part of the program (inside void loop) :
Code: Select all
String inputString = ""; // clear temporary string
osc_freq = 0; // Clear oscillator frequency
while (Serial.available()) {
char inChar = (char)Serial.read(); // Reads a byte on the console
inputString += inChar; // Add char to string
if (inChar == '\n') // If new line (enter)
{
osc_freq = inputString.toInt(); // Converts String into integer value
inputString = ""; // Clear string
}
}
if (osc_freq != 0) // If some value inputted to oscillator frequency
{
init_osc_freq(); // reconfigure ledc function - oscillator
}
Using the frequency generator with the Beamex MC6 (read the manual - page 26):
https://www.beamex.com/calibrators/beam ... #resources
- Adjust the amplitude to 3V. If it doesn't work, increase it to 4V.
- Select waveform - square
- Select Duty Cycle - 50%
- Configure the frequency (up to 50KHz)
I don't know what the output impedance of the Beamex is. Test it by inserting a 10 Kohm resistor between the generator output pins. And connect this output to the ESP32 Frequency Meter input.
I recommend that you measure the signal generated by this MC6 with an oscilloscope, to make sure it is correct.
See previous posts for a square waveform in scope.
Retired IBM Brasil
Electronic hobbyist since 1976.
Electronic hobbyist since 1976.
-
- Posts: 1
- Joined: Tue Oct 15, 2024 4:45 am
How to generate a float frequency by modifying the code, such as 24.12HZ
How to generate a float frequency by modifying the code, such as 24.12HZ?
- jgustavoam
- Posts: 164
- Joined: Thu Feb 01, 2018 2:43 pm
- Location: Belo Horizonte , Brazil
- Contact:
Re: Best Frequency Meter ever made with ESP32 - awesome!
Hi Wukon,
In this project the minimum resolution of the oscillator is 1.
A floating value is not allowed.
if (resolution < 1) resolution = 1; // set min resolution
In this project the minimum resolution of the oscillator is 1.
A floating value is not allowed.
if (resolution < 1) resolution = 1; // set min resolution
Code: Select all
//----------------------------------------------------------------------------
void init_osc_freq() // Initialize Oscillator to test Freq Meter
{
resolution = (log(80000000 / osc_freq) / log(2)) / 2; // Calc of resolution of Oscillator
if (resolution < 1) resolution = 1; // set min resolution
Serial.println(resolution); // Print
mDuty = (pow(2, resolution)) / 2; // Calc of Duty Cycle 50% of the pulse
Serial.println(mDuty); // Print
ledc_timer_config_t ledc_timer = {}; // LEDC timer config instance
ledc_timer.duty_resolution = ledc_timer_bit_t(resolution); // Set resolution
ledc_timer.freq_hz = osc_freq; // Set Oscillator frequency
ledc_timer.speed_mode = LEDC_HIGH_SPEED_MODE; // Set high speed mode
ledc_timer.timer_num = LEDC_TIMER_0; // Set LEDC timer index - 0
ledc_timer_config(&ledc_timer); // Set LEDC Timer config
ledc_channel_config_t ledc_channel = {}; // LEDC Channel config instance
ledc_channel.channel = LEDC_CHANNEL_0; // Set HS Channel - 0
ledc_channel.duty = mDuty; // Set Duty Cycle 50%
ledc_channel.gpio_num = LEDC_HS_CH0_GPIO; // LEDC Oscillator output GPIO 33
ledc_channel.intr_type = LEDC_INTR_DISABLE; // LEDC Fade interrupt disable
ledc_channel.speed_mode = LEDC_HIGH_SPEED_MODE; // Set LEDC high speed mode
ledc_channel.timer_sel = LEDC_TIMER_0; // Set timer source of channel - 0
ledc_channel_config(&ledc_channel); // Config LEDC channel
}
//----------------------------------------------------------------------------------
Retired IBM Brasil
Electronic hobbyist since 1976.
Electronic hobbyist since 1976.
Who is online
Users browsing this forum: No registered users and 38 guests