I'll have to look into those chips.You need a rail-to-rail op-amp, like @MrChips says, and you need to run it from the same power supply as the micro. That way it can get to the maximum input voltage possible for the A/D without exceeding the inputs. My favourite op-amps for that situation are Microchip's MCP6061, MCP6071, MCP6021 etc.
Bias the input with two equal value resistors to keep it as near the centre as possible
Interesting. Got any videos? What algorithm did you use and how accurate was it?Shucks, I did that already a long time ago. I had a display in a showcase. Visitors could come up to the display, talk, hum, whistle, sing a song, etc, and it showed the frequency and note detected. I was written in MATLAB.
ESP32's ADC is famously rubbish.I'll have to look into those chips.
ESP32 can be powered either 3.3 or 5v. But ADC limit is 3.1v.
yeah. Most if not all of the hobbyist microcontrollers (Arduino, ESP32, Seeed, Teensy, Lilygo, etc) have less than stellar ADC's. But for our application, we don't need accurate voltage readings. Just accurate time.ESP32's ADC is famously rubbish.
That is for FFT, yes. 1 Hz resolution is pretty poor at lower frequencies. And FFT is notoriously processor intensive - no one uses FFT for this type of application. Autocorrelation and zero crossing algorithms are much better, and faster. But, back in the day, FFT was IT.I just did an FFT (Fast Fourier Transform).
Sampling theory says that the resolution is the inverse of the sampling period.
Hence, if you want 1 Hz resolution, you need to sample for 1 second. To get 0.5 Hz resolution, you need to sample for 2 seconds.
The devboards have a regulator to produce 3.3V for the ESP32 chip. You can power the board from 5V, but the ESP32 itself can't be powered from 5VESP32 can be powered either 3.3 or 5v. But ADC limit is 3.1v.
Further to my post #14 (with suggestions subsequently repeated by others), given your application is just to determine frequency, the LM358 is probably okay but I would certainly make R1 and R2 the same value and use the available 9V to power the circuit followed by a resistive potential divider on the output to drop the possible 9V to 3V. Not being rail to rail, you don't need to drop quite so much. By making the gain higher you will cap the maximum and minimum voltage output to near the rails to look more like a square wave. Maybe use a potentiometer to vary the gain to accomodate different input values.The LM358 is hopeless for audio and nowhere near rail to rail, especially at 5V supply voltage. Why are R1 and R2 different values? Surely you want the peak to peak to swing equally between the 2.5V midpoint? Maybe power with 12V and attenuate the output with a resistive potential divider?
Right. Good clarification. We are using the Heltec dev board, it can be powered by 5v or 3.3v.The devboards have a regulator to produce 3.3V for the ESP32 chip. You can power the board from 5V, but the ESP32 itself can't be powered from 5V
So by 9v, I mean off the shelf 9v (Boss style center negative) power supplies used by musicians. But they aren't actually 9v, they are anywhere from 9.2 - 9.6v. So I really need to use a voltage regulator to accurately put the signal in the middle of the ADC 0-3.1v range. That's why I chose the 7805 so I could start with 5.0v.Further to my post #14 (with suggestions subsequently repeated by others), given your application is just to determine frequency, the LM358 is probably okay but I would certainly make R1 and R2 the same value and use the available 9V to power the circuit followed by a resistive potential divider on the output to drop the possible 9V to 3V. Not being rail to rail, you don't need to drop quite so much. By making the gain higher you will cap the maximum and minimum voltage output to near the rails to look more like a square wave. Maybe use a potentiometer to vary the gain to accomodate different input values.
Personally, I doubt that the poor linearity of the ESP32 A/D really matters. I'm actually wondering if you could simply use digitalRead(); instead of analogRead(); as it's much faster - I believe less than 0.8V is guaranteed low and above 2.5V is guaranteed high. Maybe adjust either R1 or R2, or the resitive voltage divider so that LOW and HIGH values occur equally often. I believe this would be a good starting point from which to try alternative algorithms. As already mentioned, FFT will take too long to provide a good frequency resolution and you'd need a lot of memory!


yeah, that's what @Jerry-Hat-Trick was suggesting above to use digitalRead(); I'm looking into that. Thanks.I think you're splitting hairs here.
If all you want to do is analyse zero crossings, then use a narrow band-pass filter and AC couple the signal to an analog comparator (or digital GPIO pin). You don't need an ADC for this.
Huh, a logic hex inverter. I've known about those for about 15 minutes. So it would do the digital conversion, kinda. As I understand it, if I use Vcc = 3v, then the LOW input < 0.5v and HIGH input is >2.46v. And the output LOW = 0.32v and the HIGH output would be 2.68v. Sending those into the digital GPIO would allow the use of digitalRead(); and keep the voltage under the 3.3v GPIO limit.One thing that is worth trying is to use a 74HCU04 as and amplifier. (Also available as a 74HC1GU04).
Its maximum gain is about 50, and its linearity is rather horrible as the output signal approaches supply rails, but it never really clips, rather it compresses, making the output signal vary rather less in amplitude than the input signal.

CMOS gate as a linear amplifier Edit oops sorry if that's duplicate of what Ian0 said in post #34.Huh, a logic hex inverter.
You can treat it as an op-amp, with only inverting input and output pinned out, and non-inverting input internally connected to half supply. Compared to a real op-amp the open loop gain is hopeless (about 50)Huh, a logic hex inverter.
That will almost work. Connect the 74HCU04 VCC to the microcontroller Vcc.Would this be how to design this circuit around the 74HCU04? It creates a 1.5V dc offset for the MCU. And the 3v supply effectively protects the MCU from overvoltage.
View attachment 329933
