# Interfacing variable voltage a/c signal with a uC

#### gte

Joined Sep 18, 2009
353
It worked, I'm not saying this is the best way to do this, but it did work ... what do you think?

cranksignalconditioned(5.1zener-schmitt)ac motor 800rpm

cranksignalconditioned(5.1zener-schmitt)ac motor 800rpm

cranksignalconditioned(5.1zener-schmitt)ac motor 4000rpm

cranksignalconditioned(5.1zener-schmitt)ac motor 6000rpm2

Circuit current is:

#### CDRIVE

Joined Jul 1, 2008
2,219
Thanks.

Out of curiosity, what do you think of the current circuit? I would think with a 4000/6000Ω resistor voltage divider on the signal out pin, that I'm golden. I'd give me 2.7v peak at 4.5v and 3.3v peak at 5.5, and since my schmitt trigger is powered by 5v, it shouldn't ever eclipse Vcc, correct?

Since I'm a hobbyist, there is a good chance I'm overlooking something
My issue with that circuit is the same one that I've had from the beginning. It's not transparent to the sensor. In other words it doesn't present a high impedance to your sensor and will therefor pull it down.

This circuit has an input impedance of 100K and can be 1Meg if you like. Just change R2 to 1M. The JFET is actually inputting the negative going wave and inverting the signal at the Drain. Since, in your case, the negative waveform is a mirror of the positive, I see no issue here. This circuit also has the advantage as running directly off your 3V uC supply. It produces a fairly decent squared digital signal from input levels down to 4V and up to 15V. I simulated it up to +-30V but your input will never be that high so I didn't post that plot. You will also note that the 0 logic state is very close to zero and logic 1 = 3V. These levels should be ideal for your uC input.

If you feel the need, you can always hang your Schmitt trigger on the output of this FET for further squaring. You would then have to deal with reducing the 5V TTL level down to your uC's 3V requirements though.

#### Attachments

• 208.2 KB Views: 12

#### CDRIVE

Joined Jul 1, 2008
2,219
In my last schematic I used an MPF102 JFET. This because I have over a thousand of them but as you can see from this plot it was not the best choice. Check this plot out and notice that even a +- 2V signal is still providing a 0-3V output. This Fet has a Gate threshold spec about 1/3 that of the MPF102.

#### Attachments

• 58.1 KB Views: 14
gte

#### gte

Joined Sep 18, 2009
353
Hi, thanks for the reply and the schematic!

I do agree with you about it not being transparent, and I definitely like that thought process. When I originally hooked something up to this that was a prebuilt circuit, and then hooked a second prebuilt circuit up, the ac motor was erratic because two of those circuits hanging onto the signal line were drawing enough current to interfere with the sensors operation! Which is why I decided to build my own circuit.

I'm guessing I don't have any of those components in my parts stash and that they probably aren't Radio Shack items? So I will have to order them and wait for them to arrive.

One thing I will note, I'm not 100% convinced the logic high is the same length as the logic low, I believe the logic low is about 3 times as long as the logic high when the negative portion of the circuit is clipped, as seen in the pic below. What do you think?

#### CDRIVE

Joined Jul 1, 2008
2,219
I formed my opinion of your source signal when I asked you to measure it with nothing but your scope connected. Those waveforms were symmetrical. It's your circuit that's distorting the hell out of it (no doubt in my military mind) and that's exactly what I'm trying to avoid.

Here's a BJT alternative. It works well, 100K input Z and works down to 1V input. This circuit is squaring the positive slopes as you want. BTW, I would normally use 1K collector resistors in a switching circuit like this but rise time is not a big issue here and battery conservation is.

EDIT: Here's the link to what I'm referring to.

#### Attachments

• 87 KB Views: 102
Last edited:
gte

#### gte

Joined Sep 18, 2009
353
Sweet, thanks. Those BJT's I do have in the parts stash.

I'll try and assemble that tomorrow night or Saturday morning and then scope it and see what I get and report back. Based on the diagrams, it appears this circuit offers some hysteresis also?

Thank you for this alternative.

#### CDRIVE

Joined Jul 1, 2008
2,219
The diode can be just about any GP diode even the 1N2x series. No, not hysteresis. Just a lot of gain that makes it look that way.

gte

#### gte

Joined Sep 18, 2009
353
Ok, I like the BJT simulation better because the square waves are pretty much symmetrical, just like the analog ac waves. That will be better for my uC code anyway.

If my signal turns out to be the like the picture below, will a schmitt be able to be added without compromising the integrity of the symmetry of the rising and falling square waves?

#### CDRIVE

Joined Jul 1, 2008
2,219
I'll convert the last circuit to a Schmitt trigger for you.

#### gte

Joined Sep 18, 2009
353
Thank you

In the mean time I tested out the dual transistors and this should put a smile on your face.

This was at ac motor idle

#### CDRIVE

Joined Jul 1, 2008
2,219
Thank you

In the mean time I tested out the dual transistors and this should put a smile on your face.

This was at ac motor idle
Ooo, I see we're transferring serial data. Nice!
I'll be posting the schematic soon.

#### gte

Joined Sep 18, 2009
353
I actually have two small a/c motors that are over top of the larger one with this and ...

This is awesome!

#### CDRIVE

Joined Jul 1, 2008
2,219
Glad to see you're having fun. Curious, what uC are you using?

OK, here's the Schmitt trigger you wanted. I wanted to keep component count down, so this circuit's output is inverted from the input. I don't see this as an issue for your application. If you absolutely need the Input and Output in phase let me know. I can add another stage. This circuit triggers on input voltages above ~ 3.2V. See included plots and notes.

#### Attachments

• 110.6 KB Views: 17

#### gte

Joined Sep 18, 2009
353
Thank you so much!

I believe I've developed an algorithm from my oscope that I may be able to use the original circuit without hysteresis. I not, I should use a non inverted signal so that if I need to trigger on the certain part of a tooth, I'm not trying to trigger instead on the certain part of a gap. I appreciate you keeping the component count to a minimum as well!

I'm now trying to make sure I have the speed I need for the up to 9000 events per second I might be seeing. I'm using the para llax pro peller uC for this and trying to figure out assembly now.

#### CDRIVE

Joined Jul 1, 2008
2,219
Well, if you decide to use it here's the last version. Instead of adding another stage I decided to remove the last stage, which was Q3. I wanted to give you 0 to +3V logic but it wasn't worth the overhead of two more stages. As you can see, this circuit will swing from 331mV to 3V. You're uC should have no problem interpreting 331mV as logic 0. Eliminating 331mV just isn't worth the effort.

#### Attachments

• 80.1 KB Views: 118
gte

#### gte

Joined Sep 18, 2009
353
Thank you again. My uC will see 331mV as a logic low without issue, I am confident of that.

Can I ask what simulation software you use?

Well, if you decide to use it here's the last version. Instead of adding another stage I decided to remove the last stage, which was Q3. I wanted to give you 0 to +3V logic but it wasn't worth the overhead of two more stages. As you can see, this circuit will swing from 331mV to 3V. You're uC should have no problem interpreting 331mV as logic 0. Eliminating 331mV just isn't worth the effort.

#### Attachments

• 80.1 KB Views: 16

#### CDRIVE

Joined Jul 1, 2008
2,219
Thank you again. My uC will see 331mV as a logic low without issue, I am confident of that.

Can I ask what simulation software you use?
My Spice software is Tina Classic Version 9.3.30.306 CV-DS by DesignSoft. I also have LT Spice (it's Free) like many others here do. I rarely use it though because Tina is much faster to work with and it produces schematics that aren't clunky. What I mean by this is that the component models are much smaller than LT Spice and thus takes up much less real estate. I like Tina very much but I do have my issues with the folks there. Their help desk is very good and will answer questions within 12Hrs but they don't seem to pay attention to customers suggestions on improving the product. I've been waiting for years for them to add Picaxe uCs to their MCU library, to no avail. I also suggested a very simple addition to the Plot Windows that I've been posting. A few lines of code is all that's required to provide a frequency readout as a reciprocal of time between any two X points on the Transient Plots. If they don't do it soon I'll be writing a VB6 hook.

Another Spice program that I have is Visual Spice. This software started out as a stellar product but went dormant before the bugs were worked out. It's still sold but support is just about zilch. Unless someone cleans it up it will remain difficult to use and overly complicated, with zero intuitivity. .. I made this word up.

#### CDRIVE

Joined Jul 1, 2008
2,219
gte, thanks for the heads up. I thought you might like to have these hysteresis vs frequency plots of the last circuit I posted. C3 was included to further filter out extraneous noise. The smaller C3 is the flatter these curves will be. So if it becomes an issue at high RPM reduce it by half or more. That said, I don't think it'll effect your measurements as is.

Edit: I just realized that after looking at these, the rise and fall times may look drastically different from 50Hz to 1200Hz. This is only because I made no attempt to maintain the start and end times of these plots. The Sensor vs Out voltages are what's meaningful and they're noted on the plots.

#### Attachments

• 113.5 KB Views: 16
Last edited:
gte

#### gte

Joined Sep 18, 2009
353
Hi,

I've made some good progress but have a question for you, I've made some progress but I am getting some erroneous values which I believe to be crossover. My uC sometimes reads less than 1000 clk cycles which is 0.0000125 seconds. 12.5 uC is not possible with what I'm doing so because of this I believe it is getting noise. Is the best plan of action to throw a pull down resistor at the transistor base or or uC pin do you think? Or maybe something else to deal with the noise?

I'm currently still using the non hysteresis circuit that you created.

#### CDRIVE

Joined Jul 1, 2008
2,219
Did you install decoupling a cap close to the uC's Vdd?