Electronic – Industrializing a PIC micro-controller

24vmicrochippicplc

I want to replace some timers with a PIC16F887 micro-controller. The problem is that the input voltages to the I/Os is going to be 24V which is too much. For the output part I was thinking about using a relay module. I'm stuck on the input part. How can I use the 24V as a input to the micro-controller?

The application is simple. When a input pin goes high the output will be enabled after a certain period of time (When 24V is received from the input the output will send 24V in other words). The time will be adjustable trough some push buttons. The times will be displayed on a LCD.

This question is tied to a different question I asked from the forum before. A user recommended a similar cheap solution which is already made but I want to build one just for a personnel project.

Best Answer

I don't know why you're using such a ancient PIC in a new project, but there is no reason it shouldn't work.

Scaling 24 V signals down to 5 V is as easy as a resistor divider. Something like this should work:

The resistors attenuate 24 V to about 5 V. The zener guarantees the voltage into the PIC is within what it can handle because stuff happens. The zener will also clip negative spikes, but to one diode drop, which is right about where the PIC starts misbehaving.

If you are really worried about negative spikes, then you can put a Shottky diode across the zener just to clip negative voltages. Or you can break up R2 into two resistors that attenuate a bit after the zener, and use a bit higher voltage zener to compensate.

There are lots more things you can do. It depends on how much you want to protect against. More protection will add complexity and cost, but robustness to ever less likely abuse. Only you can decide what the right tradeoff is.