Filter signal to optocoupler

Discussion in 'Embedded Systems and Microcontrollers' started by PZUFIC, Dec 7, 2015.


    Thread Starter Active Member

    Jan 7, 2012

    I'm using Raspberry Pi 2 in a production environment. I'm also using GPIO on the Pi. There are some problems with inputs and noise. Input signals are
    24 V DC and they are driving the optocoupler LED trough resistor. Optocoupler then just switches gpio pin to ground. Presence of noise sometimes triggers Pi input trough optocoupler. For now I solved this issue inside program but if it's posible I want to further solve it with hardware. The noise has a pretty decent amplitude about 10 V and it last for about 1 ms. This was measured before we changed the communication (GPIO) cable between the GPIO board and PLC with shielded one. Noise is produced while TIG welding on the same machine.

    For now I solved the problem by software and it works well, but is there any option to do that with hardware? For instance, even the PLC had some troubles with noise and they were also solved by the program, so i wonder if it's even possible to effectively and simple filter this out by hardware.

    I just used TLP521 and 3k3 resistor in series with diode. I knew that this is not the best option, so just to be safe for other projects (even if it won't help for this case), how the optocoupler driving circuit should be made?
  2. Papabravo


    Feb 24, 2006
    I think you might have better luck eliminating the source of that transient. Does it cause a low level to pop up by 10 volts, or does it cause a high level to drop from 24 volts to 14 volts. A Schmitt Trigger might help with the problem. It creates a dual threshold for changing logic states. For example, a low requires a transition from 24 volts to less than 5 volts, while a high requires a transition from 0 volts to greater than 18 volts. The input can wander around in the range of 5 to 18 volts all day without changing state. This should go on the input to the optos, assuming you have all your other bases covered.

    A couple of final questions; how economical was using non industrial hardware for a production process? Could you have used industrial grade equipment and avoided this problem? If you had it to do over would you make the same choices?
    PZUFIC likes this.
  3. JohnInTX


    Jun 26, 2012
    PB makes a good point i.e. try to minimize / eliminate the noise at the source with shielding, proper grounding etc.
    You might try a resistor across the LED inputs. This will create a current threshold for the LED input that can help by swamping low-energy transients.
    Your solution to fix it in firmware is excellent. Even with the best intentions, transients can get by the hardware and its up to the firmware to filter signal from transient. I always use both approaches. I would leave the firmware in even as you get the hardware cleaned up.
    Good luck.
    PZUFIC likes this.

    Thread Starter Active Member

    Jan 7, 2012
    It's an older machine which uses TIG welding and now we install a machine vision application for checking the parts on it. TIG has a positive pole on a chassis. There were some problems with bad connections and we solve it. Otherwise I don't know how and where to search for problems. We also put a Rpi and dependencies in a metal case, change the cable between PLC and machine vision system with shielded one and install EMC filter on main, before power supply for Rpi.

    System work fine for now (knock on the wood). In future I will replace GPIO board, with new one. Currently I'm using relays for outputs and I want to change that with FETs. Optoisolation is already present on the board so all the grounds are separated. So at that point I want to enhance the inputs to.

    It causes low level to pop up, but there is also some noise in the power supply for Rpi. Rpi has it's own power supply which is connected to main trough EMI filter. Ground of machine and ground of Rpi are not connected together, except trough the DVI cabel and trough camera cases which is hard and expensive to totally isolate.

    It seems that the problem is very complex and it's not solved totally, but the system work fine as it is for now. Because the machine itself works fine it's hard to change things, especially because machine mostly works all day. Leave it alone until it works. ;)

    We were trying to solve noise problems for weeks and at the end we solve it in firmware, I know that it's not the best solution so for future projects I just want to make my hardware more robust with better design event if it won't help for this problem.

    I was searching for that, but I wonder are there any integrated circuits for that purpose on 24 V, or I have to make it with discrete components?
    I saw just TTL ones.

    Hmm... We have good experiences with Rpi in production environment for scanning and checking bar-codes so why not to try and use it for machine vision. If it fails somewhere between development we just change it with industrial grade PC. It was actually working fine until we mount the system on a production line. But we kind of solved the problems and I think that in my opinion noise problems can occur on a industrial PC to.
    We learned a lot from that project. Of course now we would make some things differently at the start instead changing trough the process of development but I think that we would and probably we will use almost the same setup.

    Ok, what about the value?

    At the end I just need some well tested and used approach for driving optocoupler LED. I know that I probably won't get rid of all noise with hardware, but solution with just one resistor is probably not the best approach for industrial applications.

    Thank all of you for help.
  5. Papabravo


    Feb 24, 2006
    The best way to make a Schmitt Trigger is with an LM339(quad) or LM393(dual) comparetor. The inputs are 0-24V and the output is open collector, you pull it up to 3.3 Volts or 5 Volts or whatever your logic supply is.

    Your system is too complex to be described verbally in a forum post, but you might want to get somebody, who does understand EMI and fast transients, to help you since you seem to be at sea when it comes to this stuff. If for no other reason than to verify that you've covered all your bases.
  6. Involute

    AAC Fanatic!

    Mar 23, 2008
    You might also try putting a 5.1V zener diode on the input to the optocoupler (with appropriate series resistor). This should clamp transients to 5.1V.