# Interfacing variable voltage a/c signal with a uC

#### gte

Joined Sep 18, 2009
360
Hello,

I have a variable voltage/frequency signal that I need to measure with my uC. My uC can accept up to 3.3v+, so I'm wondering the best way to measure this positive and negative variable voltage value, while protecting my uC. The signal will range from +/-5v to +/-10v, at various frequencies. Below are a few scopes.

I was thinking that if I used a diode to filter out the negative part of the sine wave, and then a 3.9k/5.1k resistor ladder with a 3.3v zener "teed" in between the resistor ladder out and the uC pin in.

This would give me ~ 1.75v at 5v peak and 4.03v at 10v peak, of which my uC cannot take so that is why 3.3v zener would be needed.

#### Attachments

• 93.5 KB Views: 30
• 99.8 KB Views: 27

#### wayneh

Joined Sep 9, 2010
17,498
Measuring AFTER a diode is no longer measuring your signal, IMHO. Voltage drop across that diode is not constant and will depend on current and temperature. And it may alter the wave shape as well, if its response is slow relative to the signal. Also make sure your voltage divider doesn't load down the signal and alter it. In other words maintain a high impedance.

#### gte

Joined Sep 18, 2009
360
Hi,

Thanks for the response, if I understood your post correctly my proposed interface is far from optimal ... how would you interface the uC with the signal then?

Logically I'm trying to filter out the negative half of the wave and limit the peak voltage ceiling to 3.3v, while keeping voltage floor above 1.65v with my resistor values.

#### wayneh

Joined Sep 9, 2010
17,498
I don't know enough to give you an answer, but I'd consider shifting and shrinking the signal, so that it can be passed fully into the acceptable range for your µC. Shrinking is easy, but I'm not sure how you get the minimum of the AC signal to be at µC "ground". Maybe capacitive coupling would help.

I can tell you that defining "ground" between a circuit and another instrument such as an oscilloscope, is a constant and recurring problem.

#### pilko

Joined Dec 8, 2008
213
What parameters of the signal do you want to measure, and what do you want the uC to do with the information?

pilko

#### gte

Joined Sep 18, 2009
360
Hi Pilko,

I only want to measure when the voltage eclipses 1.65v. To be more specific, the voltage is generated by an ac motor crank sensor and trigger wheel.

I measure time differences between peaks as well as peaks per other time period.

My uC does many different things and calculations with the information.

Last edited:

#### pilko

Joined Dec 8, 2008
213
If I understand you correctly , do you just need to know when the signal is increasing and passing through 1.65V. If that is the case, then rectify the signal, use a potential devider to reduce the voltage, and use the ADC on your uC.

pilko

#### gte

Joined Sep 18, 2009
360
Hi Pilko,

I count rising edge's and time between rising edges with my uC, so yes I believe you understand me correctly.

My uC is 80mhz, and this portion of the code is written in assembly ... throughout testing it has been plenty fast enough so far, so yes I believe it is.

Do you have a rectifier you can recommend?

#### pilko

Joined Dec 8, 2008
213
Try a schottky diode with suitable voltage rating and a 3 to 1 devider.No zener.
Its always better to scope the signal before shoving it into th uC.

pilko

#### wayneh

Joined Sep 9, 2010
17,498
Yes, my earlier concern about the accuracy of measuring a rectified signal are not terribly relevant to your situation. You give a threshold voltage to two significant figures after the decimal, but I suppose some plus or minus is acceptable, and the voltage drop across the diode won't really be a factor.

#### gte

Joined Sep 18, 2009
360
I don't think 5v - .3 and then applied to a 3 to 1 resistor divider is going to give me enough peak voltage though. How would that work? Am I overlooking something?

Would interfacing an LM2903 be better?

Thank you both!

Last edited:

#### wayneh

Joined Sep 9, 2010
17,498
I'm confused by your question. I thought you wanted to limit your peak to 3.3V. Maybe you should draw out your plan so we're all talking about the same thing.

#### gte

Joined Sep 18, 2009
360
Hi Wayne,

Yes that is correct.

I thought if I used a comparator I could do that, similar to how they do so in this circuit?

If that is wrong, I'll be happy to draw it out, just let me know.

Last edited:

#### wayneh

Joined Sep 9, 2010
17,498
Ah, so now you're considering an input buffer op-amp. That might be a good idea in general to help protect your micro. But I don't think it's required to get a result, because your micro is smart enough to process the input directly without the op-amp to square it up.

#### gte

Joined Sep 18, 2009
360
Hi Wayne,

I was just wondering because I have used the lm2903 (might have been the lm339) before and liked working with it and found it pretty durable.

I'm confident that the 3:1 resistor divider will not mathematically work because of the large variance in voltage.

The floor voltage value is about 5v and the ceiling is at least 10v, it may go higher than that above 5000rpm, I have not tested it because free revving the engine like that is hard on it.

At 3:1 I would be at (5v * 1/4) - .3 = .95v, not enough to trigger the uC. At 1/3 I'm at 1.35, at 2/5 I'm at 1.7 which is a hair above the 1/2 way point of 1.65v . At 10v and 2/5 ratio, I'm at 3.7v which is above the threshold that the uC can take, so that fails. I could go to 4.25:10 (a good ratio for the floor) and be at 5v/1.83v, 10v/3.95v but the ceiling is too high which is why I thought the zener's would have to be in between the resistor ladder and uC input pin. This way they could regulate voltage via current and act as a voltage clamp.

My only other choice that I can think of is a comparator circuit, of which I believe I can get the lm339 at Radio Shack? Do you agree? Also do you agree about needing a zener in the first circuit?

Ah, so now you're considering an input buffer op-amp. That might be a good idea in general to help protect your micro. But I don't think it's required to get a result, because your micro is smart enough to process the input directly without the op-amp to square it up.

#### wayneh

Joined Sep 9, 2010
17,498
I think you could use a 5v zener on the input signal (along with a current limiting resistor), so that every peak is held more-or-less constant at 5V. Then divide that down to 3.3 and you're done. If I understand your system correctly (I didn't initially!), I don't see why you'd need anything more complicated than that. You'll lose information on the size of the peaks, but it sounds like the peak timing is what you're after, not the amplitude.

gte

#### gte

Joined Sep 18, 2009
360
That's a good idea! (and it's simple which I like)

I shall try that tonight on the scope and if it works, then on the uC.

#### gte

Joined Sep 18, 2009
360
Well this worked (I couldn't wait ), but I can't seem to increase the voltage value and I'm a little confused about that.

I'm seeing between 1.8 and 2v, controlled by the zener. It's a 3.3v zener and I tried altering the larger resistor and changing it from 3.9k to 6.8k and I still couldn't get more than 1.8 to 2v out of the signal.

Any idea as to why?

#### wayneh

Joined Sep 9, 2010
17,498
You don't need the 3.9k resistor, which is only serving to distort what the zener is doing. Just omit it.

The other resistor may be a bit too high in value for the zener, which needs a minimum current to hold its nominal voltage. I would expect it to work with your resistor, given that you should be getting at least about 4mA across the zener, but maybe it needs more. If removing the 3.9k doesn't do the job, do a little research on your zener.

gte