It’s my understanding that NPN style sensors sink to ground. I.e. - if you plug the signal cable of a NPN into the roborio DIO, it will pull the signal pin to ground and roboRIO will “see” it.
How would you go about hooking up a PNP sensor to the roboRIO?
RoboRio DIOs have a pullup resistor, which is why connecting an NPN directly to them can work. To make a PNP output to it, you basically need to reverse this situation. Connect a pull-down resistor from the signal pin to ground, then you can connect your PNP output to the signal pin as well. Your pull-down resistor will have to be low enough resistance to overcome the pullup resistor, but high enough resistance that your PNP output will still drive the volts high enough to register as a high level on the DIO.
For DIO 0-9 and DIO 0-13 on the MXP with the 40kohm resistors, a pull down of 10k would barely be enough, 5k pulldown would be safer.
An important caveat is that this only works with 5V PNP sensors. A 12V PNP output is going to blow up your DIO port unless you use a more complicated circuit.
yes, you can voltage divide down your 12V PNP to get a 5V output. you can buy this board if you want, but its also easy to do with soldering a few resistors.
Pay particular attention to this as many common PNP sensors output the same voltage they are supplied with, which is typically 12V or more for the sensor to function (5V is not a common supply voltage for industrial environments that are the target market of most sensors).
Another option is to use an interposing relay to convert from PNP to NPN. Get a relay with a coil rated for the output voltage of the sensor, connect the signal wire of the sensor to the positive coil lead and a common wire to the negative coil lead. Then connect the RoboRio input to the NO lead of the relay output and a common wire to the common lead of the relay output (these will be the only leads on a SPST relay, make sure to use NO and common if using a SPDT relay). You can use this same method to convert between different voltage levels also (using a 12V PNP sensor to trigger a 5V sinking input, just have to feed 5V to the common side of the relay output).
Unless I am missing something on that voltage divider, it’s going to try to output 5V, which still makes it PNP. That won’t work for feeding the RoboRio inputs that expect an NPN style sensor.
A more reliable way than relying on a voltage divider and two resistors pulling against each other is to use an opto-isolator with a NPN output to invert the signal. That is basically the same thing that Donut is saying, but just doing with a solid state device instead of a relay.
Also be away that a sensor with an NPN output may not pull the voltage down low enough for a logic low into the DIO port of a roboRIO. Last year we used some QM series reflective sensors from Automation Direct that only went down to around 1.7 volts. We had to run them through opto isolators to get a good logic low, which is generally 0.7 volts or below.
I’m hesitant about that without my Art of Electronics to remind me about transistor fundamentals. I think that’s alright, but you should have high values for the resistors. Probably dividing down till the base voltage is less than 3.3V. If I remember correctly, an NPN has a diode from base to collector which would be forward biased if you drive the base with more than 3.3V. Which I think would be bad, or atleast wouldn’t work properly.
That’s fascinating information, where did you find it? The RoboRIO specs that I looked at when formulating my answers stated 5.25V max for the logic high of the DIOs, with no mention of a max voltage. The analog IO is listed as ±16V protection, but there’s no reason to assume that carries over to the DIO.
You can use an NPN BJT with a single series resistor of high enough resistance to limit the base current. I don’t think the voltage divider is necessary.
You can also use a FET with a pull-down resistor on the gate. This is what I would pick. The resistor value doesn’t matter, as long as the current through it isn’t higher than the limit for the PNP in the sensor.
During Alpha testing, NI covered some design info. They talked about the protections they were incorporating and I remember them talking about the protections incorporated. I’ve got an Alpha Rio lying around I can attach a battery directly tonight to demonstrate (if I’m wrong and it fries, I won’t care).
Remember that survivable voltage is different than functional voltage. The RoboRIO was designed to survive battery voltage on any pin, but those pins may or may not be functional until the battery voltage is removed.
True, but that’s typically the power rails which self protect, not the signal inputs.
Was able to test last night. Unfortunately the web interface had become corrupted and wasn’t able to get status messages. I did connect battery voltage (~12V) to the DIO signal line and no smoke occurred. Checked DIO voltage & expected signals afterwards and it was still operating as expected, no apparent damage. Will see if I can get it to talk.