Circuit to drive Wiegand output - Page 1
Forum section: electronics / beginners

author: jfuu_
author_rank: Newbie
timestamp: September 03, 2024, 10:52:33 am
content: I'm working on a design to drive aWiegand outputvia a microcontroller (3.3V logic).My only real requirement for the output is that it has protection to ensure nothing bad happens if an output is connected incorrectly (e.g. it is accidentally shorted to GND or connected to 12V). I'm not expecting the output to be connected incorrectly for long periods, I just want to protect against incorrect installation.I initially designed it to use an NPN transistor like so:But I received a suggestion on Reddit to use a MOSFET instead, as disconnecting WIEGAND_OUT_D0 (or connecting it to a high-impedance input) would result in only 0.5mA through Q5, leading to a slow fall time.I've updated the design to use a 2N7002 MOSFET and also added some protection inspired by the first 3 methods listed onhttps://www.rugged-circuits.com/10-ways-to-destroy-an-arduino:Is this suitable for my needs? Here's how I decided on the values for the components (please tell me if my thinking is wrong!):R46- Some sources say a gate resistor isn't needed, but I foundthisStackExchange answer indicating otherwise. I want to draw a maximum of 5mA from GPIO22, so I used Ohm's law to get R = 3.3V / 5mA = 660 Ohms (rounded to nearest available resistor value)R47- There's not much information online about the required pull-up resistors for Wiegand. I've got a device with a Wiegand output and that uses a 10K resistor (although they also drive the output directly from the uC), so I just followed that. My understanding is that the strength of the pull-up will mainly affect the maximum cable run length, so I may end up adding some switchable resistors using DIP switches to allow the end user to adjust the pull-up for their application.F2- In some cases, Wiegand devices may be connected to the same D0/D1 pins (like I2C), so I added a 100 Ohm resistor here to limit the current coming from other devices to 50mA (at 5V). I've not specified the trip current in the schematic, but I'm thinking of looking for a part with ~100mA of trip current.Q6- I don't really know much about choosing MOSFETs for my application - this one showed up on Digikey and the 2N7002 seems to be a jellybean-ish component which should switch at 3.3V.Thanks!

author: PGPG
author_rank: Frequent Contributor
timestamp: September 03, 2024, 02:48:29 pm
content: Quote from: jfuu_ on September 03, 2024, 10:52:33 amWiegand is not the fast transmission connection so I don't understand this suggestion (specially - what is the problem if disconnected).Quote from: jfuu_ on September 03, 2024, 10:52:33 am2N7002https://www.mouser.pl/datasheet/2/916/2N7002NXAK-1623722.pdfwill be working correct but ...I would never use this transistor controlled by 3V3 source. It is because RDSon is specified only for 5V and not for 3V3. Gate threshold (max 2.1V) is defined for Ids=250uA so it is not a voltage that switches transistor seriously on but the voltage that starts to switching it on. You can conclude from Fig.8 that 3V switches it on enough good (for lower voltage - we can't be sure). But it is clearly written that it is for typical values. If Gate threshold is 1.1-2.1 than typical I assume 1.6V. So if from Fig.8 I read 3V is enough than for worst case (Vgs threshold of 2.1V) I would say 3.5V will be enough. And, assuming some tolerances your 3V3 can be 3V2...Of course in 99,99% situations it will be working.I don't know what you have at output. It is 100R resistor, 100mA PTC or a resistor with PTC functionality included (I have never heard of such devices but that doesn't mean they don't exists).If it is PTC than have in mind that PTCs are very slow. If you connect 12V (what for human is a moment for electronic is everlasting) your question is what power will be in PTC and what in Zener and which of them will win.You can configure your output as current source to limit power released in output transistor when connected to 12V.

author: T3sl4co1l
author_rank: Super Contributor
timestamp: September 03, 2024, 03:19:34 pm
content: Surely they meant rise, not fall: the transistor turns on as hard as it does regardless of resistor, producing a short fall time. The rise can only be with the transistor off as suddenly as possible, followed by an RC time constant as the collector/drain capacitance charges up.Which might be a good reason to prefer BJT over MOS: you can get smaller ones, i.e. smaller die --> less junction area --> less capacitance.A 3.3V compatible jellybean is BSS123. If you don't mind tiny parts, RUM001L02T2CL and friends is another option, small enough to be comparable to BJTs in many applications, but without the base current.But what does the load look like, anyway? Logic input? Coil driver? Something else? Would anything else ever be connected? How fast does it go?Tim

author: pcprogrammer
author_rank: Super Contributor
timestamp: September 03, 2024, 03:32:10 pm
content: Wow I did not knew that the Wiegand interface/protocol is still used.What system and in what environment uses this where it might be physically disconnected and connected to something else with the risk of being connected to a wrong voltage?The one usage of Wiegand that I encountered was way back in the late 90's to control a coffee vending machine. The connection was made inside the machine to never be disconnected or connected to something else. In that case also not wise to have it exposed since it would allow for hacking and getting free coffee.Can't recall how I rigged up the hardware back then.

author: PGPG
author_rank: Frequent Contributor
timestamp: September 03, 2024, 07:05:38 pm
content: Quote from: pcprogrammer on September 03, 2024, 03:32:10 pmEN IEC 60839-11-5:2020 was introduced with intention to replace Wiegand. And (to put it mildly) I don't like this new standard. Standards are not mandatory, but people seeing that one exists just write it into specification and that way we are forced to use it with the following consequences:- in small system (most of them are like that) increasing about 100 times power used on RS485 communication (while the whole world is trying to limit energy use),- in big system (40 devices on bus) urgent signals (tamper violation) instead of being send 'at once' have to wait until pooling will come. Standard gives each device max 200ms to answer (it says that it should be typically less than 3ms, but only should) and (which is already bizarre) allows in frame transmission to have up to 20ms breaks between bytes.We use RS485 since 90s but we never used pooling and and never interrupted frames being sent. May be in 80s someone had to break frame because controller was too slow. But specifying something like that in 2020...

author: tszaboo
author_rank: Super Contributor
timestamp: September 03, 2024, 07:56:54 pm
content: Quote from: pcprogrammer on September 03, 2024, 03:32:10 pmI think it's usage is almost exclusive to entrance card readers.OP, I wouldn't overthink this. The easiest way to handle these communication interfaces is always optocouplers. Or digital inputs and outputs on a PLC. You don't know how long cabling will there be on these devices, or when there will be a lightning strike next building. Go for galvanic isolation.

author: jfuu_
author_rank: Newbie
timestamp: September 03, 2024, 10:51:08 pm
content: Quote from: PGPG on September 03, 2024, 02:48:29 pmI'm not really sure to be honest. Their comment was:QuoteQuote from: PGPG on September 03, 2024, 02:48:29 pmI foundtheseon Digikey - they sound like they might have an initial resistance of 100R and then increase from there with temperature?Quote from: PGPG on September 03, 2024, 02:48:29 pmAh that's good to know. I guess it just depends on how much current is going through the PTC? What would you recommend in place of a PTC+Zener to ensure 12V doesn't damage my input?Quote from: T3sl4co1l on September 03, 2024, 03:19:34 pmYeah it isn't really clear - it does make more sense that it'd be the rise time as opposed to the fall time.Quote from: T3sl4co1l on September 03, 2024, 03:19:34 pmI don't mind small parts - I'm having a PCB manufacturer assemble it anyway.I'm not really sure what the load looks like - it's an existing access control system I'm connecting up to. I've done some testing and it seems like the downstream (i.e. the Wiegand input on the access control board) sinks about 2mA, and it outputs about 3V when nothing is connected (maybe a voltage divider with an on-board pull-up?).I'd like to support a wide range of Wiegand inputs if possible, but I'd expect they all work very similarly for compatibility. In terms of speed, the shortest pulses (i.e. 5V->0V->5V) are usually around 40uS, with the gaps between them being around 2ms.Quote from: pcprogrammer on September 03, 2024, 03:32:10 pmIt seems like it's still in reasonably wide-spread use for access control (at least in the specific domain I work in). The main issue I have with it is that it's pretty poorly documented overall - there isn't one "specification" and lots of devices require different setups.Quote from: pcprogrammer on September 03, 2024, 03:32:10 pmThe device only really needs protection during installation - ideally I'd like holding it wrong to not release the magic smokeQuote from: tszaboo on September 03, 2024, 07:56:54 pmI like the sound of isolating the device (makes it harder to hold it wrong!). How would a pull-up work if I want to keep my input isolated?Thanks all for the help! Certainly a lot to think over.

author: jfuu_
author_rank: Newbie
timestamp: September 04, 2024, 12:29:46 am
content: Thinking about it some more, I'm probably just going to go with something close to my original design:Can someone please confirm my calculations are right?R1- GPIO is 3.3V, so I calculated this resistor using:Ib = Ic / hFE(sat)Ib = 4mA / 10Ib = 0.4mARb = (Vb - Vbe(sat)) / IbRb = (3.3V - 0.7V) / 0.4mARb = 6500R (rounded down to 4700R, better to overdrive to ensure saturation?)R2- 1k pull-up alongside R3 limits the short-circuit current (i.e. if WIEGAND_OUT_D0 gets grounded) to 5V / 1200R = ~4mAR3- 200R resistor limits the current through Q1 to 5V / 200R = 25mA if WIEGAND_OUT_D0 is shorted to 5VAlso, is there a better BJT I could be using here? This one seems a bit overkill (600mA collector current!).I've decided I'm not really fussed about people connecting it to 12V - I'll tell them to hold it properly

author: ArdWar
author_rank: Frequent Contributor
timestamp: September 04, 2024, 12:47:02 am
content: The lack of defined or documented I/O characteristics make things a bit complicated here, as we can only guess which compromises are acceptable and which aren't. At first glance, I thought why not just use logic gates or myriad of line drivers. But then I thought that was kind of obvious, so theremustbe other obvious thing that I don't know of that makes you avoid those choices.Another example, you said the input sinks 2mA. That much input current will cause your 1k2 impedance drive to drop VOHsignal down to around 2.6V. That's marginal for typical 5V logic, but that might be normal for your protocol, I don't know.

author: PGPG
author_rank: Frequent Contributor
timestamp: September 04, 2024, 12:59:26 am
content: Quote from: jfuu_ on September 03, 2024, 10:51:08 pmThey suggest that rising edge can be slow. I don't want to discuss with it. If you drive base with small resistor than when you switch transistor off you take charge from base also with this small resistor so comparable fast. But you can absolutely don't care how slow rising edge is - see later.Quote from: jfuu_ on September 03, 2024, 10:51:08 pmI'd like to look at it. So link please.Quote from: jfuu_ on September 03, 2024, 10:51:08 pmI have already written. I drive npn base with 4k7+3k3 divider and use 33R in emitter and 4k7 pull-up. It should withstand 12V. But 12V is not what you should be aware off - see later. Risk of mistake is rather small. People connect things with power switched off. If 12V wire will be red then they should not connect other wire to +12V. If other wire touch it temporarily when power is switched off nothing will happen.Quote from: jfuu_ on September 03, 2024, 10:51:08 pmWe manufacture access controllers since end of 90s. Our controllers never had Wiegand input. For special cases (when someone needed this and only this Wiegand reader) we have made an extension module - interface Wiegand to our RS485 bus. So I know only what are at our Wiegand inputs - 4k7 pull-up to 5V.I am surprised that anyone is constructing anything with Wiegand thinking about adapting to multiple devices when we already considered it outdated in the 90s. Wiegand comes from metal identification cards with two rows of holes in it so the transmission speed depended on the speed of user swiping the card in the reader.Readers are part of access system that are installed in not protected area. Using an unencrypted interface (like Wiegand) there is simply irresponsible.Quote from: jfuu_ on September 03, 2024, 10:51:08 pmSo you have much, much more time for rising edge and you worry when someone says that the transistor is slowly turning off.Quote from: jfuu_ on September 03, 2024, 10:51:08 pmYou don't realize how wrong you are.When lightning strikes near the building in which your device is installed, you can expect a ground difference of up to 50V within one building and several kV between buildings.I use SMB 600W 18V transils at all inputs/outputs. 18V to ensure 12V doesn't damage itQuote from: jfuu_ on September 03, 2024, 10:51:08 pmThere is no idea to isolate signal wires while you transfer not isolated supply in the same cable.

author: coppercone2
author_rank: Super Contributor
timestamp: September 04, 2024, 01:14:17 am
content: I wonder how that wire was invented. Did someone get locked in a boiler room with a roll of galvanized wire?Wiegand wire is kind of a sad inventionor was it from torturing paper clips in meetings?

author: jfuu_
author_rank: Newbie
timestamp: September 04, 2024, 01:20:40 am
content: Quote from: ArdWar on September 04, 2024, 12:47:02 amI'm pretty clueless when it comes to this kind of stuff - I just designed what I could understand. From looking around online, Wiegand outputs are usually open-collector and have a pull-up on them (although it's hard to tell what end this is usually on). I've just found that there's an "official" specification for Wiegand but it's paywalled (SIA AC-01-1996.10) - hopefully it might contain more information (looking to purchase it later).Quote from: ArdWar on September 04, 2024, 12:47:02 amThe 2mA sink is without any resistors on the output, so I think the impedance of the input is closer to 2500R. Still doesn't give a great VOHthough - 3.3V from my calculations.Looking around online, some Wiegand readers don't have pull-ups, some allow them to be configured (e.g.https://www.turnstiles.us/wp-content/uploads/2024/01/www.TURNSTILES.us-WSOI-100-Wiegand-Signal-Optical-Isolator-Product-Manual.pdfoffers optional 1500R pull-ups) and some have fixed pull-ups. I'm going to do some testing to see what kinds of voltages this device can recognise as high on its input.Quote from: PGPG on September 04, 2024, 12:59:26 amApologies - I thought I'd linked it in my reply:https://www.digikey.co.uk/en/products/filter/ptc-resettable-fuses/150?s=N4IgjCBcoGwBwGYqgMZQGYEMA2BnApgDQgD2UA2uGAAwAEAtgIIgC6xADgC5QgCqAdgEtOAeXQBZfJlwBXAE74QAX2IAmagHYYyEGkhY8RUhXDU6IgBb1crDt0h8hoiVNkLlKkNughBAEx4AWhoIOx4QYk4AT3ZFB2k0JSUgAQuote from: PGPG on September 04, 2024, 12:59:26 amYeah I think I've come to terms with not trying to prevent incorrect connections like thisQuote from: PGPG on September 04, 2024, 12:59:26 amThe device I'm building is an interposer to retrofit on systems that are already using Wiegand - I agree that it's not something that should really be used going forward. It's interesting that you had the pull-ups on your input - as I mentioned above it seems hit-or-miss as to where the pull-ups are actually located a lot of the time.Quote from: PGPG on September 04, 2024, 12:59:26 amFair enough! I find it hard to gauge the scale that things like this operate on. I guess the easiest thing for me to do is just breadboard something like this and see how it behaves.Quote from: PGPG on September 04, 2024, 12:59:26 amAh that sounds worthwhile haha! I'll take a look at adding TVS diodes between all of my inputs/outputs and GND. Thank you!Quote from: PGPG on September 04, 2024, 12:59:26 amYeah I guess having a pull-up on my end of the wire pretty much ruins any hopes of thisQuote from: coppercone2 on September 04, 2024, 01:14:17 amI'm sure it was a great invention for the time, but I'd rather not have to deal with itThanks again everyone for the help! I really do appreciate it (apologies for being clueless!)

author: pcprogrammer
author_rank: Super Contributor
timestamp: September 04, 2024, 06:48:29 am
content: A simple solution can be to have the pullup at the receiving end, or at least powered from the receiving end. Same for the ground wire.How to do this is to just make an open collector output with an optocoupler. The MCU drives the LED of the optocoupler via a suitable resistor. The transistor of the optocoupler is connected to the target wires including ground. Do not connect the ground of the interface wires to the MCU ground.Choose an optocoupler with high enough max collector voltage and it won't have problems when wrong fully connected, as long as you add some series resistor to limit current.This of course stands or falls with how your MCU is powered.Another option for protecting the transistor is to use a TVS instead of a zener diode. They can withstand higher power surges and react faster.

author: PGPG
author_rank: Frequent Contributor
timestamp: September 04, 2024, 10:48:28 am
content: Quote from: jfuu_ on September 04, 2024, 01:20:40 amI suppose the idea was open collector and pull-up at input.But when you want to see outputs at your reader just powered pull-ups inside help a little and as they don't interfere with anything...Quote from: jfuu_ on September 04, 2024, 01:20:40 amYou are right - it really have specified resistance.I knew about standard PTC thermistors (with their characteristic simply temperature dependent) used as temperature detectors (self heating avoided).I knew about PTCs used as fuse (with as small on resistance as possible). They have hysteresis (after trip they get higher permanent resistance).I didn't knew about PTCs with some specified R25 resistance being also specified as fuses. They clearly claim in datasheet to have no hysteresis so are different from those PTC I use.I use 0ZCJ0020FF2E - 0.2A/30V PTC. It has 0.6Ω before first trip and 2.5Ω after.In linked by you PTF serie closest would be 0.34A/25V with 5Ω. It have to have higher R as have higher volume to be heated. I suppose these both are the same kind of devices but one sold before being trip and other with paying attention to get exact resistance after trip and intentionally tripped during manufacturing.If you want them as fuse and you expect to never being trip in your device live cycle than you probably prefer 0.6Ω than 2.5Ω. But as my PTC is SMD so during reflow soldering... . But THT you are able to assemble without heating them over their trip temperature of about 80°C, I think.Quote from: jfuu_ on September 04, 2024, 01:20:40 amSo something opposite to our Wiegand-RS485 bus interface. Our device is not simple converter as it can operate in our RS485 bus having up to 50 devices and no pulling. We try to connect Wiegand readers, you try to be visible as Wiegand readerQuote from: jfuu_ on September 04, 2024, 01:20:40 amI think pull-ups at input are mandatory in Wiegand concept while in outputs are optional but never investigated it deeply.Quote from: jfuu_ on September 04, 2024, 01:20:40 amSimulation will be enough. It is really hard to build OC transistor output to not switch off in 1ms.

author: tszaboo
author_rank: Super Contributor
timestamp: September 04, 2024, 01:56:19 pm
content: Quote from: jfuu_ on September 03, 2024, 10:51:08 pmI don't think your schematic is correct. At least not from what I remember.Wiegand is pulled up on the door controller's side. It has two open collector outputs.The card reader can pull either of these low to send 0 or 1. It doesn't need it's own pullup resistor.Especially, since several card readers can be connected to the same controller, in parallel.

author: jfuu_
author_rank: Newbie
timestamp: September 04, 2024, 06:20:26 pm
content: I've purchased the SIA document and it confirms what PGPG and tszaboo have said:QuoteIt also provides this nice table:And states:QuoteFrom the table saying that Iohis limited to 1mA, does that imply that the input is what is limiting this current (as that's where the pull-up is located)? From my testing with the panel I have, it's happy to source 3.5mA from D0/D1 to GND (it's also only pulling up to 3.3V - naughty!).I initially thought this would mean I could use an optoisolator, as I no longer need a pull-up on the output, however it seems like any high-speed optoisolators (i.e. ones with <1uS switching time) require VCC on the output side. I guess something like this would suffice instead? The 100R resistors would probably be 0.5W to ensure they can handle dissipating the 50mA if WIEGAND_OUT_D* is shorted to 5V (although I can't see how this would happen).EDIT: The bottom input would be GPIO23 not GPIO22.

author: tszaboo
author_rank: Super Contributor
timestamp: September 04, 2024, 06:26:18 pm
content: Quote from: jfuu_ on September 04, 2024, 06:20:26 pmFrom what I remember the protocol is very-very slow. I think we were sending it at 9600 baud, and any higher the controller didn't even read the bits.I wouldn't worry about switching speeds. But you should try it. This is a very simple circuit, just prototype it and test it with your controller.

author: jfuu_
author_rank: Newbie
timestamp: September 04, 2024, 06:34:13 pm
content: Quote from: tszaboo on September 04, 2024, 06:26:18 pmThe Wiegand specification lists the pulse width (signal low duration) as 20uS - 100uS and I'd like to be able to control this with uS accuracy in software (some panels don't really adhere to the standard and require specific timing). I'll have a bit more of a browse as there may be faster optoisolators that don't require VCC about, but the few I took a quick look (e.g. PC817, TLP2301) mentioned rise/fall times of ~20uS.I agree it's probably easier to breadboard - I'll get a few different ones ordered and have a play around.

author: PGPG
author_rank: Frequent Contributor
timestamp: September 04, 2024, 08:29:15 pm
content: Quote from: jfuu_ on September 04, 2024, 06:20:26 pmThe only way I can find to understand this table is:Output in high state even loaded with 1mA current (towards GND) will ensure at least 4V.Output in low state even loaded with 25mA current (toward VCC) will be below 1V.My output (with 4k7 pull-up to 5V will ensure 4V when loaded with 0.2mA. So in state 1 is too weak.My output (4k7+3K3 with 33R in emitter) is about 16mA current source so will ensure output below 1V loaded with 16mA (for higher current output will be higher then 1V). So in state 0 is also too weak.If my understanding the tabele is correct than pull-up have to be 1k to 5V. And transistor should be able to sink at least 30mA (5mA into 1k and 25mA into load).

author: jfuu_
author_rank: Newbie
timestamp: September 04, 2024, 09:41:20 pm
content: Quote from: PGPG on September 04, 2024, 08:29:15 pmI'm not sure I understand sorry. The specification seems to indicate that there is no pull-up on the reader side, so how could current flow from the reader to the panel?I'm also a bit confused by the negative current - could it be saying that the panel can sink up to 1mA from the reader (not sure how if there isn't a pull-up in the reader) when pulling the signal high and the reader can sink up to 25mA from the panel (through the panel's pull-up resistor into GND) when pulling the signal low?

author: PGPG
author_rank: Frequent Contributor
timestamp: September 04, 2024, 09:51:41 pm
content: Quote from: jfuu_ on September 04, 2024, 09:41:20 pmWhere from this idea?Quote from: jfuu_ on September 04, 2024, 09:41:20 pmFor me positive = source, negative = sink.So table says: 1mA source, 25mA sink (like digital circuit output specification).

author: jfuu_
author_rank: Newbie
timestamp: September 04, 2024, 10:11:49 pm
content: Quote from: PGPG on September 04, 2024, 09:51:41 pmThe specification says:QuoteIt doesn't explicitly say itcan'tbe provided at the output, but from looking at other readers online, it seems like the pull-up usually appears only on the panel (some readers have an optional or built-in pull-up).Quote from: PGPG on September 04, 2024, 09:51:41 pmMy confusion was around which direction the source/sink is - is it from the perspective of the reader or panel? I re-read the specification and found it says this:QuoteWhich makes it sound like it's the reader sourcing 1mA and sinking 25mA, which I think makes the most sense to me. It does specify that the minimum current for high is 0, so I guess compliant panels shouldn't have a problem with there being no current flowing from the reader to the panel.It seems like Wiegand is probably rather forgiving, given the mix of pull-ups and no pull-ups I've seen on readers. I'm probably going to just go with thelatest schematic I postedunless anyone can see any glaring issues with it. An axial resistor can just be installed between 5V and D0/D1 if needed for a specific installation (I've seen a few reader manuals suggest this if the voltage is dropping too much).Thanks!