Page 1 of 1

opto isolator or optocoupler read engine speed

Posted: Mon Jun 25, 2018 7:38 pm
by ahlis_se
Hello All,

There are many threads about optocoupler how to´s and so on. Still I cannot find a recommended optoisolator for the most common applications like reading a 12V signal.

I realised that I may have jumped the gun a bit purchasing an ILD213T as it consumes a bit too much current, I think.
https://www.vishay.com/docs/83647/ild205t.pdf
or exactly this one https://www.sparkfun.com/products/9118

I would be very happy if I can get some help how to wire this to a raspberry pi 3 B+, pin to pin.
What I am trying to achieve is to read engine speed from CDI ignition system on a 4 cylinder engine with a 12V electrical system ( signal voltage can be between 10-14.4V as in any car )

thanks for a great forum

Re: opto isolator or optocoupler read engine speed

Posted: Mon Jun 25, 2018 8:23 pm
by wh7qq
If the signal is, as you suggest, between 10-14 volts, you can easily build a circuit to provide a safe current to the optocoupler's LED...just a dropping resistor to the anode and ground the cathode. Be sure not to exceed ~20 ma to the diode but much less is fine...a 750 ohm resistor should do here, maybe even 1K. The GPIO side is almost as trivial...tie the collector to the GPIO pin and to a pull-up resistor to the 3.3 volt supply. Do not use the 5 volt supply for this. The emitter goes to ground. The GPIO pin is limited to around 15 ma but it will require much less, so a 1K, 1/4 watt resistor will do nicely. There are other ways this can be done...potatOH, potAHto. This is probably the simplest with fewest bits. Resistor values are not critical here so you can experiment a bit if you wish.

Be very careful in the voltage range you quoted...if it is a voltage spike, then it could be much higher than you say unless you have a scope or a peak reading meter.

Re: opto isolator or optocoupler read engine speed

Posted: Mon Jun 25, 2018 10:23 pm
by rpdom
wh7qq wrote:
Mon Jun 25, 2018 8:23 pm
If the signal is, as you suggest, between 10-14 volts, you can easily build a circuit to provide a safe current to the optocoupler's LED...just a dropping resistor to the anode and ground the cathode.
Maybe put a zener diode across the optocoupler's LED to limit the forward voltage to a safe level. That'll protect against sharp spikes.

Re: opto isolator or optocoupler read engine speed

Posted: Tue Jun 26, 2018 9:15 am
by ahlis_se
wh7qq wrote:
Mon Jun 25, 2018 8:23 pm
If the signal is, as you suggest, between 10-14 volts, you can easily build a circuit to provide a safe current to the optocoupler's LED...just a dropping resistor to the anode and ground the cathode. Be sure not to exceed ~20 ma to the diode but much less is fine...a 750 ohm resistor should do here, maybe even 1K. The GPIO side is almost as trivial...tie the collector to the GPIO pin and to a pull-up resistor to the 3.3 volt supply. Do not use the 5 volt supply for this. The emitter goes to ground. The GPIO pin is limited to around 15 ma but it will require much less, so a 1K, 1/4 watt resistor will do nicely. There are other ways this can be done...potatOH, potAHto. This is probably the simplest with fewest bits. Resistor values are not critical here so you can experiment a bit if you wish.

Be very careful in the voltage range you quoted...if it is a voltage spike, then it could be much higher than you say unless you have a scope or a peak reading meter.
Hmm Other ways this can be done, a more recommended way ?

Currently I have got together a simple Throttle position reader using a potentiometer to read position I have connected a MAX3232 serial port to connect a wide band Lambda reader and the last bit is the rpm. Would be nice to add ignition timing advance reading too, the electronics are simple I think, the translation from movement to degrees is a little harder and a lot more sensitive than the throttle positioning.

All of this is to be written into every tenth of a second a .CSV file for me to analyse and change jets accordingly to a Weber carburettor.

If I have read you correctly, wiring should look something like this to connect the optoisolator to the pi. I think I would be ok to set a 1500Ohm resitor on the 12V side too, I prefer to miss a few readings compared to burn my pi (optoisolator is spendable thou.. )
Sparkfun optoisolator D213T.jpg
Sparkfun optoisolator D213T.jpg (149.85 KiB) Viewed 1025 times
If I am to put a zener diode in this where do I put it ?
how can I ensure not to exceed 20mA?
I think there are already fitted resistors on the other side of the ciruitboard.
09118-03.jpg
09118-03.jpg (239.97 KiB) Viewed 1025 times
I have a powerbank sourcing 3.1A@5V to power the raspberry pi in the car tested and working, still todo is to fit att socket to the potentiometer and extend the cable to the engine and attach the serial socket to the pi casing.
20180625_214758.jpg
20180625_214758.jpg (166.49 KiB) Viewed 1025 times
Thankyou for taking time to help out with my questions.

//ahlis

Re: opto isolator or optocoupler read engine speed

Posted: Tue Jun 26, 2018 12:10 pm
by Z80 Refugee
I recommend you look at published rev counter (tachometer) or timing light circuits and see how they pick up the ignition pulses. IIRC they use induction pickup from the HT leads and thus avoid any nasty energy spikes.

Re: opto isolator or optocoupler read engine speed

Posted: Tue Jun 26, 2018 12:56 pm
by ahlis_se
Z80 Refugee wrote:
Tue Jun 26, 2018 12:10 pm
I recommend you look at published rev counter (tachometer) or timing light circuits and see how they pick up the ignition pulses. IIRC they use induction pickup from the HT leads and thus avoid any nasty energy spikes.
Hello Z80 Refugee,

thanks for the response.
The use of induction on HT leads is an option but not preferred as when everything jumps around there is a risk of malfunciton. As the engine built produces twice the power compared to a standard engine I would prefer to keep the ignition system as it is to avoid any ignition related issues.
Currently it is fitted with a CDI ignition system using a Hall effect. This box actually provides a 12 V tacho signal. Still being in a car there is absolutely no guarantee it will be 12V at all times as the alternator will charge between 13.8-14.4V if it is as it should be. Most car electronics survive short spikes up to 16-20 Volts depending on the age of it and depending on how far away it is from the source of the spike( and the amount of electronics in it of course).

Dips are to be expected, when the electric cooling fan starts it will draw a lot of current causing voltage drop to about 10.5-11 Volts for a brief moment. To be on the safe side, any given auto will have a Voltage between 10-14.4V it may go above that if something goes wrong with the generator but this usecase can be excluded.

I believe that the optoisolator will work between 1-7 Volts if I read the spreadsheet correct from Vishay, this should give a lot of room to survive a voltage spike.

I need help with is to understand how to wire it. I am a good mechanic, but not very good with micro electronics ;-).

Re: opto isolator or optocoupler read engine speed

Posted: Tue Jun 26, 2018 3:53 pm
by Z80 Refugee
ahlis_se wrote:
Tue Jun 26, 2018 12:56 pm
The use of induction on HT leads is an option but not preferred as when everything jumps around there is a risk of malfunciton. As the engine built produces twice the power compared to a standard engine I would prefer to keep the ignition system as it is to avoid any ignition related issues.
Well, your concept is wrong there. Using an inductive pickup avoids interfering with the ignition electronics.
ahlis_se wrote:
Tue Jun 26, 2018 12:56 pm
Currently it is fitted with a CDI ignition system using a Hall effect. This box actually provides a 12 V tacho signal.
So it should be easy then, even for a novice.
ahlis_se wrote:
Tue Jun 26, 2018 12:56 pm
Still being in a car there is absolutely no guarantee it will be 12V at all times as the alternator will charge between 13.8-14.4V if it is as it should be. Most car electronics survive short spikes up to 16-20 Volts depending on the age of it and depending on how far away it is from the source of the spike( and the amount of electronics in it of course).

Dips are to be expected, when the electric cooling fan starts it will draw a lot of current causing voltage drop to about 10.5-11 Volts for a brief moment. To be on the safe side, any given auto will have a Voltage between 10-14.4V it may go above that if something goes wrong with the generator but this usecase can be excluded.
If you need this not to die under any automotive circumstances/mishap, you need to allow for the possibility of 50V excursions in the supply including negative. Manufacturers electronics systems in cars are designed to withstand this.
ahlis_se wrote:
Tue Jun 26, 2018 12:56 pm
I need help with is to understand how to wire it. I am a good mechanic, but not very good with micro electronics ;-).
You're right there, the first thing we needed to see is the circuit diagram: https://www.sparkfun.com/datasheets/Bre ... or-v12.pdf

This shows the opto-isolator IC being used the opposite way round to what you intend, but it clarifies things considerably. On the RPi side connect HV and HV-GND to 3.3V and 0V on the GPIO respectively. OUT1 can then go straight to a GPIO input (and so can OUT2, if you want a second channel). This is what you have already shown in your sketch.

On the input to the breakout board, the LEDs in the 2-channel opto-isolator are simply driven directly, via 220ohm resistors. Thus the inputs are current (not voltage) driven, and all you need to do to adapt them to a particular voltage is choose the right resistor. Get rid of the resistor you have shown connected between the breakout GND and your car 0V, just connect it directly.

1k "feels" about right for the other resistor, but all you need to do is get a simple program running on the RPi to monitor the input, and see if it reads properly when you put 12V on the opto. If it doesn't switch, or doesn't switch fast enough, decrease the resistor a bit (but not much).

To protect the opto from voltage excursions, wire a 4.7V Zenner diode between IN1 (cathode) and GND (anode).

There should be no direct connection between HV-GND (RPi 0V) and GND (car 0V).

Re: opto isolator or optocoupler read engine speed

Posted: Wed Jun 27, 2018 7:05 am
by ahlis_se
Z80 Refugee wrote:
Tue Jun 26, 2018 3:53 pm
ahlis_se wrote:
Tue Jun 26, 2018 12:56 pm
The use of induction on HT leads is an option but not preferred as when everything jumps around there is a risk of malfunciton. As the engine built produces twice the power compared to a standard engine I would prefer to keep the ignition system as it is to avoid any ignition related issues.
Well, your concept is wrong there. Using an inductive pickup avoids interfering with the ignition electronics.
ahlis_se wrote:
Tue Jun 26, 2018 12:56 pm
Currently it is fitted with a CDI ignition system using a Hall effect. This box actually provides a 12 V tacho signal.
So it should be easy then, even for a novice.
ahlis_se wrote:
Tue Jun 26, 2018 12:56 pm
Still being in a car there is absolutely no guarantee it will be 12V at all times as the alternator will charge between 13.8-14.4V if it is as it should be. Most car electronics survive short spikes up to 16-20 Volts depending on the age of it and depending on how far away it is from the source of the spike( and the amount of electronics in it of course).

Dips are to be expected, when the electric cooling fan starts it will draw a lot of current causing voltage drop to about 10.5-11 Volts for a brief moment. To be on the safe side, any given auto will have a Voltage between 10-14.4V it may go above that if something goes wrong with the generator but this usecase can be excluded.
If you need this not to die under any automotive circumstances/mishap, you need to allow for the possibility of 50V excursions in the supply including negative. Manufacturers electronics systems in cars are designed to withstand this.
ahlis_se wrote:
Tue Jun 26, 2018 12:56 pm
I need help with is to understand how to wire it. I am a good mechanic, but not very good with micro electronics ;-).
You're right there, the first thing we needed to see is the circuit diagram: https://www.sparkfun.com/datasheets/Bre ... or-v12.pdf

This shows the opto-isolator IC being used the opposite way round to what you intend, but it clarifies things considerably. On the RPi side connect HV and HV-GND to 3.3V and 0V on the GPIO respectively. OUT1 can then go straight to a GPIO input (and so can OUT2, if you want a second channel). This is what you have already shown in your sketch.

On the input to the breakout board, the LEDs in the 2-channel opto-isolator are simply driven directly, via 220ohm resistors. Thus the inputs are current (not voltage) driven, and all you need to do to adapt them to a particular voltage is choose the right resistor. Get rid of the resistor you have shown connected between the breakout GND and your car 0V, just connect it directly.

1k "feels" about right for the other resistor, but all you need to do is get a simple program running on the RPi to monitor the input, and see if it reads properly when you put 12V on the opto. If it doesn't switch, or doesn't switch fast enough, decrease the resistor a bit (but not much).

To protect the opto from voltage excursions, wire a 4.7V Zenner diode between IN1 (cathode) and GND (anode).

There should be no direct connection between HV-GND (RPi 0V) and GND (car 0V).
Many Thanks, this is just what I was looking for.
i will post here again and let you know if I fried it or got it working :-)