Simple preamp circuit for generating 3.3V square wave output with Schmitt Trigger

Thread Starter

joulupukki

Joined Sep 9, 2022
271
My friend @rpschultz and I have been building an open source guitar tuner and are getting close on a final hardware enclosure design and have switched to a different flavor of ESP32-S3 that has an attached 2.8" screen. We made a lot of progress in this other thread getting the control circuit for the DPDT relay and that part is all working.

We've been using a simple op amp circuit and passing in an amplified guitar signal into the ESP32 for pitch detection, but in some simple tests using a hex inverter IC I noticed that tuning stability might be even better if I could send in square waves into the ADC of the ESP32. The algorithm I'm using for pitch detection is extremely fast because it's a zero-crossing algorithm. The pitch detection seems to get a lot smoother when I pass in square waves rather than the raw audio (which we were intentionally making clip anyway). However, when the input level dropped lower (especially true on the high strings of the guitar), the pitch information has been tailing off too quickly.

Here's a possible alternative circuit that uses 3x 2N3904 basic transistors as a simple preamp and Schmitt Trigger for generating the square wave output and then it's clamped at 3.3V with a 1N4728A Zener Diode. This seems to "work" well in LTspice all the way down to 20mA and also handles much higher inputs.

One thing I would have to add is to read the incoming voltage using another ADC GPIO (GPIO15_CTL on the schematic) so that I could use it as a noise gate for when the signal level gets low enough. I think, without that, the tuner would pick up noise and try interpreting it as frequency. Maybe ideally it'd be possible to have the output of the schmitt trigger not send anything if the incoming signal dropped below 30mA?

Does this look sane?

Here's a screenshot of the schematic and also the simulation at 20mV, 100mV (typical output of my tele), 300mV (typical output of one of my humbucker guitars), and 1000mV (crazy high, but it still seems to work).

1742168874600.png1742168881034.png1742168889520.png1742168895707.png1742168903915.png
 
Last edited:

sghioto

Joined Dec 31, 2017
8,633
You can do the same thing with the LM358.
One half for amplification and the other half as the Schmitt trigger.
Less complicated.
One other thing, an audio signal should be a voltage level not "ma" which is current.
Or did you mean "mv" which stands for millivolts?
 

Thread Starter

joulupukki

Joined Sep 9, 2022
271
You can do the same thing with the LM358.
One half for amplification and the other half as the Schmitt trigger.
Less complicated.
One other thing, an audio signal should be a voltage level not "ma" which is current.
Or did you mean "mv" which stands for millivolts?
Yes, I meant mV, good catch.

The LM358 can act as a Schmitt trigger with no other components?

Also, I realize the oxymoron part of the title of this thread. Clearly I didn't make this very "simple." Doh!
 

Thread Starter

joulupukki

Joined Sep 9, 2022
271
Thanks for the help with this!

One thing that's still in here from before is a high pass filter and a low pass filter. Now that we're not really concerned about any flavor of clean audio and more just about the zero crossings, do those even make sense to have in here?
 

MrChips

Joined Oct 2, 2009
34,621
Most musical instruments generate lots of harmonics.
Ideally, you want a notch filter to remove everything else except the fundamental.

Leave the filters in.
 

Thread Starter

joulupukki

Joined Sep 9, 2022
271
Can't hurt to leave them in. This little box will be a little bit more than a tuner. I've already built in a little feature where it quizzes you on different notes and as you play them it gives you another random note to play. It's a good fretboard exercise. You can stick with just one string, alternate strings, or change strings on every new note that pops up. It's not quizzing on a particular frequency but just a note. So you might play an A at the 5th fret on the 1st or 6th strings or open on the 5th string and it doesn't care. That feature is working pretty well. I've kind of got it all torn apart right now but I'm hoping to make a quick demo of it tomorrow after I scratch out some traces and modify it to the bottom circuit in post #8.

Incidentally, the plan is that we'll be making these available as DIY kits once we have the hardware, enclosures, etc. all sorted out. I'll make the software updatable via a web page and a USB cable. That part works pretty well, in fact. Soon, we'll be looking for a couple of people who are guitar players and into DIY who are interested in trying out a build to give us feedback ... for the raw cost of the parts of the kit. If you're reading this and you're interested, please reach out to me in a private conversation.
 

WBahn

Joined Mar 31, 2012
32,702
Just out of curiosity, does your device do anything that can't be done with an app downloaded onto a smartphone (either an existing app or one that could be written pretty easily)?

If not, what do you see as the hook for people to get your kit and build the device and then have to carry it around when they could just download an app and launch it?

I'm constantly thinking up all kinds of neat devices that would be handy to have and that I think that others would like it, too, usually to discover that "there's an app for that."
 

Thread Starter

joulupukki

Joined Sep 9, 2022
271
Just out of curiosity, does your device do anything that can't be done with an app downloaded onto a smartphone (either an existing app or one that could be written pretty easily)?

If not, what do you see as the hook for people to get your kit and build the device and then have to carry it around when they could just download an app and launch it?

I'm constantly thinking up all kinds of neat devices that would be handy to have and that I think that others would like it, too, usually to discover that "there's an app for that."
Great question! I also frequently use an app on my phone for the same reason, because it's always handy. Pretty much you nailed it about there being "an app for that." I had a couple of apps on the App Store when it launched in 2008 and have been building apps for iOS ever since – so I'm very aware of that particular issue.

The tuner we're building is meant for a guitar pedal board that you activate with a foot switch. It'll have an internal switch for buffered or true bypass mode. It'll have a 2.8" screen and be accurate. The sky is the limit for what it can look like and other features that it could have (based on what you might want the tuning interface to be). I don't imagine anyone carrying it around in their pocket, but for someone looking for a great pedalboard tuner that's open source and configurable, this will be the ticket.

Speaking of which, if you have ideas for something you'd like to see in terms of a cool interface for tuning, I'm all ears. ;) A couple of weeks ago I played around with adding one tuning interface that is similar to an airplane's attitude indicator. It took me a couple of hours to whip up and I'll add more refinements to it as the project moves along.
 

Thread Starter

joulupukki

Joined Sep 9, 2022
271
I've breadboarded the circuit using 5Vcc supply to the LM358 so that my output isn't too high (I don't yet have any 3.3V zeners).

I've got our latest PCB board (v3) and can easily switch between its output, the output of the 1st half of the breadboarded LM358, and the 2nd half of the breadboarded LM358 (the schmitt trigger).

Cool to see this generally working:
1742230774520.png

However, in practice, the one that performs the best on the actual ESP32 is the current V3 circuit which is using the 2nd half of the LM358 as a buffer.

In second place is the breadboarded LM358's first half.

In last place (in terms of stability of the tuning and the length of how long the tuning stays active while the string tails off), is the LM358's Schmitt trigger. It stops detecting much too soon and so the tuning disappears. Interestingly enough, while it *is* tuning, it's not as stable as the v3 board's output.

I also noticed that the stronger the signal, the more accurate and less jittery the tuning becomes. This makes me think that I should try to use the LM358's 2nd half as an additional amplification process and then just use a 3.3V Zener to clamp the voltage from going too high into the ESP32.
 

sghioto

Joined Dec 31, 2017
8,633
Using two amp sections to over drive the LM358 will produce a decent square wave.
Won't need the zener because at 5 volts the 358 max output is appx 3.5 volts.
 

Thread Starter

joulupukki

Joined Sep 9, 2022
271
Yeah, I've been trying to model it in LTspice. 5.7x gain on the 2nd stage, but not sure if this is how you do it. It at least keeps the output overdriven with a low signal input which should help the note tails last longer.
1742244419237.png
Here's 100mV input:1742244431041.png
 

sghioto

Joined Dec 31, 2017
8,633
Try this:
Remove C6 and U2.
Connect the junction of R5 and C3 to the plus input.
Install a capacitor in series with R7 like the one on R3
Can also increase the gain of the second stage if more sensitivity is needed.
 
Top