Protecting a microcontroller's input line

Discussion in 'The Projects Forum' started by someonesdad, Mar 11, 2011.

  1. someonesdad

    Thread Starter Senior Member

    Jul 7, 2009
    1,585
    141
    I'm designing myself a "simple" continuity tester. There will be a 200 ohm pot on the PC board that will be the "resistance standard". A PIC processor will apply voltage across the pot and measure the analog voltage on the wiper. Then it will apply voltage to the unknown resistance on the input leads and measure the voltage drop across that resistance. If the voltage drop across the unknown is less than or equal to the voltage across the pot's wiper, then a signal will turn on (either an LED or a piezoelectric beeper or both). A DIP switch will allow you to invert the sense of the test. Basically, I want a continuity tester that lets me adjust the definition of "continuity". There will be some pulse stretching in software to help find those momentary shorts.

    I intend to use this for quick troubleshooting around the bench, the house, and the car. It will be in a small package that easily slips into a pocket so that it's handy to carry around. I also have a small analog meter (10 mm in diameter and 15 mm long) that I will use to make DC voltage measurements up to 15 volts.

    I would like to protect the microcontroller's input lines in case I accidentally put it across a significant voltage -- say, up to typical US line voltage levels. If I were to use a fuse, it would probably have to be a fast-blow fuse rated to around 10 mA or so (and I don't know if such things exist). The problem with a fuse is that if it blows in the field and you don't have a spare, you're shut down until you can get one. I was hoping there would be a simple and low power method of protection

    Question: what method would you folks recommend to protect the input line?
     
  2. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    A zener diode?
     
  3. someonesdad

    Thread Starter Senior Member

    Jul 7, 2009
    1,585
    141
    I see the benefit of having a zener on an input line, as it will clamp an input by conducting when its knee voltage is reached. But I'm worried that if the zener gets blown (and behaves as an open circuit), then its protection is lost.

    I've attached a diagram of what I'm considering for a design.

    To measure the unknown resistance Rx, the port A would go high to approximately Vdd. To keep the output current to less than 25 mA, R will be 40*Vdd ohms. Then port B will be configured as an analog input and will measure the voltage across Rx. This will be used to calculate the value of Rx.

    What I'm worried about is that the resident maladroit will substitute line voltage for Rx. The circuit's ground is not earth ground, as it will be a battery-operated device, so there's no worry about a line to ground short. I'm worried that the application of such a voltage (or e.g. a 20-30 volt DC voltage or higher) would blow the input protection on the microcontroller.

    I'm looking for a simple way to protect these pins from such maladroitness.

    I could protect port A by using a small signal transistor in a socket and keeping a few transistors in the box as spares.

    Since B will be an analog input, it will be a reasonably high impedance. Should I just put e.g. a 10 kohm resistor in the line and call it good?
     
  4. Wendy

    Moderator

    Mar 24, 2008
    20,764
    2,534
    Couldn't hurt. You could also use the standard CMOS protection used by chip manufacturers. It the voltage exceeds Vcc or Gnd they conduct, and the surge is routed to the power supply.

    A good example is shown on page one of the 4060 PDF datasheet.
     
  5. mjhilger

    Member

    Feb 28, 2011
    119
    16
    I have the A/D section pulled up for an 18f4525 and looking at the input it specifies an input impedance of 2.3K. It has internal diode protection to the rails already. I'm thinking if you really want a robust design and it will be battery powered (also assuming low bandwidth); I would suggest that you use a very large input resistor say 500K and add an op-amp with a pass through (gain of 1). Because the op-amp has a very high input resistance as well, very little current will pass through the resistor and even if the voltage applied is 100+ volts, (BTW I would also put diodes on the op-amp input as they have already suggested) because of the small amount of current, virtually no damage can result. You would want to use a very high voltage transistor to provide the voltage to the unknown, and in your program before you apply the voltage, check from the A/D (you probably want to make a few checks in a row to make sure you don't catch AC at a low crossing point) to make sure it is safe (dont want to apply your battery to 110 vac or so - could make for a bad day)
     
  6. someonesdad

    Thread Starter Senior Member

    Jul 7, 2009
    1,585
    141
    Thanks, mjhilger. I remember reading somewhere a warning about not letting the impedance of the input to the analog in ports get above 10 kohm and that's the maximum recommended by the processor's spec sheet. I was hoping to avoid another external active component, but your recommendation of using an op amp does make sense.

    It then occurred to me that this whole thing might be simpler to do with an analog circuit using a chip like the LM339 quad comparator. It wouldn't have the "feature tunability" that a microcontroller solution might, but it could be built pretty quickly and give me what I want. I've attached a sketch I made yesterday.

    Using a 9 volt battery, I'd then see if I could find something to provide a reasonably-regulated 0.25 volts. This is the voltage that would go across the unknown resistance (and I want it around a quarter of a volt to keep from turning on any junctions). Then if the voltage is appropriate, the comparator turns on either the LED or the sound or both. I have a fantastic little red LED (I wish I knew where I got it), as it's adequately bright for indoor work at 2 or 3 mA, quite bright at 10 mA, and blindingly bright at 20 mA. Thus, I've shown a two pole DIP switch I'll use to select the LED brightness.

    I'll also use a square wave oscillator in the LM339 data sheet to drive the piezoelectric device -- this piezo device takes about 0.5 mA at 2.4 kHz to produce a nice sound at 3 volts.

    I'm still not sure which approach I'll use yet. The PIC design can be quite simple, as all that's really needed is the PIC chip itself. I've got a tube of 5 of these PIC chips, so if I blow one, I can keep a programmed spare in the box and just stick it in the socket if I blow the first one.

    The analog solution uses more parts, but it's also easy to replace the LM339 if I blow the thing up.

    To review my goals for this continuity tester, I want it to either use an LED or beeper or both for indicating continuity. I also want to be able to adjust the resistance that is considered continuity from around 1 ohm up to one or a few hundreds of ohms. I'd also like to stick it in a tiny box if possible; the two protruding banana jacks will probably be the biggest part of it. :p If I use the PIC, then I can probably make it using a single CR2032 lithium cell.

    Any other designs you folks would recommend?
     
  7. mjhilger

    Member

    Feb 28, 2011
    119
    16
    Your 339 design will do as you have described, but I thought one of your design goals was to survive a 110v connection? It could still be done with the 339 (since there are 4 in a package), but might take a little work. I do think you should provide some protection if you believe you might EVER accidentally get it connected to 110v. I think you might be holding a small bomb if it gets connected the way it is currently designed. Also, do you understand how to build a constant current source? Using a current source to supply to your unknown can provide a lot of advantages, and you can design the upper voltage which could be presented to the external component. The diode setting on most DMM meters work this way, then you see the voltage across the diode at X uA's.

    Since the PIC's became available, I have been a big fan. Customers always want more, so the analog approach works, but if the scope of the product changes after the initial design, the customer is looking at a virtually complete redesign for added functionality. The PIC (provided you leave yourself some pins, and processing room) can usually accommodate a fairly high level of added functionality when the product is moving to V2.0. There is always another use or stretch for a product once its in the customers hands.

    Since this is your baby, you call the direction. And I'm sure the 339 design will work for you. But I'll bet you $1 within 60 days of use (if you use it often) that you will think of another use if it only had ........ This is not to say that you can't still add that functionality, but just food for thought.
     
  8. someonesdad

    Thread Starter Senior Member

    Jul 7, 2009
    1,585
    141
    Actually, the LM339 approach was suggested by the desire to keep the probing voltage low to avoid turning on a junction. But that's a want, not a must. Surviving a connection to line voltage is also a want, not a must. This thing is just for use on my bench and troubleshooting around the house, so it will never evolve into a product.

    The motivation for it is based on two desires: 1) a simple device in a lightweight and small package and 2) a beeper that can be heard by me (I have hearing damage from guns in the 60's and I can barely hear the continuity beeper on my Fluke multimeter). I've salvaged a nice piezo beeper that has a nice resonance around 2.24 kHz and I'll make use of it (my hearing stops at 2.9 kHz).

    One thing that bugs me about my multimeter is that dealing with leads has always been a PITA. My son-in-law showed me a little Fieldpiece DMM he got for $20 that stores its leads in the back and I've always wanted something like that. So one of the things I'm considering is building the thing in an old eyeglasses case (my optometrist gave me a whole bag full of them a number of years ago) and the leads would get stored in the case too. But, I've already got an Altoid tins with two banana jacks and a switch mounted on it (from a defunct older project), so it's tempting to reuse that.

    Since I have a supply of 16F690 PICs, I'll probably just go with the PIC solution since it's probably the easiest to get up and running and uses the fewest parts. And, you're right about the convenience of the microcontroller -- it makes it easier to add features later.
     
Loading...