A
Arduino3mo ago
Patrick

Bidirectional I/O buffer

For something I am making I am going to have each I/O pin of a microcontroller controlling the gate of a transistor or MOSFET. But I also want to use those I/O pins as inputs while only connecting devices to the drain or source of each transistor. Is there a type of transistor that would allow current to flow back through the body to the gate? Or would I need some extra components to do that reliably.
115 Replies
Patrick
PatrickOP3mo ago
All I am really familiar with are n-channel MOSFETS
AnonEngineering
AnonEngineering3mo ago
the pins going to the base of a BJT or gate of a MOSFET are outputs, not sure what you are trying to do
Patrick
PatrickOP3mo ago
and if I used those pins as inputs, I would need to be able to send them a signal but from the source or drain of the mosfet since I won't be able to reach the bare pins by themselves
AnonEngineering
AnonEngineering3mo ago
the gate is an input to a MOSFET, still don't know what you are trying to do
Patrick
PatrickOP3mo ago
this might make more sense
No description
AnonEngineering
AnonEngineering3mo ago
what is the drain driving? if the voltage is ok you could monitor it on a second INPUT pin, but not on the pin driving the MOSFET, which is an OUTPUT
Patrick
PatrickOP3mo ago
the drain could be driving anything, it is acting as the I/O Pin but able to support more power when it is used as an input, the mosfet wouldn't have a purpose anymore until the pin is used as an output again
AnonEngineering
AnonEngineering3mo ago
as shown it's an "open drain", if can be brought LOW, but when the mosfet is off it's just floating. typically the drain is connected to a load which is in turn connected to X voltage
Patrick
PatrickOP3mo ago
so forgetting about the input feature for now 😅 , Is there any way I could make something like this work? This setup with the n channel mosfet and the load on the source would need a higher VGS than normal I think?
No description
AnonEngineering
AnonEngineering3mo ago
that is "high side switching", you typically use a P-channel for that
Patrick
PatrickOP3mo ago
This is what I had made earlier
No description
AnonEngineering
AnonEngineering3mo ago
see the direction of the "arrow"
Patrick
PatrickOP3mo ago
though I would need the microcontroller logic to be the same as that 5V which I also wanted to avoid
AnonEngineering
AnonEngineering3mo ago
you often need a driver for the switching element when you do high side
AnonEngineering
AnonEngineering3mo ago
No description
Patrick
PatrickOP3mo ago
this way would allow the microcontroller logic to be lower than the VCC?
AnonEngineering
AnonEngineering3mo ago
yes, a 3.3v GPIO could drive a load powered by 5 or 12v for instance
Patrick
PatrickOP3mo ago
is there some other setup where I use just one transistor?
AnonEngineering
AnonEngineering3mo ago
you need to be able to drive the gate up to Vcc to fully turn the P channel off
Patrick
PatrickOP3mo ago
same deal with any p channel transitor? or really any semiconductor that could work like that
AnonEngineering
AnonEngineering3mo ago
yes, same with PNP BJTs
Patrick
PatrickOP3mo ago
alright thank you oh also, could I use this with 0v turning off the p channel mosfet and 5v turning it on instead of the other way around? I should rephrase, 0V going to the transistor that then turns the p-channel mosfet off, and 5v turning it on?
AnonEngineering
AnonEngineering3mo ago
for BJTs you need a current flowing base to emitter to turn it on, for MOSFETS you need a voltage source to gate so for a p-channel with the source sitting at Vcc you need to bring the gate up to Vcc for it to turn off
Patrick
PatrickOP3mo ago
but with that transistor driver, could I give it 0v to make it turn off the main mosfet and give it 5v to turn on the main mosfet?
AnonEngineering
AnonEngineering3mo ago
5v to the base of the NPN will turn it on, pulling the gate of the MOSFET LOW, which will turn it on (because now there is a voltage Source to Gate)
Patrick
PatrickOP3mo ago
okay good, so it already works like that and 0v to the base of the transistor will turn the mosfet off
AnonEngineering
AnonEngineering3mo ago
technically, 0v on the base causes 0 current to flow base to emitter, shutting off the NPN since the NPN is off no current flows in the collector circuit so the gate goes HIGH now the gate is the same voltage as the source, so no current flows Source to Drain
Patrick
PatrickOP3mo ago
that's still fine right?
no current flows Source to Drain
no current flows Source to Drain
AnonEngineering
AnonEngineering3mo ago
in the end that is what you are controlling, whether current can flow thru the load or not
Patrick
PatrickOP3mo ago
And I don’t want current to flow through either if it is at 0V, so it’s right, right? Also if I want to go back to this where the max vcc is the logic voltage If I wanted 5v to turn it on and 0V to turn it off would I be able to use some logic gate that would flip the signal? So when I output a high signal the mosfet turns on instead of off and vise versa
AnonEngineering
AnonEngineering3mo ago
for low side switching just the NMOS will do
Patrick
PatrickOP3mo ago
What would be the VGS limitations that I have heard about?
AnonEngineering
AnonEngineering3mo ago
say your MOSFET needs 10v Vgs to turn on, how well will that work with an Uno pin?
Patrick
PatrickOP3mo ago
that not at all 😆 is that the only limitation with high side switching compared to low side? isn't it the same either way? sorry I got low and high side confused with each other would it still works for high side switching, because that's what i really need
AnonEngineering
AnonEngineering3mo ago
yes, Vgs is the minimum voltage you need to turn it on
Patrick
PatrickOP3mo ago
so this would work right?
No description
Patrick
PatrickOP3mo ago
im confused why the current moves so slow with high side switching than with low side
AnonEngineering
AnonEngineering3mo ago
no, you need a p channel
Patrick
PatrickOP3mo ago
okay so back to this then, would some type of logic gate that flips the signal be the best option? so 5v turns into 0v to turn it on and 0v turns into 5v to turn it off
AnonEngineering
AnonEngineering3mo ago
if the mcu is 5v and Vcc is 5v that is a special case you can then set a pin high enough to turn a p channel off
Patrick
PatrickOP3mo ago
but i would rather it be the other way around, where that high 5v signal turns it on instead of off which I would need something to flip the signal
AnonEngineering
AnonEngineering3mo ago
digitalWrite(myPin, HIGH); or digitalWrite(myPin, LOW); 🤷‍♂️
Patrick
PatrickOP3mo ago
of course this haha, but it's more un-conventual for the high signal to be turning something off and the low signal be turning something on, at least for beginners
AnonEngineering
AnonEngineering3mo ago
in any case, setting the pin HIGH will turn off the p channel, since it seems you need high side switching
Patrick
PatrickOP3mo ago
I think this is what I want
No description
No description
Patrick
PatrickOP3mo ago
when the output pin is high, the p channel turns on because of the inverter changing the signal to 0v and the other way around
AnonEngineering
AnonEngineering3mo ago
yes, if you don't want to do it in code the NPN transistor does that very thing
Patrick
PatrickOP3mo ago
i just simply wanted to flip the signal so I (or others) don't have to do it in code
AnonEngineering
AnonEngineering3mo ago
right, the NPN is the inverter in your drawing
Patrick
PatrickOP3mo ago
are you talking about the npn transistor here acting like the inverter
Patrick
PatrickOP3mo ago
ah alright
AnonEngineering
AnonEngineering3mo ago
and it becomes more general purpose because you can use higher Vcc's
Patrick
PatrickOP3mo ago
I would do it like that, but it requires a lot more resistors
AnonEngineering
AnonEngineering3mo ago
you only need 3 or 2
Patrick
PatrickOP3mo ago
sounds more enticing
AnonEngineering
AnonEngineering3mo ago
you must limit the base current to the NPN, and you need the collector resistor
Patrick
PatrickOP3mo ago
let me get your opinion on this, the project is for a very beginner friendly dev board that has some of the I/O pins connected to this mosfet circuitry we have been talking about, so that people can run motors or a bunch of leds straight off the gpio pins. but do you think i should make it with the vcc being the same as the microcontroller logic, or doing as you seem to like more, with the vcc being anything and not just the microcontroller 5v logic. the downside to that it may be more confusing with so many ports for different supply voltages, im not sure if it would be that beginner friendly anymore.
AnonEngineering
AnonEngineering3mo ago
the voltage needed is totally dependent on what the user decides to hook up and on the limitation of the MOSFET what if i want to control a 12v pump?
Patrick
PatrickOP3mo ago
and that's the bright side i feel like the good would outweigh the bad especially if i made it simple enough
AnonEngineering
AnonEngineering3mo ago
i really can't say without knowing your audience
Patrick
PatrickOP3mo ago
anyone new here trying to run motors off 2 I/O pins alone
AnonEngineering
AnonEngineering3mo ago
you only need 1 per motor
Patrick
PatrickOP3mo ago
well you know what i mean 😆
AnonEngineering
AnonEngineering3mo ago
afraid i still don't, this is where we started
Patrick
PatrickOP3mo ago
that was somewhat irrelevant anyways this might be a better explanation I am making a dev board like an Arduino UNO, but each gpio pin can output a 1A or so. And I am allowing those pins to output up to 1A by using these mosfets to switch power so when you would normally set an output high on your board, it will set the output high on this board but just more available power
AnonEngineering
AnonEngineering3mo ago
you have a 20A power supply?
Patrick
PatrickOP3mo ago
I was just throwing 1A out there as a number, it probably wouldn't actually be that high
AnonEngineering
AnonEngineering3mo ago
that x 20 pins...
Patrick
PatrickOP3mo ago
well do you get the concept 😅
AnonEngineering
AnonEngineering3mo ago
you'll need to be able to deliver enough power is all i'm saying or you're depending on these beginners to supply external power?
Patrick
PatrickOP3mo ago
I realized now I will also need a different mosfet setup to work the same way as a output pin
AnonEngineering
AnonEngineering3mo ago
they are push pull good luck with it, gtg
Patrick
PatrickOP3mo ago
this is the new design
No description
Patrick
PatrickOP3mo ago
thanks a lot for your help as usual haha
Patrick
PatrickOP3mo ago
No description
Patrick
PatrickOP2mo ago
hopefully I will have enough space for all of these output buffers Now I need to figure out how to bypass all of this to use the gpio pins as inputs I was thinking I could use some logic gates that tell when the pin is being used as an input and change this signal on the microcontroller side, but it never worked
AnonEngineering
AnonEngineering2mo ago
here's how Atmel does it 😉
No description
Patrick
PatrickOP2mo ago
Haha
Patrick
PatrickOP2mo ago
No description
Patrick
PatrickOP2mo ago
It seems like that turns off the pull up resistor for the input And is this the output buffer below?
Patrick
PatrickOP2mo ago
No description
AnonEngineering
AnonEngineering2mo ago
that is how they configure the pin GPIO
Patrick
PatrickOP2mo ago
Ohhhh
AnonEngineering
AnonEngineering2mo ago
INPUT, OUTPUT, INPUT_PULLUP
Patrick
PatrickOP2mo ago
Where are the input and output buffers
AnonEngineering
AnonEngineering2mo ago
you circled the tri-state output buffer, input is on the bottom
Patrick
PatrickOP2mo ago
No description
Patrick
PatrickOP2mo ago
So that is the input buffer?
AnonEngineering
AnonEngineering2mo ago
yes, and the rest is the logic necessary to set the pinMode
Patrick
PatrickOP2mo ago
Ah okay thanks Also, did you say this to the first image Or to this one
AnonEngineering
AnonEngineering2mo ago
that is the circuitry connected to each GPIO pin
Patrick
PatrickOP2mo ago
gotcha, then which is the one that configures Input, output, or input_pullup? That’s an explanation of it?
AnonEngineering
AnonEngineering2mo ago
as nis said, yes, that whole thing is what configures each pin
Patrick
PatrickOP2mo ago
which datasheet are you guys looking at, because mine has everything in a different order https://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A-PA-88A-PA-168A-PA-328-P-DS-DS40002061B.pdf I did find the general digital i/o diagram though. and let me get this straight, this only connects the pull up resistor this is just the input buffer and im still not sure what this is
AnonEngineering
AnonEngineering2mo ago
it is how the chip sets the pin to INPUT, INPUT_PULLUP, or OUTPUT, it does all of those things
Patrick
PatrickOP2mo ago
alright thanks, i wasn't sure what you were replying to the first time could you explain how it sets the pin to the different states?
AnonEngineering
AnonEngineering2mo ago
the logic gates read the various "W" states and based on that the pin behaves differently
Patrick
PatrickOP2mo ago
what is "W"?
AnonEngineering
AnonEngineering2mo ago
No description
AnonEngineering
AnonEngineering2mo ago
those registers are set with the pinMode statement which is all to say this is not as trivial as you might have imagined
Patrick
PatrickOP2mo ago
yes haha im still confused how that buffer alone could change to the different modes, i can see how the input pullup would be triggered, but not changing the needed circuitry from input to output I also don’t know what the “pinout” of that buffer is compared to the buffer in my circuit My question there being what are the output and input lines for that symbol
AnonEngineering
AnonEngineering2mo ago
if you look along the "data bus" line ALL those signals are generated inside the mcu and toggle the logic as needed, enabling / disabling the input and output buffers on the far left is the pin in question, of which there are 20 on the 328 DIP package and that diagram is a "block diagram", it isn't showing all the components needed, just the general idea of how the pin mode is changed
AnonEngineering
AnonEngineering2mo ago
the circuit you were making last night is this part
No description
Patrick
PatrickOP2mo ago
that makes more sense than just the symbol above being the thing that changes it and I do understand this, but all the lines connecting to the symbol have to mean something, and I don't know what they mean for example, is the top line coming out of it enable the buffer or something similar? If I could “sense” that the pin turned into an input, I might be able to use a transistor to disable the buffer or connect a wire to bypass it
Patrick
PatrickOP2mo ago
I had came up with this, but i would need a way to break that bottom connection when the pin turns into an output again
No description
Patrick
PatrickOP2mo ago
thanks for all of this, but I think i figured it out!
Patrick
PatrickOP2mo ago
No description
Patrick
PatrickOP2mo ago
I also realized I could cut one diode out
No description
Patrick
PatrickOP2mo ago
well I also just realized I could do this to get the same affect, still not sure about the different vcc's though.
No description
Patrick
PatrickOP2mo ago
I was thinking, if I could use something to detect a lower voltage on the right side, then I could switch off one of the buffers, is there something I could do that with? scratch that because it would have to be either a high or a low signal to get it to the other side
AnonEngineering
AnonEngineering2mo ago
tbh, I'm not sure what I'm looking at here without access to the registers you'd need switches to configure each pin manually, not beginner friendly at all
Patrick
PatrickOP2mo ago
Im not even sure if I should use this or not anymore for the digital I/O outputs, since I am not able to use it for the analog I/O

Did you find this page helpful?