Understanding transistors - Page 1
Forum section: electronics / beginners

author: bitman
author_rank: Unknown
timestamp: May 17, 2017, 10:54:02 pm
content: Another newbie question. I'm running in circles, having tried several different approaches. I have a 12v line that I want a "high" from an arduino to turn on. Simple right? Well, every time I attempt anything with the few transistors I have (getting a better collection by the weekend) I don't see anything remotely as I thought I would. In particular, as I tried this optionhttps://electronics.stackexchange.com/questions/17581/best-way-to-get-5v-or-12v-or-0v-from-arduino-pin/17584in particular this circuit:nothing works.So I've simplified things things, and I have a single 2N3906 PNP transistor (I know, not the one mentioned in the drawing - it's all I have). I apply 12v to the emitter. NOTHING to the base. And I measure 12v on the Collector. Base isn't even pulled to ground (if I do it short circuits so there's definitely something I don't get). If I measure the base I get about 6v on it? When I build the circuit referred here with a 2222 and 3906 all I get is a constant voltage regardless of applying a voltage to the base of the 2N2222a.I've read and followed quite a few talks (youtube etc) and well, I thought I understood transistors. Granted, it's much easier for me to understand the NPN than PNP, but still I thought I had the basics down. Even with 5 volts on the collector on an NPN I don't seem to be able to fully turn off the power. Not sure why - in particular I'm not sure why I see a voltage on the 2N3906 when I have nothing connected to the base, just the emitter (and the collector is going through a 2Kohm resistor to ground to simulate a small load).My question is very simple. I obviously need a "dummies guide" here. What's a good source to get what's going on here? ALL I really wanted to learn was creating a switch using a transistor that turned on/off a higher voltage. And there in lies one of my issues I think. I'm focused on voltage, not current here. Is that the issue?

author: rstofer
author_rank: Super Contributor
timestamp: May 17, 2017, 11:30:30 pm
content: A PNP transistor is exactly the wrong device. The proper way to interface with voltage limited devices like uC IO pins is to use an NPN transistor - 2N3904Here is more info but note that down under "gotcha's", you can't have a voltage higher than the uC Vcc. In general, this is true. There are exceptions but I won't go down that path.http://www.w9xt.com/page_microdesign_pt8_pnp_switching.htmlYou can Google for 'Arduino PNP relay driver' to see what you can find.

author: Seekonk
author_rank: Super Contributor
timestamp: May 17, 2017, 11:38:59 pm
content: First off, there is no black magic. The electrons always know what they are doing. The problem is when we think we have done everything right. One or more of your transistors is damaged or not hooked up correctly. Start with the 3906, with a 10K or so resistor connected to common it should be able to turn on and off. Always have some load on it as just some noise in the air can turn it on somewhat. Meters can be very sensitive. Any drawings found on the internet are questionable. The designs are often not suitable for you application. Some transistors of relatively the same number can have different pin outs. So start with this simple test first.

author: sokoloff
author_rank: Super Contributor
timestamp: May 17, 2017, 11:42:02 pm
content: You have a 2N2222A in your hand. That's an NPN BJT, exactly what you want for this application, assuming you can "sink" the current from the load through the transistor (rather than "source" the current out of the circuit). If you can switch the low-side, it's a fairly trivial and standard circuit. Try to get that to work first, IMO.Follow any of the various tutorials, using the 2N2222, and then tell us where/if you get stuck.Here's one, semi-randomly chosen:https://teachmetomake.wordpress.com/how-to-use-a-transistor-as-a-switch/

author: amspire
author_rank: Super Contributor
timestamp: May 18, 2017, 12:16:45 am
content: You may have blown some of your transistors. Particularly if you connected the base of the PNP transistor to 0v while the emitter is at 12V. If you did put the full current of the 12V supply through the transistor base, and you may have turned it into a lump of shorted metal internally.Here is how to test the transistors:https://www.electronics-notes.com/articles/test-methods/meters/multimeter-diode-transistor-test.php

author: rstofer
author_rank: Super Contributor
timestamp: May 18, 2017, 01:05:13 am
content: Quote from: bitman on May 17, 2017, 10:54:02 pmThat circuit should work with a 2N2222A substituted for the 2N4401.Check your pinout...You will need to be certain that your uC output can get up to 5V or so. I would put a 330 Ohm resistor in series with the 2N4401 base to limit the current from the uC.Don't count on this circuit working with a 3.3V uC. With the 12V and resistors shown, the base needs to get to 4.5V in order to get the transistor to turn on. It will need more to get the transistor fully saturated (which may not be terribly important).

author: bitman
author_rank: Unknown
timestamp: May 18, 2017, 01:11:04 am
content: Quote from: amspire on May 18, 2017, 12:16:45 amI made myself a little gadget a long time ago that I've used to measure transistors, diodes etc. I'm color blind, so I have to measure everything that uses colors - makes me slow as snails doing anything but it's fun none-the-less. I'm attaching two pictures here showing me testing both the PNP and NPN transistors in the circuit, and they both come up "working". I definitely made them go hot for a few seconds. But I use a current limiting PSU so the through-put is maxed out at 300 mA for this setup. That said, I've tried to replace the NPNs before and found no difference, knowing it came down to how I was using it and not something broken.I'll check your link out, but so far I don't think that's the issue here.

author: bitman
author_rank: Unknown
timestamp: May 18, 2017, 02:19:52 am
content: Thanks for the advice - I went even further back to basic, recreated stuff I've done before and that worked. I still didn't see 0 volt (more about that in a moment) but I did see the LED go on/off on the collector side when the base got +5v (using 2n222a). So far so good.Back to the not seeing 0 volts. I think I'm confusing potential with actual voltage. If I put the meter gnd on gnd, and place the plus on the collector pin, there's a voltage potential between that point and ground through the resistor and LED/Diode. However, if I place the meter on the emitter I get the voltage potential of +5v because the emitter is connected straight to ground. So I'm back to a question I've posted about before, on how to actually measure what voltage is being "turned on". That said, when the transistor is "on", I get a full potential of 5v as there's now a straight line to ground. So I see a difference. I just didn't see 0 volt - again getting the current confused with voltage (potential). At least that's my working theory.So what's the right way to measure? I took a picture of my setup on a bread board. I added back my booster to so I could get the 12v. I then connected the boosters + to the collector through a load resistor of about 1MOhm. I added a few comments on the picture indicating where I did the measurements, but you probably have to zoom in to see them. I'm absolutely NOT seeing 0v anywhere but that probably is how it should be. So that leads me to the question on how to determine if a basic 2222a transistor is turned on or off? I guess I have to find a way to measure current, and forget all about measuring voltage (potential)?

author: amspire
author_rank: Super Contributor
timestamp: May 18, 2017, 02:38:19 am
content: Haven't you got the transistor around the wrong way? Looks like you have the emitter connected to the load resistor.

author: rstofer
author_rank: Super Contributor
timestamp: May 18, 2017, 02:58:04 am
content: There's no chance of figuring out what that breadboard circuit should do without the corresponding schematic.That said, why such a high value load resistor? How about something reasonable like 1k or so?You meter should probably have the black lead connected to ground or the negative output of the power supply. Every measurement in a circuit like this is relative to common ground.

author: bitman
author_rank: Unknown
timestamp: May 18, 2017, 03:46:05 am
content: Quote from: amspire on May 18, 2017, 02:38:19 amThe flat side is going away from the camera. When I look at the datasheet for the 2222A it seems it's "reverse" order from others I've used, so you have to turn it around from what you expect. At least what I would expect from the transistors I've dealt with in the past. So no, the resister is connected to the collector side. And there's another resistor on the base.

author: amspire
author_rank: Super Contributor
timestamp: May 18, 2017, 06:00:21 am
content: http://www.onsemi.com/pub/Collateral/P2N2222A-D.PDFhttp://s680.photobucket.com/user/sorgil613/media/Elelctronics%20Components/Transistors/PN22222-h.jpg.htmlHere are two datasheets of variants from the same manufacturer with the opposite pinout. It comes down to the exact manufacturer and part number. The 2N2222A is actually a metal can transistor. Many manufacturers called the plastic TO92 variant PN2222A with the emitter on pin1 or in the case of Onsemi (Motorola in the old days) P2N2222A for the version with the collector on pin1.One way of checking is to check the emitter-base and collector-base diode junctions with a diode mode on a multimeter. The emitter-base junction will have a lower voltage because it is more heavily doped.If you reverse the emitter and the collector, you will end up with a much lower gain transistor and also the emitter-base junction when used as a collector-base junction breaks down like a zener at 5V to 9V.

author: Seekonk
author_rank: Super Contributor
timestamp: May 18, 2017, 09:55:08 am
content: I wanted to start with first steps, but I probably should have said not to use that circuit. That circuit is too clever for you or most anyone. It is a very fast way to blow up a micro should anything go wrong. Modify it so the base of Q1 has the 4.7K going to your signal source. The emitter resistor is eliminated and connected directly to common. This will define how much current goes through the base. That multiplied by the gain of the transistor how much current the collector is capable of.The direct connection of the collector to the base of the other transistor is really bad. Use a 2.2K to 4.7K resistor between the two. That will define how much current the base will see. Multiplying the gain will give the current Q2 is capable of driving. All very straightforward.The circuit you posted will destroy things quickly if anything is no connected correctly.

author: Zero999
author_rank: Super Contributor
timestamp: May 18, 2017, 12:16:29 pm
content: Quote from: Seekonk on May 18, 2017, 09:55:08 amWhat this circuit?What's wrong with it? I'd probably reduce the value of R3 for faster switching but otherwise it's a good circuit. I've used it before with no problems.

author: Seekonk
author_rank: Super Contributor
timestamp: May 18, 2017, 01:15:44 pm
content: "It is a very fast way to blow up a micro should anything go wrong."I think that is self explanatory. I didn't say it didn't work. The OP has not managed to hook up two transistors without destroying them. It is harder for a beginner to understand the principles of operation. I have a problem with R1. I don't think you are helping this person with these diversions. Focus on trying to help him instead of trying to show how smart you are.

author: Zero999
author_rank: Super Contributor
timestamp: May 18, 2017, 02:28:52 pm
content: Quote from: Seekonk on May 18, 2017, 01:15:44 pmIt isn't self explanatory to me, and possibly the original poster too, how that circuit can blow an MCU output. By explaining what you may consider to be obvious, you'll help both the original poster and me.

author: Seekonk
author_rank: Super Contributor
timestamp: May 18, 2017, 03:53:49 pm
content: If the OP uses good parts and connects it as it is supposed to, it will work. Then why are we here? He didn't. If it had been connected to a NANO, the conversation may have been about cheap Chinese stuff that never works. The "base" input could output a lot of current if it isn't the base or the transistor magically shorts. Of course, it could have just barely worked because, being a high side driver, he is likely trying to power something that needs a lot more current and R1 is a little high for that.This thread will descend into that other thread, equivalent to how to connect a light bulb, that is 8 pages and 99% of the posts don't even relate to the OP's problem. That poster hasn't returned. Did he really get any help? I will only respond to any future posts of the OP. Your last post was a waste of good bandwidth. Good Day.

author: mikerj
author_rank: Super Contributor
timestamp: May 18, 2017, 04:21:13 pm
content: You have created unnecessary confusion by stating this circuit is "too clever for you or most anyone" when there's nothing actually wrong with it. The OP could blow up the ports on his micro with a myriad of different circuits if he doesn't assemble them correctly, there's nothing particularly risky about this circuit.

author: rstofer
author_rank: Super Contributor
timestamp: May 18, 2017, 04:52:21 pm
content: One of the risks in this project is applying 12V to a uC output pin, with or without a series base resistor. That the schematic doesn't even show a base resistor causes me an issue. The only reason the circuit works is that 4.3k resistor that raises the emitter voltage which raises the base voltage to a point where the current flow doesn't harm the uC. I would still put a 330 Ohm resistor in series with the NPN base. I pretty much use 330 Ohm in series with all inputs and outputs just to protect the uC or FPGA.I ran an LTSpice simulation with no base resistor and the base current is just 10 uA but I only had a 1k load on the output.The thing about transistor circuits is that you must start with the output current and work backwards. I don't recall a load being given for the PNP transistor. First we get that current, then we guess at the required base current based on some estimate of hFEthen we figure out how much collector current the NPN (base current of PNP plus 10k resistor current) will have and with another estimate of hFEfor the NPN, we get a required base current.That 4.3k resistor limits the PNP base current and needs to be reconsidered. The simulation works with a 1k load, it does not work with a 10 Ohm load.

author: Zero999
author_rank: Super Contributor
timestamp: May 18, 2017, 05:48:12 pm
content: Quote from: rstofer on May 18, 2017, 04:52:21 pmThe base current is independent of the load current and is set by R3, so there's no need for any base resistor which will do nothing. I agree, the load current needs to be considered. As drawn, the circuit will be able to supply loads of up to 50mA or so before the saturation voltage becomes unacceptable (>1V or so).Quote from: bitman on May 17, 2017, 10:54:02 pmYou haven't said how much current your load draws?Try assembling the circuit as per the attached picture. If your transistor tester is working, the pins on the transistor pictures will be correct. For a test load, use something which doesn't draw much current, such as an LED in series with a 330R resistor or a small (<50mA) piezo buzzer.

author: james_s
author_rank: Super Contributor
timestamp: May 18, 2017, 06:56:33 pm
content: Something I remember confusing me early on which may be going on here. The Emitter is always the one with the arrow on it, even though with a PNP connection the arrow is pointing toward the junction rather than away from the transistor. Without going into the reasoning of why that is, or getting into the conventional theory vs electron theory debate it's important to remember that current is assumed to flow in the direction of the arrow.With NPN, you need to lift the base up relative to the emitter which is typically grounded in a switching circuit. With a PNP you need to pull the base down relative to the emitter which is typically connected to the V+ source. In both cases the base needs to be protected with a current limiting resistor as transistors are current-driven devices. Trying to drive a constant voltage through the B-E junction will burn it out.

author: rstofer
author_rank: Super Contributor
timestamp: May 18, 2017, 08:26:10 pm
content: Quote from: Hero999 on May 18, 2017, 05:48:12 pmYes, the base current is the independent variable. We can put as little or as much through the base as we wish, subject to not melting the base-emitter junction. The collector current, the thing we really want, is determined primarily by the base current. If we only have a few microamps of base current and a gain of, say, 100, we will only get a few hundred microamps of collector current.So, that 4.3k resistor needs to be sized to provide enough collector current and in this case, the maximum base current is approximately 1 mA. So, for an fFEon the PNP of, say, 100, the maximum collector current will be 100 mA. So a load resistance of 120 Ohms is about the maximum.The simulation shows the output just starting to fall off 12V when RLis 150 Ohms. I just used generic transistors so I'm not sure what value of hFEis being used. Somewhere around 85 mA is the maximum load current. According to the simulation, using a 150 Ohm load, the PNP base current is just about 890 uA so with a gain of 100, somewhere near that 85 mA is possible.Clearly, this isn't much of a driver using the values given.But, we still don't know the load requirement (or at least I don't).

author: Zero999
author_rank: Super Contributor
timestamp: May 18, 2017, 10:02:09 pm
content: Quote from: rstofer on May 18, 2017, 08:26:10 pmBe careful when going by Hfe figures listed on data sheets. They're often given when the transistor is not in saturation and there will be a high voltage loss, if you just about give the transistor enough base drive for the required collector current. To get the transistor into full saturation the base current needs to be an order of magnitude higher. Fortunately the 2N3906 specifies the Hfe of 60, at a VCE= 1V which is probably acceptable for a 12V circuit.https://www.onsemi.com/pub/Collateral/2N3903-D.PDF

author: rstofer
author_rank: Super Contributor
timestamp: May 18, 2017, 11:05:16 pm
content: Quote from: Hero999 on May 18, 2017, 10:02:09 pmI usually assume a MUCH lower value of hFE, perhaps as low as 10 unless it is a power transistor and then definitely 10 or less (2N3055). From the On Semi datasheet for the 2N3904, we can see the truly grim gain characteristics for the On condition of Vce about 1V.https://www.onsemi.com/pub/Collateral/2N3903-D.PDF- page 2Using an hFEof 10 isn't unreasonable. If the output stage has a load of 100 mA then the PNP will need at least 10 mA of base current so the NPN will need at least 1 mA of base current.But regardless of the value of gain, the process begins at the output. First we need the load current. Then the datasheets...

author: bitman
author_rank: Unknown
timestamp: May 19, 2017, 12:49:38 am
content: Wow - thanks for all the replies here. Note, I only have a few hours at night spread over the week to do this, so I'm a bit slow with replies and followups.I took the initial posts realizing I needed to make a small test circuit to "prove" I could get the transistor working. As it's been pointed out there, I've had the transistors turned the wrong ways at times - looks like there's no consistency on the pin connections even using the model number - well, another newbie lesson learned. And yes, it is really confusing when most data sheets just shows the metal cap and others are bad photo-copies scanned in. That said, I managed to get a very simple 5v setup working. When I applied current through a resistor on the base, rgw LED turned on. I even got it to reverse so the LED turned off when I applied a current to base. Happy camper, it works as I hoped it would. So that got me thinking that all I needed was ONE transistor so I created this small circuit This is part of a slightly larger of my EEPROM writer/reader thing - I've left out a lot details that doesn't deal with the transistor side.In essence I'm getting outputs from a 74-595. Only ONE line is going to be active at a time (software controlled). When the A line is high, I want to apply 14v, when the B line is active, I want 12v and when the C line, I want the lined grounded. This goes into a W27C512's OE line needed to indicate the state of the operation (read, write, erase). I combine the emitter output through a diode so there's no feedback current/voltage. Now, I wouldn't be writing this if this worked.So I started out with the two transistor option, as that is what searching around seemed to indicate I needed. Since I'm not able to fully explain WHY I need 2, I have attempted what I thought was a more straight forward solution. Since I got a bunch of 3906 and 2222As for a few dollars on Ebay I have plenty to experiment with, to destroy so if that happens it's not a big deal. Perhaps they're not the best ones for this, but my simple reading of the data sheet seems to indicate they're safe up to 20v and since my current need/input is low I didn't think I needed "specialized" transistors for a small proof of concept.Of everything written so far by everyone, it's clear "I don't get it". The simple math stuff being used to explain the resistor sizes is foreign to me. Not the math itself, but why it's used. So I definitely need to go back to basis. I'm slowly going through the book "Practical Electronics for inventors, fourth edition" when I have time. But so far it's been great at putting me to sleep - talking quantum physics when all I want to do is figure out how to do simple logic based circuits is a bit too much for me. I've not yet gotten to the transistor section yet so I probably should give my experiments a rest and do some reading (I learn best by doing). I definitely need to get a better understanding of hFE and similar concepts so I can measure/plan out what will work. A lot of what I've done so far is simply trying things out with low voltage and limiting the current to 200mA (or use a battery).So if the original layout/schema is the way to go, I'll setup another separate circuit and give it a try. I did try with 14V on the collector and that seemed to work. Only problem is that I always get the potential voltage when I measure the C/E of the transistor - so I'm not really sure it's actually working with 14v. It didn't get hot etc. so it looked like it was working.So now that I've showed a rough diagram of what I now thought was the better solution, I'm sure the feedback will be even heavier on what not to do. Anyway, my problem is that when I measure on the voltage where pin 14 will be, I do even remotely see the voltages I see on the collector. And the emitter currents are MUCH SMALLER (50% or so) than what's coming in on the collector (voltage potential) so well, I'm not sure why that is.Thanks again for the feedback. Amazing forum and people here.

author: rstofer
author_rank: Super Contributor
timestamp: May 19, 2017, 01:10:06 am
content: Well, you're right, there will be comments...There is no way this circuit is going to work.The outputs of the 74LS595 can, at most, get to 5V and the transistor emitters can only get to 0.7 volts less or 4.3 volts. The rest of the supply voltage will be dropped across the transistor.It looks like Q3 just sends the emitter directly to ground which is ok but I don't see where that does much with the diode. ETA: If the idea is to send 5V to the diode, get rid of the ground connection.It would have helped enormously if you had told us the application earlier.Your original 2 transistor circuit is much better because the PNP will deliver the proper voltage while the NPN will interface with the logic.You need to account for the diode voltage drop (0.7V) so you won't get 14V, you will get 13.3V or, actually about 0.2V less if you can somehow get the transistor into saturation, which you can't when driving the base to just 5V.ETA: It might help to know which EEPROMs you plan to program so we can see if the dropping resistors will provide enough current.

author: bitman
author_rank: Unknown
timestamp: May 19, 2017, 01:36:05 am
content: Quote from: amspire on May 18, 2017, 06:00:21 amThanks - it was pretty clear that the model number by itself wasn't enough. If it helps, here's a closeup of my 2222As. My very basic test circuit that works is the second image. As you can see, from the bewel side of the transistor, the collector is on the right, and the emitter is on the left.QuoteThanks - I'll keep that in mind and do some measurements.QuoteAnd that's when you lost me - not sure what the gain in this context is. I know there's an amplification part of the transistor on the current side. Is that what you mean by gain?

author: bitman
author_rank: Unknown
timestamp: May 19, 2017, 01:55:43 am
content: Quote from: rstofer on May 19, 2017, 01:10:06 amFigured - the positive result I'm hoping for is more knowledge. In the end, the circuit isn't that important (it will help in a bigger project I want to deal with later). And given this is by far over my head (should be pretty clear by now) I think I found an EEPROM that just works off 5v that I can fully control from the Arduino (AT28C640).QuoteThanks - what I need to figure out is how to read that into the diagram. I picked large resistors since I didn't want to push any extra current along the way. The Q3 is a small circuit I have showing I can pull to ground and turn off things by applying voltage to the base. Since I need to drop to 0v for READ, I thought I could use the diode in the same manner allowing the ground to be exposed to the output pin.QuoteSorry about that. I thought just explaining the actual issue without going into a long writeup about "unrelated" stuff would be helpful. I think I finally got KiCAD to do at least something useful, so I can at least produce better diagrams now explaining/visualizing what I'm doing. In the end, I'm just playing with logic circuits and controllers. I thought my need for "fancy" stuff for a few well placed caps, a few resistors and at worst a transistor or two. Nothing beyond that, albeit learning about inductors and other components is mighty interesting but so far I don't have any applications I can use that for. Maybe that will come one day.Unfortunately I got a hold of of a W27C512 (as I put on the diagram) for EEPROM and it uses multiple voltages to signal operation so I found myself having to do more than just the single/dual component thing.QuoteThe EEPROM model was in the sheet but why KiCAD puts it on the side like that and not in the middle, I don't know. Thanks for giving me a lot to think about. Yeah, I totally missed that the diodes drops the voltage too. Still not sure I get the transistor drop, but given they're related that sorta makes sense.I think the next stop for me is reading a bookThanks again.

author: rstofer
author_rank: Super Contributor
timestamp: May 19, 2017, 03:58:37 am
content: If you want to switch from the high side (like delivering a specific voltage to a pin), use a PNP transistor.If you want to switch from the low side (like turning on an LED in the collector circuit), use an NPN transistor.But, even though the PNP will work as a switch, a uC (or whatever) can't stand the required base voltage to turn it off. That's why your original circuit would work well. The NPN was controlling the base of a high side switch. When the NPN was off, the 10k resistor held the PNP base high so no current would flow.There are a couple of transistor relationships that are worth knowing: There must be about 0.7V difference between the base and emitter to get the device into saturation. For the NPN case, the base needs to be higher than the emitter. For the PNP case, the base needs to be lower than the emitter.The other relationship is that, at best, you can get VCESat down to 0.2V - that is, the voltage between the collector and emitter when the transistor is saturated will be about 0.2V. You may not be able to get that far into saturation. The 2N3904 datasheeet suggests it may be difficult to get below 1.0V.I suppose we can add one more relationship: The base current needs to be 1/10th of the collector current to get the transistor into saturation. If you need 100 mA of collector current, you need to design in about 10 mA of base current. This is just a 'rule of thumb' and varies considerably by device. But it's a good place to start!In your original circuit, the 4.3k resistor set the PNP base current. LTSpice shows the output, given a 390 Ohm load as 11.8V at around 30 mA. The PNP has only 0.2V between the collector and emitter which is deeply saturated. That's a good thing.Notice how the 390 Ohm load resistor and the 4.3k Ohm base resistor have a nearly 10:1 relationship.So, you original circuit, with the real transistors simulates pretty well. LTSpice .asc file attached

author: Zero999
author_rank: Super Contributor
timestamp: May 19, 2017, 08:19:25 am
content: Using discrete components is a very good learning experience but if you just want to get this done, why not use a logic level shifting IC specifically designed for the purpose?Check out the CD40109B and CD4504B. Links to data sheets below:http://www.ti.com/lit/ds/symlink/cd40109b-q1.pdfhttp://www.ti.com/lit/ds/symlink/cd4504b-ep.pdf

author: NottheDan
author_rank: Frequent Contributor
timestamp: May 19, 2017, 11:16:05 am
content: Am I missing something or do you have high chance of junking the data in your eeprom via software bug there? Should the software fail to turn off one pin before turning on another for any reason you'll possibly be overwriting your eeprom instead of reading.

author: bitman
author_rank: Unknown
timestamp: May 19, 2017, 01:01:46 pm
content: Quote from: Hero999 on May 19, 2017, 08:19:25 amSo I looked into 4504B and it only seems to support two voltages. I need at least 3 if not 4 of which one of them is ground. I couldn't see how that would work with that circuit. I didn't know about 40109B but reading it seems to have the same issue and the 4504, it's only two voltages. Since they all have to go to the same pin, it didn't look like it was providing me what I needed?You're right though - the learning side of this is probably worth the experience by itself. But I did look into it. I even have a few 4504s lying around but couldn't find a way to use them in my example.

author: bitman
author_rank: Unknown
timestamp: May 19, 2017, 01:03:30 pm
content: Quote from: NottheDan on May 19, 2017, 11:16:05 amThe way I have the 595 setup, it turns on all the bits at once on a clock pulse. I actually have 3 of them in series (the other two is the address). So while OE is always low (enabled) the new values do not leave the storage until the whole byte is ready. So that should not happen.

author: Zero999
author_rank: Super Contributor
timestamp: May 19, 2017, 05:57:16 pm
content: Quote from: bitman on May 19, 2017, 01:01:46 pmLooking at your schematic again. I can see what you're trying to do. The CD40109 and 4504 only shift from one voltage to another. There is a way to disable the output which , with the addition of a longic inverter, would allow you to set the output to 0V, or 12V but that's not what you want here.You certainly do need two transistors. One will not do.Use the circuit posted at the start of the thread, with the PNP transistors with the emitters connected to different voltages and the collectors connected together via Schottky diodes.

author: bitman
author_rank: Unknown
timestamp: May 19, 2017, 06:50:50 pm
content: Quote from: Hero999 on May 19, 2017, 05:57:16 pmHmmm - I do need to be able to set "ground". If that could be the default when there's no signal, it would probably be a better solution than having a signal come in (what if there's no signal etc). When I read the specs of the CMOS and TTL chips it doesn't look like they can handle more than 5v, so I definitely don't think an inverter or similar would be the solution - unless I can isolate them from the higher voltages.QuoteSo when I initially searched for solutions, I definitely saw a lot that used more than one transistor (and lots of discussions for/against and about details). My (most likely faulty) understanding of using two was because one alone couldn't handle the power (ie. isolating the current from the base). Anyway, as I wrote earlier I definitely need to work on my understanding here a bit better. I can see why they would work, but not WHY they're better than just one.QuoteThanks for the diagram! Very helpful indeed. Just in time for my weekend projectsI just got a "bunch" of basic transistors including the 3904 (I just had 3906) so I don't think your timing could have been better. I'll grab a blank board and give this a try. Also, based on other feedback it's clear I need to look at the voltage consumed by the diode and transistor so the end voltage will be what I need it to be.One question - what does RL mean on the transistor before ground? Ok, TWO questions - since 5v is connected directly, it means there's always going to be 5v? I'm not seeing how I can use this to switch the lead to "0v" or close to that.Thanks again!

author: rstofer
author_rank: Super Contributor
timestamp: May 19, 2017, 08:21:25 pm
content: Quote from: bitman on May 19, 2017, 06:50:50 pmThe 7406 Hex Inverter is open collector and can handle up to 30V on the output. It would have to sink whatever current you plan on having available at the output when it tries to hold the output at 0V. Remember, the open collector is either 'open' or conducting to ground. Input logic '0' and the output is whatever it is from the power supply and limiting resistor. Input logic '1' and the output goes to zero with the gate sinking all the current from the power source through the limiting resistor.http://www.ti.com/lit/ds/symlink/sn7416.pdf

author: bitman
author_rank: Unknown
timestamp: May 19, 2017, 09:38:11 pm
content: Quote from: rstofer on May 19, 2017, 08:21:25 pmWhat's the difference between the 7405 and the 7406 ? I have some 7405's around. I've got no problems reversing the logic if that's what it takes.Btw. I'm using a voltage divider to step from 14 to 12. Does that make a difference?

author: Howardlong
author_rank: Super Contributor
timestamp: May 19, 2017, 10:00:22 pm
content: Quote from: bitman on May 19, 2017, 09:38:11 pmYou are stretching my memory a long way back but ISTR it's the max open collector voltage that makes the difference. All are still 5V logic, but on 5V buses back in the 70s it was still common to use OC with pullups rather than tristate as it was cheaper. Higher voltage OC, I bow to those in the know, but I assume it was to drive stuff that needed it like incandescant bulbs etc.

author: rstofer
author_rank: Super Contributor
timestamp: May 19, 2017, 10:14:25 pm
content: Quote from: bitman on May 19, 2017, 09:38:11 pmCheck the datasheet... The 7405 can't handle voltages higher than 5VYou need to think about the impedance of the voltage divider and how the voltage changes as a function of load. I saw that resistor to get the 14V down to 12V and it may, or may not, work. Voltage dividers composed of resistors are always load dependent.You could try a zener diode to drop the voltage by 2 volts and probably get less sensitivity to varying loads. Or, if the voltage isn't terribly sensitive, take 3 voltage drops from a string of diodes. That would drop 14V to about 11.9V

author: Howardlong
author_rank: Super Contributor
timestamp: May 19, 2017, 10:21:58 pm
content: This thread needs a good, slow, video all by itself, it so takes me back to when I was learning this stuff 40 plus years ago. I empathise with the OP, it's deja vu.

author: Zero999
author_rank: Super Contributor
timestamp: May 19, 2017, 10:27:14 pm
content: Quote from: bitman on May 19, 2017, 06:50:50 pm1) I had a quick flick through the data sheet for the EEPROM and I don't see any reason why you'd want to set it to 0V2) It's pretty easy, just replace the permanent 5V with an MCU output pin and add a pull-down resistor (1k to 100k) to hold it at 0V.Quote from: bitman on May 19, 2017, 09:38:11 pmAs mentioned above the output impedance of the voltage divider might cause a problem. The output impedance of a potential divider is equal to the value of both of the resistors in parallel. If you know how much current is drawn from the potential divider, then you can work out how much the voltage will drop, when the load is connected.Where are you getting the 14V from?Perhaps you could use your MCU to control a voltage regulator, rather than switching the supply rail to different voltages?

author: bitman
author_rank: Unknown
timestamp: May 19, 2017, 10:31:52 pm
content: Quote from: rstofer on May 19, 2017, 10:14:25 pmI did - and did again, and sorry I read 20 in the same table I saw voltage, not realizing it specified mA for THAT value. Sorry, I should have read it more careful.QuoteIt's not even close right now. I only see a few volts on the emitter when it's on (it works for the 14v). When there's no connection it goes to about 6v. If I remove the 10K resistor I see 12V through the 8K resistor. I understand that it will change once there's a load on. I'll try to build a simulation to see what's going on.Thanks!

author: bitman
author_rank: Unknown
timestamp: May 20, 2017, 12:16:02 am
content: So I found myself a free (working?) simulator, and here's what I managed to put together:http://www.falstad.com/circuit/circuitjs.html?cct=$+1+0.0000049999999999999996+10.20027730826997+50+10+50%0AR+48+16+16+16+0+0+40+14+0+0+0.5%0Aw+96+16+208+16+0%0Aw+208+16+208+64+0%0Ar+128+16+128+80+0+10000%0At+160+96+208+96+0+-1+12.503891553813759+-0.213922363948587+100%0Aw+208+64+208+80+0%0Aw+128+80+128+96+0%0Aw+160+96+128+96+0%0Aw+128+96+128+128+0%0At+96+144+128+144+0+1+-13.687538069002281+0.09853954511913263+100%0Aw+48+16+96+16+0%0AR+32+144+16+144+0+0+40+5+0+0+0.5%0As+48+144+96+144+0+1+false%0Aw+32+144+48+144+0%0Ar+128+160+128+208+0+4300%0Ag+128+208+128+240+0%0Ad+208+112+288+112+1+0.805904783%0Ar+288+80+288+32+0+1000%0Ag+288+16+256+16+0%0Aw+288+16+288+32+0%0Aw+288+80+288+112+2%0Ar+32+176+32+240+0+8000%0Aw+32+176+48+16+0%0Aw+32+240+32+272+0%0Aw+32+272+208+272+3%0Ar+128+272+128+336+0+10000%0At+176+336+208+336+0+-1+2.7627267997048435+-0.5761672144868921+100%0Aw+176+336+128+336+0%0Aw+208+320+208+272+0%0At+96+352+128+352+0+1+0.5928428000896195+0.5932182747913748+100%0As+96+352+48+352+0+0+false%0AR+48+352+16+352+0+0+40+5+0+0+0.5%0Ad+208+352+288+352+1+0.805904783%0Aw+288+352+288+112+0%0Ar+128+368+128+416+0+4300%0Ag+128+416+128+432+0%0Ar+32+240+128+208+0+47000%0AAnd it agrees with what I'm seeing and I think this is also what @rstofer mentioned. Now to understand WHY.

author: bitman
author_rank: Unknown
timestamp: May 20, 2017, 12:35:03 am
content: Quote from: Hero999 on May 19, 2017, 10:27:14 pmOf course I could be reading this wrong.https://media.digikey.com/pdf/Data%20Sheets/Winbond%20PDFs/W27C512.pdfThe OE is inversed. Ie. you have to set it LOW to read (enable) it (page 7). On the waveform on page 13, OE goes low to enable the output. Granted, "low" can be betwen -0.3 and 0.8 volts - I've seen that as 0v because my simple electronics mind works that way. Am I reading this wrong?QuoteBut that will draw the other lines to 0? I need all 4 signals (14, 12, 5 and 0 volts to go to the same pin. This is why I tried with the diodes, but they don't seem to help with the 0v/grounding issue?QuoteOuch - I just posted a simulation that shows the issue I'm seeing. I'm still not sure why I'm seeing different voltages if the transistor is closed or not, when measuring the potential voltage (I presume that's what the simulator is showing). But I'll read it more careful and knowing there's a parallel circuit will definitely help. The way I was thinking was that since only one line was active at a time, I didn't have to be concerned about additional power/amps being drawn elsewhere. But of course I now have a load on - this "easy" thing is turning out a lot more complicated.QuoteBooster (step up converter). I'm trying to use the voltage I would be supplying otherwise. So I got a simple buck-boost converter that I connect the 5 to, and I adjusted the potentiometer so I got 14v out (now 15 since there's a small voltage drop). Of course doing so has shown me, that the penalty is a constant amp waste even when I don't use the 14v. I thought it was an easy/cheap solution since I suck at creating step-up even when I have a inductor and zener in a basic circuit. Reading up on that made it clear I wasn't ready to make those myself yet, so I got a cheap chinese thing from ebay (I've used similar on my 3D printer). I was going to look into lowering the amperage once I had things working.QuoteYou mean from the analog output have some kind of variable resistor controlled? Not sure how to do that. I'm pretty sure PWM is out of the question here

author: Brumby
author_rank: Unknown
timestamp: May 20, 2017, 02:11:24 am
content: Quote from: bitman on May 20, 2017, 12:35:03 amWhen you mentioned wanting one of several voltages applied to the same point which included 0V, I, too, thought of using a pull-down resistor. The mechanism works like this:When all of your 14V, 12V, 5V, etc. sources are switched off, the target pin has, essentially, no voltage applied to it, so you connect a resistor between that pin and ground to "pull down" any stray voltage on that pin to ground potential - 0V. The value of this pull down resistor needs to be low enough to ensure it does this effectively (Rule 1).When you then activate one of the higher voltage supplies, the voltage is applied to that pin -andthe resistor. The pin gets its voltage - which is what you want - and the resistor gets real current passing through it - which you would want to be as little as possible. For this to happen, value of this pull down resistor needs to be as high as possible (Rule 2). You should consider the biggest voltage it will be subjected to when doing this.Here is where you need to work out a value for this pull down resistor which satisfies Rule 1andRule 2.It is quite common for the range of resistor values for an effective pull-down to be pretty broad. A suggestion has been made for this to be somewhere between 1K and 100K, which sounds reasonable to me.

author: james_s
author_rank: Super Contributor
timestamp: May 20, 2017, 02:59:43 am
content: Quote from: bitman on May 20, 2017, 12:35:03 amThat actually does work. A low pass filter will convert PWM into a steady DC voltage, you can have a crude form of DAC with only a resistor and capacitor.

author: Brumby
author_rank: Unknown
timestamp: May 20, 2017, 03:12:45 am
content: Quote from: james_s on May 20, 2017, 02:59:43 amIt may work - but questions to ask are: how smooth does the voltage need to be and how quickly do the voltage levels need to change?The answer to this will affect your PWM frequency of operation and RC time constant ... and whether it will perform properly.

author: Zero999
author_rank: Super Contributor
timestamp: May 20, 2017, 01:43:55 pm
content: Quote from: bitman on May 20, 2017, 12:35:03 amI didn't read the whole data sheet in great detail.If you want all the voltage many pins, just connect the pins together.If you need different voltages on different pins, then you'll need to build multiple copies of the circuit.QuoteThat's one possibility or you could replace the variable resistor with a potential divider, say for 12V, then use a transistor to connect another resistor in parallel with the lower resistor to bump the voltage up to 14V. Then you should be able to simplify things by using the CD40109 and CD4096.Please post a schematic of the boost converter you're using.

author: bitman
author_rank: Unknown
timestamp: May 20, 2017, 04:01:49 pm
content: Quote from: Hero999 on May 20, 2017, 01:43:55 pmhttp://www.electroschematics.com/wp-content/uploads/2014/07/xl6009-module-circuit.pngIt's a very typical, cheap and often used XL6009.

author: bitman
author_rank: Unknown
timestamp: May 20, 2017, 04:07:53 pm
content: Quote from: Hero999 on May 20, 2017, 01:43:55 pmOuch - this is quite a bit above my current capabilities to understand/use. Btw. speaking of quickly skimming the data sheet, I just realized that deep in the datasheet of the AT28C64B there's a 12V requirement for erase ... *sigh*

author: rstofer
author_rank: Super Contributor
timestamp: May 20, 2017, 04:25:26 pm
content: The reason your simulation doesn't work is that 8k resistor. Even with only 1 mA flowing, that resistor drops 8V. Then a drop for the diode, the transistor, etc, and you're down to just 1V on the output.The 14V output doesn't have a dropping resistor and it seems to work. You need to substitute 2 or 3 diodes in series in place of the 8k resistor.ETA: the 47k resistor is also redundant.

author: Zero999
author_rank: Super Contributor
timestamp: May 20, 2017, 04:33:45 pm
content: Quote from: bitman on May 20, 2017, 04:07:53 pmDon't worry, it won't work anyway. I forgot that you need to be able to draw 30mA from the 14V rail and the CD40109 can only source a few mA.Apart from that, it's not complicated. The CD40109 is just a level shifter. It converts a voltage between 0V and VCC to 0V and VDD. It has another enable input, which turns both output transistors off when connected to 0V, or to VDD or GND (depending on the input) when it's at VCC. It's known as a tri-state buffer and when the enable pin is low (0V), the output is a high impedance, like it's disconnected from the IC (open circuit), when the enable input is high (VCC) the buffer works as usual.In the previous circuit diagram, the L input goes to the level shifter's input and the M input goes to the level shifter's enable, via a logic inverter, and is connected to the output via a diode. When M is 0V, the inverter causes the enable pin, on the level shifter, to be high. The output will then change between 0V and HV, depending on the voltage on L. When M is connected to 5V, the enable pin on the level shifter will be low, causing it to be disabled, its output disconnected from the circuit and 5V, from the M input flows to the output, via the diode.