Best Frequency Meter ever made with ESP32 - awesome!

User avatar
jgustavoam
Posts: 163
Joined: Thu Feb 01, 2018 2:43 pm
Location: Belo Horizonte , Brazil
Contact:

Re: Best Frequency Meter ever made with ESP32 - awesome!

Postby jgustavoam » Sun Aug 04, 2024 2:42 am

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.


ESP32 Freq Meter 2CH board 20 MHz.JPG
ESP32 Freq Meter 2CH board 20 MHz.JPG (159.02 KiB) Viewed 1770 times
Retired IBM Brasil
Electronic hobbyist since 1976.

OSCPUDEV
Posts: 20
Joined: Fri Jun 23, 2023 7:02 pm

Re: Best Frequency Meter ever made with ESP32 - awesome!

Postby OSCPUDEV » Tue Aug 27, 2024 2:56 am

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.

User avatar
jgustavoam
Posts: 163
Joined: Thu Feb 01, 2018 2:43 pm
Location: Belo Horizonte , Brazil
Contact:

Re: Best Frequency Meter ever made with ESP32 - awesome!

Postby jgustavoam » Tue Aug 27, 2024 3:51 pm

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!
Retired IBM Brasil
Electronic hobbyist since 1976.

DavyBoy
Posts: 2
Joined: Mon Sep 09, 2024 11:53 pm

Re: Best Frequency Meter ever made with ESP32 - awesome!

Postby DavyBoy » Tue Sep 10, 2024 12:13 am

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

User avatar
jgustavoam
Posts: 163
Joined: Thu Feb 01, 2018 2:43 pm
Location: Belo Horizonte , Brazil
Contact:

Re: Best Frequency Meter ever made with ESP32 - awesome!

Postby jgustavoam » Tue Sep 10, 2024 12:21 pm

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.
Retired IBM Brasil
Electronic hobbyist since 1976.

DavyBoy
Posts: 2
Joined: Mon Sep 09, 2024 11:53 pm

Re: Best Frequency Meter ever made with ESP32 - awesome!

Postby DavyBoy » Thu Sep 12, 2024 10:01 pm

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

User avatar
jgustavoam
Posts: 163
Joined: Thu Feb 01, 2018 2:43 pm
Location: Belo Horizonte , Brazil
Contact:

Re: Best Frequency Meter ever made with ESP32 - awesome!

Postby jgustavoam » Fri Sep 13, 2024 2:27 am

Hi Davyboy,

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
To modify the program for frequency measurements up to 50 KHz, make the following changes:

Code: Select all

uint32_t sample_time = 100000;  //  - Sample time of 0,1 second to count pulses
Calculation of frequency inside the void loop:

Code: Select all

frequency = (pulses + (multPulses * overflow)) * 5;    // Calculation of frequency
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) :

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.

Who is online

Users browsing this forum: No registered users and 89 guests