How to deal /w converting sine waves of varying amp into square waves? - Page 1
Forum section: electronics / projects

author: comfortcube
author_rank: Contributor
timestamp: August 16, 2021, 08:01:33 pm
content: So I've got this flow meter that outputs a sinusoidal waveform of frequency and amplitude that are proportional to the flow through it (I can provide some specific data and pictures of waveforms if needed). What I'd like to do is take this high impedance source and convert it into TTL 3.3V square wave to be read by a digital input of a microcontroller, which could then determine flow and so on. What I was initially thinking was something like, (sensor signal) --> (filter) --> (amplifier) --> (comparator) --> (digital input). However, the issue is the peak-to-peak voltage of the sensor signal can go as low as 0.1V and as high as 1.4V. The fact that the Vpp of the sensor signal varies so much will make it difficult, if not impossible, to work /w one single amplifier gain and comparator reference voltage, at least in my head. I'm not sure how to handle this... I would imagine another microcontroller + adc could do the job, but I'd rather avoid using another microcontroller. Anybody has any ideas?EDIT: Guys, my bad. I just thought about it for a min and figured what I missed. In my head, I was thinking something like this: I could set the comparator Vref to 1.65V, halfway between 0 and 3.3, and if the sine waves were 3.3V peak to peak, everything would work fine. But what if the sine waves were less than 1.65Vpp? Then they would miss Vref...Yeah I'm an idiot. Firstly, all the sine waves have 0 offset, so they are just oscillating around 0V. So I just need to set Vref to 0 and voila. For some reason, this didn't occur to me until now...

author: dmendesf
author_rank: Frequent Contributor
timestamp: August 16, 2021, 08:24:50 pm
content: Maximum frequency is rather low so if you just use a rail to rail amplifier with gain like 30 powered by 5V you'll get an output passable as TTL for the microcontroller (I'm counting with the saturation to make the sine into an almost square wave). Probably a comparator with carefully selected histeresis and AC coupled signal input would work too.

author: comfortcube
author_rank: Contributor
timestamp: August 16, 2021, 08:57:02 pm
content: EDIT: Guys, my bad. I just thought about it for a min and figured what I missed. In my head, I was thinking something like this: I could set the comparator Vref to 1.65V, halfway between 0 and 3.3, and if the sine waves were 3.3V peak to peak, everything would work fine. But what if the sine waves were less than 1.65Vpp? Then they would miss Vref...Yeah I'm an idiot. Firstly, all the sine waves have 0 offset, so they are just oscillating around 0V. So I just need to set Vref to 0 and voila. For some reason, this didn't occur to me until now...

author: Benta
author_rank: Super Contributor
timestamp: August 16, 2021, 09:38:53 pm
content: You missed a crucial point in the reply from dmendesf.Powering a rail-to-rail I/O opamp from 0 and 3.3 V: goodBiasing to 1.65 V (or 1/2 Vcc): goodSetting a gain of 30...50: good, you should probably go even higher, say, 100.But you missed the point about AC coupling.Also, depending the opamp you choose, it's a good idea to clamp the input with two diodes: one to Vdd and one to 0V. Small-signal Schottky diodes are fine, eg, BAT54S.

author: Circlotron
author_rank: Super Contributor
timestamp: August 16, 2021, 10:12:53 pm
content: Years ago I had a similar issue. I was using a stepper motor as an AC tacho generator attached to the shaft of a 3-phase induction motor. The AC voltage from the stepper/generator varied widely, directly proportional to rpm. The cure was surprisingly simple- just pass that AC voltage proportional to frequency through a single stage RC filter. Voila! Constant amplitude over the whole range except for the very very lowest frequency. Then square it up with a comparator with a bit of hysteresis and you’re good to go.

author: Benta
author_rank: Super Contributor
timestamp: August 16, 2021, 10:26:54 pm
content: I rethought the opamp idea and rejected it again. A comparator circuit will give you cleaner waveforms. Here's a suggestion:

author: Circlotron
author_rank: Super Contributor
timestamp: August 16, 2021, 11:56:15 pm
content: Quote from: Benta on August 16, 2021, 10:26:54 pmSounds like the flow meter output is passive, e.g. rotating magnet and inductive pickup. You could eliminate C1 and R1 and connect the sensor directly to opamp input and Vdd/2.

author: Benta
author_rank: Super Contributor
timestamp: August 17, 2021, 12:35:16 am
content: Quote from: Circlotron on August 16, 2021, 11:56:15 pmThat's quite possible and even likely. But as we don't know the sensor, it's guesswork.

author: David Hess
author_rank: Super Contributor
timestamp: August 17, 2021, 03:06:07 am
content: Amplification does not really help unless it increases the signal to noise ratio. Nothing prevents slow comparators from detecting low level signals.Usually AC coupling and filtering the input and detecting the zero crossings with some hysteresis is sufficient. If the duty cycle is extreme, then AC coupling will not work and the threshold voltage can be set to the average of the peaks.

author: comfortcube
author_rank: Contributor
timestamp: August 17, 2021, 03:47:25 am
content: This is indeed the case. A lot of flowmeters (well, turbine flowmeters) utilize this idea.

author: Circlotron
author_rank: Super Contributor
timestamp: August 17, 2021, 04:41:22 am
content: An MC3334 ignition controller has an adaptive sense input for variable reluctance magnetic trigger. It might do what you need.https://datasheetspdf.com/pdf-file/504561/Motorola/MC3334/1