Converting 12v alternator signal to HIGH/LOW into a uController with an opto-isolator

Discussion in 'Digital Circuit Design' started by ba58smith, May 5, 2019.

  1. ba58smith

    Thread Starter Member

    Nov 18, 2018
    60
    0
    I'm trying to create a tachometer with an ESP8266, by reading the output from the stator wire on my 12V alternator. I'm using a 4n37 opto-isolator to provide the HIGH/LOW signal to the ESP8266. See schematic.
    TachSchematic.png
    When I use an Arduino to create a simple ON/OFF signal and feed that into the 4n37 (through R2 first), I get exactly what I expect - the same frequency coming out of the ESP8266 as the frequency coming out of the Arduino. That tells me the 4n37 is doing what I expect. The first image shows the ouput on a DSO138 oscilloscope set to DC mode, but as you can see, the low voltage is negative, not 0, which is why I think it's AC voltage, not DC. (If that sounds stupid - I'm very new to this, and this is the first time I've ever used an oscilloscope.)

    When the input to my 4n37 is the output from the alternator, however, I get very erratic results on the input pin of the ESP8266 - the frequency jumps all over the place. I am wondering if it's because the stator wire outputs AC voltage and maybe the 4n37 can't handle that?
    Alternator output.png
    If that's the problem, it seems like I should be able to use a diode between the stator wire and the opto-isolator (in series with R2 in the schematic) (a half-wave rectifier - I looked it up!), which should basically "chop off" the negative part of the signal and have it just bottom out at 0V. That would be fine, as the ESP8266 is simply counting RISING edges. However, when I tried a 1N4007 diode, it didn't seem to have any effect on the output - see the next image:
    Alternator output with diode.png
    Questions:
    1. Is the alternator ouput in fact AC, and if so, is that causing my problem?
    2. Could it have anything to do with the fact that all the grounds are tied together?
    3. Why didn't the diode have the desired effect of setting a lower limit of 0V on the wave?
    4. Most important - what can I do? Do I need an opto-isolator that's specifically designed for AC on the input side?
    Thanks for all relevant input!
     
  2. Reloadron

    Distinguished Member

    Jan 15, 2015
    4,357
    2,119
    The alternator output is DC. The actual alternator stator outputs 3 phase AC which is on board rectified to DC. See the below image which is less the field winding and regulator guts.

    Automotive Alternator circuit.png

    Even if you pickoff the alternator using a phase to phase about all you will get is an alternator rotational speed which is not engine RPM. Depending on the automotive make and model there should be an engine tachometer sensor somewhere which would likely give you a signal more inline with what you actually want.

    Here is another example of a typical automotive alternator:
    Alternator Typical.png

    Anyway the alternator output is DC after the rectification.

    Ron
     
  3. ba58smith

    Thread Starter Member

    Nov 18, 2018
    60
    0
    Ron,

    It's not a car, it's a boat, and the tachometer output IS the stator wire, according to the alternator mfr (Balmar). The stator wire is what's driving the existing analog tachometer - it's just not at all accurate, which is why I want to create a new one. And I know it's not engine RPM, but all it takes is a simple equation to convert alternator RPM to engine RPM, which is what an analog tach does.

    But to my original question(s): can you explain to me why the oscilloscope would show the voltage alternating between positive and negative, if it's DC? When I look at bursts of DC current from an Arduino digital pin that I have progammed to pulse on and off, it doesn't look like that at all - it's 0V for a short time, then it shoots straight up to 5V for a short time, then back to 0V - over and over again. My apologies if this is an incredibly basic question, but from the reading I've done, only AC current goes back and forth between positive and negative.
     
  4. crutschow

    Expert

    Mar 14, 2008
    22,801
    6,748
    Show us the output of the optocoupler with the stator input.
    You should leave the diode in series to protect the opto input from excess reverse voltage.
     
  5. ba58smith

    Thread Starter Member

    Nov 18, 2018
    60
    0
    This is what the output from the optocoupler looks like. The more I've thought about this, the less sense it makes: if the detector side of the opto is connected to 3.3V (thru the 10K PU) and to GND (0V), how could it ever go negative? One thought: notice that the GND on the input side of the opto is connected to GND on the detector side? That seems to violate the whole "isolation" concept - I'll separate those the next time I can work on this project.
    Oscilloscope.png
     
  6. Alec_t

    Expert

    Sep 17, 2013
    10,098
    2,457
    At which point in the circuit is the scope ground lead connected?
     
  7. ba58smith

    Thread Starter Member

    Nov 18, 2018
    60
    0
    Up to this point, I don't suppose it has mattered, as I had all the grounds on the entire project connected together. As noted above, the first thing I'm going to do is separate the ground on the input side from the detector side. At that point, the oscilloscope ground test lead will go to the ground of the side being tested. I will update here after I do that, as it seems like it could make a huge difference.
     
  8. mvas

    Active Member

    Jun 19, 2017
    538
    129
    Do you have a Ground Bus Bar on your boat?
    Does the Alternator ground have a good bond to the Battery ground?
    Is there any voltage difference between your Alternator ground and Battery ground?
    Your project ( circuit Board ) should have a single point for all ground connections ( 7805 GND ) and then that point is connected to Battery Negative.
    You project should not create a secondary / parallel ground path between the Alternator and the Battery !

    3 Input wires to your project:
    1) Stator Coil to Opto (+) Input, then Opto (-) Input to project ground
    2) Battery Positive to 7805 (+)
    3) Battery Negative to 7805 (Gnd) <<< Project Ground Point

    4 Input wires ( isolated opto ) to your project:
    1) Stator Coil to Opto (+) Input
    2) Alternator Ground to Opto (-) Input but then no connection to battery (-)
    2) Battery Positive to 7805 (+)
    3) Battery Negative to 7805 (Gnd) <<< Project Ground Point
    Note: I would twist the pair coming from the Alternator.

    And you say "... the frequency jumps all over the place ..."
    Can you be specific about the change in frequency?
    +/- 5 Hz or +/- 10 Hz or ?
    How stable is your actual engine RPM speed?

    You need a clean Square Wave, you have "glitches" in your waveform.
    What is your Trigger "ON" Voltage for the Rising Edge ?
    Would a Schmidt Trigger help?
     
    Last edited: May 6, 2019
  9. dendad

    Distinguished Member

    Feb 20, 2016
    2,873
    782
    Maybe you have the oscilloscope input switched to AC coupling, not DC as there can really not be AC at the opto output.
     
  10. ba58smith

    Thread Starter Member

    Nov 18, 2018
    60
    0
    Yes.

    Yes, a good bond. No voltage difference between Alt Pos - Alt Gnd (12.79 just now) and Alt Pos - Bat Neg Bus (12.79).

    Thanks for the very detailed reply, @mvas. Can you please clarify something? "1) Stator Coil to Opto (+) Input, then Opto (-) Input to project ground" and "2) Alternator Ground to Opto (-) Input but then no connection to battery (-)". Each of these describes a connection to Opto(-); the first says connect it to Project Ground, the second says to connect it to Alternator Ground. But the second one also says "..."but then no connection to Battery(-)". It seems that in my original schematic, that's what I have. But I've modified the schematic to try to represent exactly what you said, below. Is that somehow different from the original schematic? (The battery symbol in the upper left of the schematic is actually the alternator - I couldn't find a symbol to represent an alternator in Fritzing.)
    TachSchemVer2.png
     
  11. ba58smith

    Thread Starter Member

    Nov 18, 2018
    60
    0
    @dendad, I've switched the oscilloscope back and forth between AC and DC, and it doesn't seem to do anything other than shift the wave up and down. The bottom of the wave is always negative, regardless of the setting. However, you can see "DC" in the lower left corner of all of my oscilloscope screen shots.
     
  12. KeithWalker

    Member

    Jul 10, 2017
    323
    95
    The waveform from your opto-coupler is reasonable in amplitude and shape for inputting to the arduino. In your circuit, the output can not go negative with respect to ground. I suspect that you have a zero offset on the display of your scope. What scope are you using and what display do you get when you short the probe tip to ground. It should be a straight line through zero volts.
    I think it's time to check the coding on your Arduino.
     
  13. crutschow

    Expert

    Mar 14, 2008
    22,801
    6,748
    That looks like a good signal.
    Why do you think it's not?

    Since that signal also shows a negative part, it would seen you have a scope setting/adjustment issue.
     
  14. mvas

    Active Member

    Jun 19, 2017
    538
    129
    You must select either a "3 Wire" connection OR a "4 wire" connection to your project.

    Your latest schematic looks almost like a "4-Wire ( isolated Opto ) " connection, except you have a 5th wire...
    1) Alternator Stator connects to Resistor, which connects to Opto (+) input = OK
    2) Alternator Ground connects to Opto (-) Input = OK - except for that "extra" 5th wire ?
    3) Battery (+) connects to 7805 (+) = OK
    4) Battery (-) connects to 7805 (Gnd) << Project Ground Point = OK - except for that "extra" 5th wire

    What is that "extra" 5th wire from the Opto (-) into to 7805 (Gnd) Terminal for?
    Your boat already has a connection between Alternator Ground and the Battery (-) via your Ground Bar
    So, why are you connecting another wire between Opto(-) to 7805(Gnd) ?

    The Opto(-) connects to either...
    (a) the Alternator(Gnd) using a 4 wire connection ( 2 wires to alternator & 2 wires to battery ) OR
    (b) to the Project Ground = 7805(Gnd) using a 3-wire connection ( 1 wire to alternator and 2 wires to battery )

    I think, remove that 5th wire.
    Do you agree?
     
  15. KeithWalker

    Member

    Jul 10, 2017
    323
    95
    If you are using the same 12V battery to power the alternator and the Arduino then the ground must be connected to both. The opto-isolator does not isolate the signal but it does condition the 17 Vp/p signal from the alternator so that it is suitable for connecting to the microprocessor.
    The electrical system on any gasoline engine is not an ideal environment for a microprocessor. It would be advisable to connect a pair of capacitors in parallel (100uF // 0.01uf, 16VDC working min.) between the output and ground of the 7805. This will help to minimise electrical noise.
     
  16. ba58smith

    Thread Starter Member

    Nov 18, 2018
    60
    0
    KeithWalker, now that I've played with the oscilloscope a little more, I think you're right - it's a zero offset issue. It's a DSO138 - a $25 DIY kit that works... sort of. It's too bad - I think it has the ability to display the signal pretty well, but I can find no documentation for how to actually use it, other than the very, very abbreviated ones that came with the kit. For now, I'm assuming the alternator output is DC, and that it doesn't go negative (or if it does, it's such a small bit below 0V that it's tolerable to the opto-isolator.
     
  17. ba58smith

    Thread Starter Member

    Nov 18, 2018
    60
    0
    @mvas , I didn't understand that you were telling to choose one or the other of those hookups, so I tried to make the second schematic look like BOTH of them. Doh! I modified the schematic again (below) to represent the 4-wire connection as I understand it. Does that look right? That's what I have now, actually on the project.
    Tach Schematic 3.png

    To answer your other questions from your first reply (which I overlooked), I think I had a less-than-perfect connection for my test lead when testing it at the output side of the opto. Yesterday, I was able to get the frequency on the scope to be the same, when testing the alternator side of the project (the alternator stator wire and alternator GND) and when testing the Arduino side of the project (the Arduino input pin and Project GND). If you look at the image in post #5 above, you'll see the signal going into the Arduino, which (if I had the zero level set properly) would be exactly what I want - a nearly square wave going between 0V and about 3.3. You also asked about using an opto with a Schmitt trigger, and I might do that, to give me Arduino input that's even "cleaner".
     
  18. ba58smith

    Thread Starter Member

    Nov 18, 2018
    60
    0
    Keith, thanks for the input. The engine is diesel, not gas, but your point is well taken - not an ideal enviroment for a uC. This project doesn't really use a 7805 - it uses an adjustable buck converter that has all the noise filtering built-in. (https://smile.amazon.com/gp/product/B0758ZTS61/) I just can't find an image for that converter to use in Fritzing, so I showed a 7805 in the schematic. When I have used a 7805 in the past, I have used caps, as you suggest.
     
  19. ba58smith

    Thread Starter Member

    Nov 18, 2018
    60
    0
    UPDATE: I now have a "clean" consistent pulse reaching the input pin on my ESP8266, that matches the frequency of the pulse coming from the alternator. Since that was really the point of this post, we can call this "closed". Thanks for everyone's input!

    My issue now is that the frequency that's reaching the ESP8266 input pin is NOT what's coming out of my software... but that's a software issue.
     
  20. KeithWalker

    Member

    Jul 10, 2017
    323
    95
    I just re-read the entire thread. You mention a ESP8266 wi-fi microchip but you do not show it in any of your diagrams. How is it connected?
    I have one of those. It works very well for the price. Here are the instructions for adjusting the DC offset. It's under Operations / Vpos Alignment.
    Scope.jpg
     
Loading...