PIC inputs and diode clamps and switching regulators, oh my. - Page 1
Forum section: electronics / projects

author: asgard
author_rank: Regular Contributor
timestamp: November 23, 2010, 10:47:51 pm
content: Greetings, Brue Telievers...I have a project that requires me to present sensor data to a digital input pin. The problem with that is the sensor presents a 5V signal, yet the input pin is only rated to 3.3 volts (Really 3.6v, but I don't want to push my luck).Two methods of fixing this was presented by way of a Xilinx app note. A FET with the gate to the 5v signal, source to the 3.3v supply, and the drain to the input pin is one method. The other is a diode clamp with a resistor in series tied ot the 3.3v rail with the diode tied to the 5v signal and the 3.3v input pin. That seemed like the best low-cost wayto get the circuit working. I have been down the mill with level-shifters, so that is not the right way for me.I was warned by somebody with way more brainpower than myself, that a diode clamp would cause the switching regulator (an LM3940) to shut down, since the load current would exceed the source. I "think" I can put a parallel resister across the source on the regulator to increase the quiescent current across the source so that the regulator will continue to switch, but I only have a tenuous grasp of the math here. Any tips?J.R.

author: Unknown
author_rank: Unknown
timestamp: November 23, 2010, 11:08:45 pm
content: Clamping diodes can work if you include a series resistor to limit current. You need to make sure that your diodes conduct before the internal diodes, which are often not rated for any current (hence the absolute max. input voltage of Vcc+1 diode drop or so).One solution that I like is to make it an open collector output with pull-up. Put a diode in series with the output, with the cathode facing the output. Put a pull-up resistor (few kohm or so) to 3.3V on the anode side, and connect the anode to your input. The diode will conduct if pulled low, and the output voltage will be one diode drop (use Schottky diode to limit this to 0.3V or so). If the output is high, the diode will be reverse biased, and the pull-up resistor will pull it to 3.3V. Disadvantage is that low is slightly above 0V (should be well within VILof your input), and the rise time is limited by the RC time of the pull-up resistor plus the (parasitic) capacitance of the input. I've used this successfully for 115200 baud async serial (UART), if your sensors are much faster than that, you may need an active solution.I think Sparkfun has a page with various options, and this is number three or so. The other options are either more complex or use undocumented specs of the part (eg. ESD clamping diodes, datasheets often state that they should not conduct any current, and rarely give safe limits).

author: TechGuy
author_rank: Regular Contributor
timestamp: November 24, 2010, 07:11:29 pm
content: Quote from: asgard on November 23, 2010, 10:47:51 pmYou use a 1K to 10K resistor so that the zener diode doesn't draw a lot of current.Input ---> 1K Res -+---> MCU Pin (3.3)|Zener|GNDThat said you should be able to use a 10K resistor without the zener since the resistor would limit the current to about 500 uA @5V. Which would prevent damage to the MCU pin. You can use an even larger Resistor if your sensor data output speed is low.

author: oPossum
author_rank: Super Contributor
timestamp: November 24, 2010, 07:53:08 pm
content: Many 74AHCxxx parts can accept inputs up to 5 volts while powered from a lower voltage (typ 2.5 to 3.3).The 74AHC244 octal buffer is one such part.http://www.nxp.com/documents/data_sheet/74AHC_AHCT244.pdf

author: asgard
author_rank: Regular Contributor
timestamp: November 24, 2010, 10:57:10 pm
content: So you are saying a diode clamp, such as this, would not work for me? Can a normal diode, such as a 1N4148, work?I also am trying to figure out what the resistor values, especially R1, should be to ensure the regulator turns on.J.R.

author: Unknown
author_rank: Unknown
timestamp: November 24, 2010, 11:12:15 pm
content: Quote from: asgard on November 24, 2010, 10:57:10 pmThe absolute max input voltage is Vcc+0.3V according to your requirements. The forward drop of a silicon diode like the 1N4148 is something like 0.4-0.6V, so the input will be clamped to something like 3.7-3.9V. Outside the PIC's specs. The disadvantage of this method is that you're putting two diodes in parallel, and you don't know much about the internal diodes. You could risk and it will likely work (at least for a while), but I dislike exceeding specs unlike I know what will happen. I don't usually consider myself better able to judge device capabilities than the manufacturer, so I design for worst case specs (i.e. it will blow up if I exceed the absolute max by 1mV).Quote from: asgard on November 24, 2010, 10:57:10 pm5V/R1 >= minimum regulator output current

author: asgard
author_rank: Regular Contributor
timestamp: November 24, 2010, 11:38:41 pm
content: O.K. If I blow off the discretes and use 74AHC244 buffers it simplifies everything logically, but introduces prop delay,That might be the bitter pill I must swallow for this project. But one other complication could result from the natureof the input source. This will be a rotary encoder which, being a mechanical device, could have transient surges or foreshortened pulse widths due reverse rotations. That being the case I wonder if there is a risk of getting metastabile lockups in the buffer.J.R.

author: tyblu
author_rank: Frequent Contributor
timestamp: November 25, 2010, 12:40:04 am
content: This is definitely a digital input, not analog (ADC)? The methods here are for digital'ish signals (ie: non-linear responses).

author: asgard
author_rank: Regular Contributor
timestamp: November 25, 2010, 05:44:55 am
content: The input is bitonal, but the source (the sensor) is (probably) not. It is going to be a simple phototransistor or photodiode. Since the sensor is as cheap as I could budget I don't think the maker would spec a photo-Darlington device or somesuch. Therefore, I expect to see a considerably lower-magnitude slope than is typical for TTL-level signals. In addtion, the pulse width of the signals are by necessity random in duty cycle due to the direct mechanical linkage with the sensor. It could be all worry over nothing, since the speed of the signal is going to be low, but randomness means the possibility must be designed against since the buffer would not be able to recover from a metastable lockup and so the MCU could get spurious transitions.J.R.

author: oPossum
author_rank: Super Contributor
timestamp: November 25, 2010, 05:49:57 am
content: 74AHC14 hex Schmitt trigger inverter may work well with an encoder.http://www.nxp.com/documents/data_sheet/74AHC_AHCT14.pdf

author: dfnr2
author_rank: Regular Contributor
timestamp: November 26, 2010, 08:58:40 am
content: I agree, you need a schmitt trigger on each channel to ensure a reliable response. However, before designing in the 'HC14, you will need to check out the waveform and make sure that the dead zone of the 74hc14 is well within the detector output range under all conditions. Otherwise you will get valid TTL signals that don't accurately reflect the quadrature behavior. In that case, you would be better off using a dual op-amp configured as two schmitt triggers (one per detector). You can then set the trigger points to whatever voltage you want. Tie the open-collector outputs up to 3.3V with a resistor much smaller than the feedback divider network. This will stabilize and square up the quadrature signals. Any workaday comparator such as an LM2903 will work fine. You can do the detection in software if you hook the conditioned detector signals to some "change on interrupt" pins, or if your software has other stuff to do, you can use one of the great encoder chips from usdigital (http://usdigital.com/products/interfaces/ics/) with up/down outputs hooked up to counter increment inputs on the uc.These encoders actually incorporate schmitt triggers, but unless the dead zone is perfect for your application, you're better off making your own schmitt trigger anyway.By the way, if your quadrature detector is a couple of phototransistors or whatever, what's to keep you from just powering them (and the LED's) with the 3.3V? Then you could avoid having two supplies. You'd still want a schmitt trigger, though.Dave