Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 23 of 23

Thread: Use Mosfet as switch and control it by teensy

  1. #1

    Use Mosfet as switch and control it by teensy

    Hi everybody!

    I'm trying to figure out how to use a mosfet as switch and control it by a teensy. Is it gonna work like this?

    Click image for larger version. 

Name:	Mosfet.jpg 
Views:	14 
Size:	112.9 KB 
ID:	15951

    If so, what resistor should I use as R1?

    Thanks in advance!
    Robert

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    It's not gonna work like this, since there is no common reference potential. Stand by, I'll get my iPad and draw a working schematic for you...

  3. #3
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    Here it is :
    Click image for larger version. 

Name:	fullsizeoutput_20d9.jpg 
Views:	18 
Size:	50.5 KB 
ID:	15952
    R1 serves as a bypass resistor for the gate-source capacitance of the MOSFET and would by around 10kOhm when using a common N-MOSFET like the BS170 as long as the switching frequency wouldn't go up in the RF range which would require smaller values. R2 has to eat up the difference of the battery voltage and the LED's forward voltage (typically 2V) when the LED forward current (typically 20mA) flows. Here (14.4 - 2)V / 0.02A. Next standard value would be 680 Ohm.

  4. #4
    Thank you very much! Just for my better understanding: if the teensy would be driven by a USB hub, which is driven by a DC DC buck converter which is driven by the same 14.4V battery that drives that Led - would my circuit work?

  5. #5
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    Why making it so complicated ? No USB hub is needed for that. You can use a 14.4V to 5V converter and power the Teensy directly via its Vin pin with these 5V.

  6. #6
    True, but it's part of a bigger project where the teensy also serves as USB midi controller

  7. #7
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    So, you might go with the USB hub. The latter will have to power the Teensy and probably other devices present on the hub, so count 500mA per USB device connected for the current which the buck converter should be able to provide.

  8. #8
    Yes it does. So in that case my circuit would work? Are there still advantages of your circuit?

  9. #9
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    Yes, because my circuit would work and yours not...

    You might still try to build yours for pedagogic fun, just to see that in the best case it just would not work and in the worst case (drain-gate capacitance charge current in the mosfet) it could kill your Teensy. I don’t know where you studied electronics, but that’s pretty obvious.

  10. #10
    I'm very new to this stuff. Thank you very much for your help. And since it's the only teensy I have at the moment I will have to renounce this pedagogic fun

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,506
    I would advise against building that circuit.

    Most discrete mosfet transistors have some sort of gate protection circuit built in. Depending on how the other connections are made, though the hub and its power supply, you could possibly end up with a conduction path from the 14.4V power, through that protection circuit, right to the 3.3V only pin on your Teensy.

    Theremingenieur's circuit is good.

  12. #12
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,506
    On the battery, there are 2 common cases for 14.4V.

    If you have 4 lithium ion cells in series, then this warning doesn't apply.

    But if your 14.4V is from the electrical system of a car or truck, where it's 12V with only the battery and 14.4V when the engine is running, then you should plan for the high voltage spikes which most cars alternators produce when the battery is disconnected. You can find plenty of info about this online. Many people have learned of these harsh automotive realities the hard way.

  13. #13
    Thank you for this warning Paul, I will keep it in mind for whenever I will build a automotive project. In this case its 4 lithiom ion cells.

  14. #14
    Senior Member
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    214
    Quote Originally Posted by Theremingenieur View Post
    Here it is :
    Click image for larger version. 

Name:	fullsizeoutput_20d9.jpg 
Views:	18 
Size:	50.5 KB 
ID:	15952
    R1 serves as a bypass resistor for the gate-source capacitance of the MOSFET and would by around 10kOhm when using a common N-MOSFET like the BS170 as long as the switching frequency wouldn't go up in the RF range which would require smaller values. R2 has to eat up the difference of the battery voltage and the LED's forward voltage (typically 2V) when the LED forward current (typically 20mA) flows. Here (14.4 - 2)V / 0.02A. Next standard value would be 680 Ohm.
    Hello Theremingenieur.

    1. Regarding the bypass resistor. would the teensy output being pulled low not acheive the same thing?

    2. I don't think I've seen a series resistor going too the gate but I always wonder what limits the current on the teensy output to charge the gate capacitance?

    I only have basic understanding of electronics and the couple of times I've required to used a mosfet basically as a switch I've used a driver because I wasn't sure.


    Click image for larger version. 

Name:	1.PNG 
Views:	12 
Size:	43.8 KB 
ID:	15963

  15. #15
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    Quote Originally Posted by Gibbedy View Post
    Hello Theremingenieur.

    1. Regarding the bypass resistor. would the teensy output being pulled low not acheive the same thing?
    Yes, as long as the Teensy is powered. With the Teensy off and the pin in hi-Z state, the Mosfet needs a defined state though, to protect the metal oxide gate isolation layer.

    Quote Originally Posted by Gibbedy View Post
    2. I don't think I've seen a series resistor going too the gate but I always wonder what limits the current on the teensy output to charge the gate capacitance?
    A series resistor as a current limiter or even an additional more powerful driver stage can be needed for power mosfets with higher gate capacitance. Here, since we are only switching one single 20mA LED, a small signal mosfet like a BS170 is sufficient. Its gate capacitance is small enough to not harm the Teensy's internal GPIO drivers which can source or sink 10mA.

    Quote Originally Posted by Gibbedy View Post
    I only have basic understanding of electronics and the couple of times I've required to used a mosfet basically as a switch I've used a driver because I wasn't sure.
    If you aren't sure, using a driver or buffer is never wrong. But aren't you curious to fully understand the way of each single electron before you take the soldering iron in hands? I don't know how things are taught nowadays in schools and universities, but when I was young, people had to successfully finish their first year of theoretical semiconductor physics before they were allowed to experiment with CMOS stuff...

  16. #16
    Senior Member
    Join Date
    Feb 2016
    Location
    Australia
    Posts
    214
    Thanks for quick reply.
    That's cleared that up.

    I regret dropping out of uni (around 15 years ago), but I blame age of empires II more than the universities course structure.

  17. #17
    Since I realised that I feel way safer with a high side switch and want to avoid ground loops, I decided to replace the nmos with a pmos and use an optocoupler. Is there anything wrong with this circuit?

    Click image for larger version. 

Name:	Optocoupler.jpg 
Views:	13 
Size:	33.9 KB 
ID:	16034

  18. #18
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    Why don’t you just try it out?

  19. #19
    Because I dont have those parts yet and it's Saturday night

  20. #20
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,506
    Quote Originally Posted by Gripporillat View Post
    Click image for larger version. 

Name:	Optocoupler.jpg 
Views:	13 
Size:	33.9 KB 
ID:	16034
    This is a rather strange way to draw a schematic. While it may be technically correct, when using schematics to communicate with other humans, you really should follow the long established conventions.

    Schematics are arranged so the more positive voltages are towards to top and most negative at the bottom.

    Usually signal or data flow (or causal effects) are arranged left to right, where inputs are on the left side and outputs are on the right.

  21. #21
    Quote Originally Posted by PaulStoffregen View Post
    This is a rather strange way to draw a schematic. While it may be technically correct, when using schematics to communicate with other humans, you really should follow the long established conventions.

    Schematics are arranged so the more positive voltages are towards to top and most negative at the bottom.

    Usually signal or data flow (or causal effects) are arranged left to right, where inputs are on the left side and outputs are on the right.
    Yes, I'm sorry for that. I couldn't find a pmos symbol in Kicad where the source pin is the top pin so I tried to arrange the rest in a still somehow understandable way. I seem to have failed.

  22. #22
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,277
    I guess that Kicad does allow rotating and mirroring components, as Eagle and many other CAD tools do.

  23. #23
    Of course you're right. Obviously I knew about the rotating function but somehow I didn't think about the possibility of mirroring objects. So this is hopefully better readable:

    Click image for larger version. 

Name:	Optocoupler.jpg 
Views:	11 
Size:	36.1 KB 
ID:	16035

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •