Convert LM393 based sound detection circuit to detect small sine pulse

Thread Starter

Alan Bates

Joined Nov 18, 2015
12
Hi - trying to hack together a circuit to take a small amplitude sine pulse signal (moving magnet passing static coil) of around 200Hz, and output a digital high low to an arduino. the signal will be used to calculate frequency.

I know there are a few example diagrams out there for using LM393 as a comparator, so i thought as a test I could get hold of a 393 based sound detection module that uses an electret microphone. i'm thinking i should be able to replace the microphone signal with my input and save myself some breadboarding, but what do you think? Am i way off track? I'm assuming the microphone will be active and therefore i can't just wire the input to the terminals of the mic, but i was hoping there must be somewhere in the circuit i can insert my signal to get the desired result.

Feel free to tell me if I'm in lala land - I can trace circuits and hack components together but my electrical engineering level is pretty low as you may have guessed. Cheers!
 

Roderick Young

Joined Feb 22, 2015
408
schemeit-project (1).png
Perhaps something like the above? The only reason for R3 is because the LM393 has an open collector output. If you use a different op-amp, you may not need it. You'll have to play around with R1 and R2 values, but offhand, I'd make them both 10k ohms for an 8 ohm voice coil as L1.

EDIT: oh, now I see the circuit that you were considering buying. Yes, you could mod that to work. Take out the 150 ohm resistor, and connect your voice coil between pins 2 and 3 of the op-amp. Looks like they already brought pin 2 out to the connector for you. Set the 50k trimmer to max resistance. I'd prefer that it be 500k, but the circuit might work with existing components.
 
Last edited:

AnalogKid

Joined Aug 1, 2013
8,487
The reference input to the comparator is Vcc/2, so your input signal rest level needs to be close to this. For example, if the signal is 0.1V peak, then the rest level should be around 0.05 V below Vcc/2. If you can't get stable operation with all DC coupling, then AC couple your sensor.

ak
 

Thread Starter

Alan Bates

Joined Nov 18, 2015
12
Thanks AnalogKid - I've now recieved my module. Slightly different circuit to the one I linked to but similar. See my sketched best guess below as I have it now. I have tweaked the circuit to respond to the peaks of the coil and I'm getting a clean digital output at working frequencies. So a good if dirty way to get something working quickly. I now have to tackle the digital processing of the signal to get a reliable frequency. Thanks for your help so far and I'm sure I'll be back for more...

upload_2015-11-19_22-45-45.png
 

wayneh

Joined Sep 9, 2010
16,398
You might consider pulling the output up to Vcc with a ~3.3K resistor, instead of the 10K feedback. That will give an enormous amount of hysteresis as configured. The hysteresis is OK if it suits your application, but the pull-up resistor to Vcc is pretty much necessary to get a "digital" output. The LM393 can pull the output to ground and sink current, but it cannot source current. You need the pull-up resistor to do that.
 

Thread Starter

Alan Bates

Joined Nov 18, 2015
12
ah yes - that makes sense (sort of - i'm sort of an idiot :)). hysteresis is filtering the signal to debounce it? so if i remove the 10K resistor, and add a smaller resistor between Vcc and the sensor pin? i will try that out.

i've recorded some synchronised output - top waveform is the "digital" signal, bottom is the ac pulse analog signal from the coil. is the fact that the upper signal is inverted a reflection of the need for such a pull up?

upload_2015-11-20_12-5-14.png
 

wayneh

Joined Sep 9, 2010
16,398
Yup. The output is able to go low with only the comparator's low internal resistance in the way. But the highest voltage it can go to is given by Ohm's law. The 100Ω load and 5.3KΩ resistors make a voltage divider giving about 0.1V on the non-inverting input to the comparator. There's a 10K resistor between that point and the output, which should have little effect on the output voltage you measure. So your peak upper voltage is limited to ~0.1V.

Oh, and hysteresis is not the same as debounce. Hysteresis is like a dead band on your home's thermostat, where the current setting (on or off) sticks over a small range. This prevents rapid oscillation between on and off. A larger value resistor (for instance 1MΩ) gives a narrower hysteresis band. Debounce is a way to prevent multiple trigger signals from a single event, commonly used on switches.
 

Thread Starter

Alan Bates

Joined Nov 18, 2015
12
ok - so i've spent some time tinkering with the off-the-shelf circuit and got what i think were ok results, but wanted to have more control over the values and connections, so ended up breadboarding a version with full size components. i've got something like this:

upload_2016-1-18_20-48-15.png

the VR is turned up to max, and i've recorded some output from the yellow wire that seems to match what i'd hoped for: a sub-zero signal with occasional square peaks corresponding to the pulses from the coil, which can be detected and analysed by the arduino. however, i'm sure this is more through luck and guesswork than wisdom so if anyone can point out any faults or improvements please do. thanks for your help so far
 

Thread Starter

Alan Bates

Joined Nov 18, 2015
12
It looks like it would be low, so you might even try just grounding that input and eliminating VR.
Yeah, the pulses from the coil are pretty small (~0.1v) so the voltage at the comparator input has to be practically zero in order to detect them. i think i might be able to get away with grounding the input, but i wanted the ability to adjust the input so that i could confirm it was working.

maybe i should consider an amplification stage? think i need to do some testing with known input frequencies, so that i can confirm the output to the arduino is accurately generated.
 

AnalogKid

Joined Aug 1, 2013
8,487
No immediate need for a preamp just yet. The common mode range of the 393 extends below its negative rail (GND in your case) so it should do what you want. If you put a fixed resistor between the top of R1 and Vcc you will have much better adjustability. Your reference is about 50 x your input, so start with something around 20 x R1 and see if that gives you a good adjustment range. If you reverse the connections to the 393 you should get an LED blink on each positive-going input pulse.

ak
 

Thread Starter

Alan Bates

Joined Nov 18, 2015
12
thanks AnalogKid - that's a good idea. as for the LED, i had it arranged that way initially, and got the LED pulsing, but I reversed the connections so that the output matched what i was hoping for - i.e. LOW with occasional HIGH. The led is really only there as a reassurance i've got the power connected :) but if there's a way of keeping my preferred output and having the LED trigger as well, let me know. Thanks again and I'll try the additional resistor.
 

wayneh

Joined Sep 9, 2010
16,398
maybe i should consider an amplification stage?
I agree with AK that this is not yet called for. A signal of 100mV is plenty for the 393. If it were less than 10mA, you might consider an amp.

An IC doesn't like to see voltages on the inputs below the power rail. If your pickup is really only making a pulse of 100mV, an excursion to -100mV shouldn't bother the comparator. But if it starts getting bigger, maybe a volt or more, you might consider using a diode to limit the negative voltage on the comparator's input. Another solution is to change the bias up off of ground, for instance by placing the coil between two resistors so that its resting voltage is Vcc/2.
 

Thread Starter

Alan Bates

Joined Nov 18, 2015
12
righto - so to limit the negative voltage, i'd put a diode between the coil and the lm393 + input? i may add that just to be safe. levels may be lower than i thought but will test with some known signals and record the output to see if i can spot any false peaks or incorrect behaviour. thanks for your ongoing help
 
Top