Any Arduino, Teensy, ESP32, Pi, etc. folk?

UKworkshop.co.uk

Help Support UKworkshop.co.uk:

This site may earn a commission from merchant affiliate links, including eBay, Amazon, and others.

Dibs-h

Established Member
Joined
23 Jul 2007
Messages
4,515
Reaction score
225
Location
Bradford, West Yorkshire
Does anyone "tinker" with any of those boards\controllers? More so the interfacing "out" of them?

High side switching using P channel mosfets in particular?

Cheers.
 
Sure, generally you'll want to form a low side switch first to create the gate voltage for the high side switch, see the pic - things can sometimes be simplified if you have an open collector or open drain output at your disposal.

R1 can generally be high to minimise waste power - values of 100K-1M are fairly typical. V[LOAD] can be a lot higher than the supply to the controller.

What kind of voltage, current and switching speed are you expecting for the load? I would be able to suggest suitable parts.

Any other more specific issues?
 

Attachments

  • IMG_20230125_000135.jpg
    IMG_20230125_000135.jpg
    1.1 MB · Views: 0
@ajs,

Cheers for the reply. I was thinking of using an npn transistor rather than the (looks like) an n channel mosfet.

The load would be a 21W 12V bulb - purely resistive, so I think a freewheeling diode isn't required.

The load voltage would be 13.6V - 14.5V.

The io port would output (high) would be 5v & 20ma.

Switch speed - very very slow. LOL Switch the bulb on, then some time later (mins) turn it off.

Other issues:

I've been reading a ton and from what I understand (over-statement) Rds(on) should be low given I want to switch 2A and would prefer not to generate (much) heat. It should also be quoted for 5 or so volts in the datasheet.

This lead me to look up what RS has in stock and look at SMD ones. I want to do the whole circuit in SMD.

I'm getting familiar with the "curves" for Transfer Characteristics etc. but really want to get my head round how the values are calculated for the various resistors: the pullup for the p channel mosfet, the base resistor into the npn, and the pull down resistor base on the npn (which a ton of webpages say is needed otherwise the p channel mosfet won't behave as expected).

I hope the above isn't jibberish (the other issues bit). :)
 
Last edited:
OK, I wasn't expecting you to go SMD but you seem to have a grip on most of the basics. To cut a long story short I suggest a BC817-40 for the input from the MCU, 100K for the pull up (R1 in my circuit diagram), perhaps 2.2K on the base of the 817, and a DMP3097L-7 for switching the lamp. The latter are £1.85+VAT in a pack of 25 from RS.

Obviously these values don't come from thin air, so to summarise selection:

Start with the load. In round terms we're switching 12V DC @ 2A and we want a P channel MOSFET in SMD packaging. To select a part I put those values in the MOSFET parametric search and order by ascending price before browsing through the list for likely candidates. While I'm browsing the listings I'm bearing few things in mind. Firstly you don't want to buy them buy the reel, you want a small number, if not 1s and 2s you certainly don't want to spend £10+ in total. Secondly the part has to be in stock - this is a key factor at the minute given the disruption in semiconductor supply chains, it's never recovered from COVID. Next the key technical parameter I'm looking at is RDS(ON) since as you identify that's the key for how hot it's going to get in the on condition. To be honest exact values are finger in the ir stuff, I begin with a feeling that a power dissipation of 200mW or so it reasonable for typical SMD transistors so at 2A I want 0.1R or less simply from Ohm's law.

Scanning through the list for likely candidates I arrive at the DMP3097 using the above observations. Open the data sheet and flick through it. Notice it quotes a PD of 1W for a SOT23 package (yes, my preference is deliberately conservative) so our initial assumptions seem fine. No big oddities so that's our one.

Pull up resistor (our R1) is pulled from air with a bit of experience. Input impedance of a MOSFET is going to be very high (10M+) to the extent you can basically call it infinite. That means we can save power with a large value but a bad idea to go really high, if currents get too small leakage and even contamination on the circuit board can start having noticeable effects. 100K chosen as a sensibly high value, may choose to got lower, paossibly down to 47 or even 22K, after all at this level the additional power saving is miniscule.

Low level switching transistor - BC817. That's just my bog standard general purpose SMD NPN. We're not asking it to do anything remotely special here (speed, pwer etc) so I don't even think about it. Go for the -40 variant, it has a higher minimum gain which can save power into the base.

Base resistor. Here I'll consider the properties of what's driving the input but generally figure it's going to be at least TTL compatible in the key metrics - for us that is low voltage is 0.4V or less, high voltage will be 2V or more, don't want to source or sink more than perhaps 1mA. These are generally compatible assumptions for anything from 3.3V CMOS to 5V TTL provided the output isn't driving anything else at the same time. Collector current is insignificant here, but a basic low level switch I tend to plonk in from memory if it's under 100mA or so. The BC817-40 has a gain of at least 250 at that current, so we're looking at 100/250=0.4mA at the base. In the on condition work on the basis the base is at 0.7V and the input is at 2V, that gives 1.3V across the resistor. Again Ohm's law gives 1.3/0.0004 = 3.25K. Call it 2.2K as a standard value that gives us a nice margin even in our worst case conditions.

As for a pull down resistor on the base, generally not with a bipolar transistor and it is the only load on the output. Logic families can allow the "low" voltage to rise up past the switching threshold but at the input, the output is generally far switcher. Since the transistor is either effectively not there when turned off, or pulling it down when turned on, you don't need a pull down to form a potential divider and adjust the switching threshold voltage.
 
@ajs,

Cheers for the info.

RS - I wish there was a filter for removing the "reel" option. :rolleyes:

For a pull down resistor on the base of the NPN (and the IO pin), the reasoning I came across (if I understand it correctly) was that in the case of Arduino (and others), on power up - the IO defaults to input (high impedance) and the pin would effectively be floating (or driven high), so you could get random switch on's until the Arduino powers up, boots up and the IO pin has been set (as output) and driven low. Effectively holds the mosfet off whilst the controller boots up.

In this circuit's case - power cycling of the controller would be happening more often than not.

Would it be useful to have a low resistor between the collector of the NPN and the gate of the Mosfet? Say a couple of 100 to limit any current spike when the NPN turns on? Or not necessary?

Cheers.
 
For a pull down resistor on the base of the NPN (and the IO pin), the reasoning I came across (if I understand it correctly) was that in the case of Arduino (and others), on power up - the IO defaults to input (high impedance) and the pin would effectively be floating (or driven high), so you could get random switch on's until the Arduino powers up, boots up and the IO pin has been set (as output) and driven low. Effectively holds the mosfet off whilst the controller boots up.
A bipolar NPN needs to be sourced current to the base in order to turn on. If the I/O is in input mode that shouldn't happen unless there are weak pull-ups in play, you'll need to read up your specific docs.

Would it be useful to have a low resistor between the collector of the NPN and the gate of the Mosfet? Say a couple of 100 to limit any current spike when the NPN turns on? Or not necessary?
I wouldn't bother, the capacitance involved here that could possibly cause any spike will be tiny, and the BC817 isn't a terribly fast switching transistor in any case. In short, nothing to worry about.
 
A bipolar NPN needs to be sourced current to the base in order to turn on. If the I/O is in input mode that shouldn't happen unless there are weak pull-ups in play, you'll need to read up your specific docs.
I'll have a read up on the docs. Worst case, I could put a "space" & tracks for it on the PCB. That way I could later fit one if need be.

I wouldn't bother, the capacitance involved here that could possibly cause any spike will be tiny, and the BC817 isn't a terribly fast switching transistor in any case. In short, nothing to worry about.

Cheers - I'll skip it. RS seemed to have none in stock and after 20 mins of messing about trying to find out what they had in stock as alternatives, check eBay and bingo. LOL

Many thanks!

Dibs
 
You have not provided any circuit, normally you use high side switching because you cannot use low side switching as in applications such as switched mode power supplies as in push pull and bridge topologies. For those I used to use dedicated high side switch drivers from SG Thompson.

The load voltage would be 13.6V - 14.5V.
sounds like an automotive application .
 
You have not provided any circuit, normally you use high side switching because you cannot use low side switching as in applications such as switched mode power supplies as in push pull and bridge topologies. For those I used to use dedicated high side switch drivers from SG Thompson.


sounds like an automotive application .
Yep - automotive, so can't switch the GND.
 
Yep - automotive, so can't switch the GND.
Why not lowside, having worked on engine management systems we always supplied ignition power to one side of for example the injectors and the module switched the low side, it is how most automotive switching is done. Even on some vehicles like my Honda Crv the headlamp relays are supplied battery voltage and the colomb stalks just switch to ground, they could easily have switched high side as no solid state switching devices.

Are you dealing with something like a light unit which is grounded through the bodywork metal and so you can only handle the live side ? If so why not use a small solid state relay like this https://www.st.com/en/automotive-analog-and-power/vn920b5-e.html#st_all-features_sec-nav-tab

This also provides a status signal and some protection.
 
Why not lowside, having worked on engine management systems we always supplied ignition power to one side of for example the injectors and the module switched the low side, it is how most automotive switching is done. Even on some vehicles like my Honda Crv the headlamp relays are supplied battery voltage and the colomb stalks just switch to ground, they could easily have switched high side as no solid state switching devices.

Are you dealing with something like a light unit which is grounded through the bodywork metal and so you can only handle the live side ? If so why not use a small solid state relay like this https://www.st.com/en/automotive-analog-and-power/vn920b5-e.html#st_all-features_sec-nav-tab

This also provides a status signal and some protection.
Yep it's a light that's already grounded at the other end - so don't think I have a choice other than high side switching of some kind.

Cheers for the link to the solid state relay - I'm open to it if the availability is there (no for that one, they're classed as obsolete) and price isn't stupid. I'll have a look on Mouser\RS. Oh and heat doesn't become an issue switching 2A.

Cheers.
 
RS seemed to have none in stock and after 20 mins of messing about trying to find out what they had in stock as alternatives, check eBay and bingo. LOL
Sorry, I hadn't even thought of that - I did say it was an "on autopilot" spec. As I hinted at those assumptions are based at switching anything up to 100mA, since your application is nowhere near that a BC817-25 or even -16 will do without switching any surrounding components and easier to source from RS at least.
 
Sorry, I hadn't even thought of that - I did say it was an "on autopilot" spec. As I hinted at those assumptions are based at switching anything up to 100mA, since your application is nowhere near that a BC817-25 or even -16 will do without switching any surrounding components and easier to source from RS at least.
No apologies necessary. ;)

It's all part of the learning curve - finding alternatives. If eBay had none (10 for £1.55 delivered, which is probably on par or better than RS), I would have asked if x, y or z were good alternatives.

On a related note - I've been using easyeda.com which is free and I can draw my regular schematic, then convert to PCB and have full control over the tracks, vias, etc. I can also download the files if I want to send them to an outfit to produce me the PCB's. I find it really straightforward and fairly intuitive. Well after skimming through a couple of YouTube vids. :D

The Simulator side isn't too bad - it has the "models" for many things, just not all things.
 
Last edited:
Back
Top