Reading an ac signal with an Arduino

Hello,

I've hit a problem with a project I've been working on for a few weeks and I'm hoping somebody can point out what I'm doing wrong.

The gearbox speed-sensor on my van failed - there was no way to fix it without taking the gearbox apart, so I decided to take a feed from one of the ABS sensors instead and use an Arduino to generate the Vehicle Speed Sensor (VSS) signal. The VSS signal was a 0-12V square-wave, proportional to the vehicle speed between 0Hz and about 800Hz flat-out!

The ABS sensors on my van are of the Variable Reluctance (VR) type, so generate an a.c. signal which increases in amplitude (from about 1V to 5V) and frequency as the vehicle speed increases. The relationship between ABS frequency and VSS frequency is 6:1, so the Arduino just divides the frequency by 6 and outputs a square-wave.

The difficulty was in reading the ABS signal from the VR sensor without upsetting the ABS control unit - my solution (which seemed quite simple at the time) was to use a 741 op-amp as a comparator, like this:

What's difficult about reading the VR sensor is that it isn't actually earthed as far as I can see - the two wires coming off it are either end of a detector coil, so have to remain independent from the vehicle (and Arduino) earth to avoid upsetting the ABS control unit. Using a comparator, I thought, would get around this, as the op-amp inputs are essentially isolated from the supply terminals and have such high input impedance, the ABS control unit should detect no change in the VR sensor circuit.

I built the circuit on strip-board as a DIY shield and wired it up...

...and was pleasantly surprised when it actually worked perfectly! That was, until two days ago, when it stopped working altogether.

I've since done quite a lot of fault-finding and have just tied myself up in knots, so if anybody can offer any advice, I'm open to any ideas whatsoever!

So far, I've confirmed that the sketch is still good and have replaced both the Arduino and the op-amp with no difference in behavior. I know the fault is in the input circuitry or the VR sensor, as the Arduino generates a calibration signal when it powers on, which drives the speedo to 100mph and this still works fine.

I've had the Arduino and shield on a workbench and found that it works exactly as expected; the comparator converts the sine-wave to a square-wave, the Arduino generates a square-wave output at 6x the input frequency and the transistor brings the 5V logic level up to 12V vehicle level.

The only unexpected (by me, at least) behavior I've discovered is that the comparator isn't changing state when the input wave crosses zero, but when it crosses 2.5V, which is half the supply Voltage - I'm using the comparator to both generate a square-wave and bring the variable VR signal level to 0-5V logic level, so it's powered via a 7805 at 0-5V. Essentially, this doesn't make any difference to the system function, though, as I still get a frequency-proportional pulse for the Arduino to read.

I've tried grounding the inverting input of the op-amp to try to improve the comparator function (i.e. force it to change state when the VR signal crosses zero), but this stops the ABS system from working, as the ABS control unit throws an error and the dashboard warning light comes on. I've tested the VR sensor and it still works as expected - without the non-inverting terminal grounded, the ABS light goes out.

What I don't understand is why it worked for a fortnight and then stopped working...I didn't change anything! Nothing's moved or broken on the shield and the Arduino is working fine. The only thing I've not changed is the VR sensor, but I've connected it to a scope and it seems to be working fine.

Any ideas? I'm properly stumped now :frowning:

The only unexpected (by me, at least) behavior I've discovered is that the comparator isn't changing state when the input wave crosses zero, but when it crosses 2.5V, which is half the supply Voltage

"The" input voltage isn't meaningful because there are two inputs. When the + input is higher (more positive) than the - input, the output goes high, otherwise the output is low.... I sure you know that. With (differential) AC in, you should always be getting a square wave out.

Do you know the differential voltage coming out of the sensors? Maybe it's too high and you've blown the op-amp? If the op-amp comparator requires a 2.5V differential to change state, it's bad. I don't know the limits of the 741 but if that's the problem you can probably add a couple of series resistors (so you don't "kill" the signal) and a pair of back-to-back Zeners for over-voltage-protection.

BTW - I'm impressed with what you've accomplished!!!

A 741 is NOT a good comparator, and it is NOT a good op amp to use on a 5V single supply. It isn't even close to rail-to-rail on the inputs or the outputs.

I strongly suggest that your very next step be to switch to a newer Op Amp, preferably an actual comparator. Then continue troubleshooting from there, if that does not solve it.

And I do not mean an LM358 or LM324.

Thanks very much for your help and advice, chaps.

I quite agree that the 741 is the bargain-bin option of op-amps and is widely acknowledged as the very worst way to devise a comparator, but I have a tonne of them sitting around and it worked in principle.

What comparator would you recommend for a single-rail supply configuration?

I've measured the differential voltage coming out of the VR sensor to be about 0.5V at about 10mph, going up to about 5V at 60mph (tricky to read a scope at that speed, to be honest!) The frequency is approximately 12x the mph in Hz...

I've tried driving the op-amp inputs (i.e. the differential input) with a 7V rms supply on the workbench and it doesn't damage the op-amp (as far as I could tell), but when the ac goes beyond a peak of 5V, the comparator seems to detect a second zero-crossing and the output goes low again until the input drops below 5V peak, at which point the output goes high and then low again when the input drops below 2.5V...it's tricky to picture, admittedly. My first thought was that I'd blown the op-amp and I tried adding back-to-back clamping diodes across the op-amp inputs, but this had no effect on the output - I tried it with zeners, too, but still couldn't see any effect. I haven't tried putting resistors in series with the op-amp inputs, as I felt the high input impedance of the op-amp would probably negate their effect, but it's another thing to try...

I absolutely promise, though, that it worked for a fortnight "as is" before it stopped working...

Thanks very much for your help with this :slight_smile:

LM339 quad comparator, about the cheapest chip available, works from 3 to 36V, open-collector output,
fast, cheap, low-power, very commonly used.

Tie each side of the tachogen to mid-rail (using a 10k--10k resistive divider), then it won't float about
and will stay centred. Use 10k resistors on the inputs of the comparator to protect them.

The simplest way to convert your signal to squares is any OP with 1M feedback resistor.
Power it by 5V so is arduino friendly.

...and was pleasantly surprised when it actually worked perfectly! That was, until two days ago, when it stopped working altogether.

and have replaced both the Arduino and the op-amp with no difference in behavior.

So is working for 2 days and dies ?

...no, it worked for about a fortnight and then died - that's the weird thing...and it hasn't really "died", as it still works fine on the bench and all the elements work in isolation, they just don't work together.

The only logical thing that makes sense to me is that I've somehow damaged the VR sensor in such a way that it's output is no longer readable by the comparator - but I've checked the sensor and it outputs fine...also, the ABSCU does a static (resistance) test and a dynamic (signal) test on it every time the van's driven and it's throwing no errors...

It's all a bit confounding - I'm starting to feel a bit like this:

You are smell in the right place.
car 12V can be nasty from ignition system, high voltage spikes .....
Use 5V regulator with 1000uF and 0.1uF on both sides of regulator, you also can add a choke,
or run your toys from seperate battery.
If doesn't help you need optocoupler.
put transistor to 5V instead 12V,

I worked on a very similar project, I converted an AC signal from a VR crank shaft sensor on a motorcycle and converted that to a 5V square wave, this was amplified to a 12V square wave which made the rev counter work on my motorcycle engine.

I did not use an OP AMP though, below is a simulation of the circuit that I used.

D1 is a 1N4148
D2 is a 5.1V Zener. BZX55C

That's pretty handy to see - thanks for that.

What is D1 doing? Is it protecting D2?

I'd have problems grounding the ac supply in my setup, as the ABSCU would see that as a fault, but I've been wondering whether a schmitt trigger might help somehow.

Thanks for your help :slight_smile:

I forgot to mention, on my engine, both of the wires went directly to the ECU, but one of them had continuity with ground so I spliced into the other one.

0x10c:
That's pretty handy to see - thanks for that.

What is D1 doing? Is it protecting D2?

I'd have problems grounding the ac supply in my setup, as the ABSCU would see that as a fault, but I've been wondering whether a schmitt trigger might help somehow.

Thanks for your help :slight_smile:

D1 is removing the negative voltage

This is how interferences are reduced in car radio - transformer = choke

the last picture

Thanks for your input Ted.

Admittedly, I've not added any capacitors to stabilise the regulator - maybe that would be a good idea, given the potential for transients on the supply, but the Arduino is running fine with no apparent damage or blown pins after three weeks in position, now.

Running the Arduino off a separate battery seems like overkill to me - plus, it would still have to be tied to the vehicle ground to supply the VSS signal to both the speedo and the ECU.

I originally thought about using an optocoupler, but I think even the 20mA or so it would draw from the VR circuit would trip an error with the ABSCU.

The transistor on the output stage has to be at 12V to bring the VSS signal generated by the Arduino (running at 5V) up to the 12V expected by the ECU (and the speedo).

All suggestions are helpful, though, so please keep them coming :slight_smile:

0x10c:
Running the Arduino off a separate battery seems like overkill to me

That is for testing to locate the problem, if it ok then you work on filtering power supply.
Voltage regulator capacitors are mandatory for all designs.

0x10c:
Thanks for your input Ted.

The transistor on the output stage has to be at 12V to bring the VSS signal generated by the Arduino (running at 5V) up to the 12V expected by the ECU (and the speedo).

Add 1 -10mH choke in series with resistor and capacitor to the ground from LR common point

I thought I'd post (probably) a final update on this one:

I built a new shield with an improved 7805 circuit with some filtering in place (like this) and an LM339N based comparator (basically like this, but with 10k input and output resistors and a 10k pull-up resistor) and kept the same 2N2222 output driving transistor.

The result? Exactly the same - the comparator apparently fails to detect the ac signal from the VR sensor - everything else was working as expected. I re-checked the VR sensor with a scope and it works as expected up to 40mph at least - I even purposefully tripped an ABS error and the ASBCU cleared it once the fault was removed, so the sensor's working as expected as far as the ASBCU is concerned.

I think I'm going to have to accept that this can't be done - with no way to apply some sort of reference to the VR signal without disturbing the ABSCU, there seems to be no way to actually measure it. What I just can't understand is why it worked for a fortnight with my 741 circuit and then stopped - it's rather shaken my faith in electronics, to be honest...

The real pain is, the van's not worth the cost of stripping the gearbox to fix the original sensor drive, so it's next trip is to the scrapyard :frowning:

Thanks for all your help anyway...

Your sensor has two wires,how you connect the oscilloscope ?
Ground and one of sensor wire ?
Capacitors on voltage regulator make it working properly but not eliminate interferences.
oscilloscope say - the sensor is not dead.
Pin #6 of 741- do you have 5 V square waves on it ? (oscilloscope)
Put your oscilloscope on 12V and 5V - should be a straight line.

What I just can't understand is why it worked for a fortnight with my 741 circuit and then stopped

So you drive signals outside the rails of an op amp and are supprised when it dies.
That is how electronics works, when you get it so badly wrong it doesn’t always instantly fry, many times the lifetime of the chip is severely reduced. It looks like this is what happened. It only takes a passing pulse to drive things over the edge.

With no common referance this is bound to happen.