2
\$\begingroup\$

I am using attiny45 microcontroller for switching MOSFET at 40kHz. I have the following circuit set up:

schematic

simulate this circuit – Schematic created using CircuitLab

If I measure the signal coming out of the uC without anything connected to it, I can see the modulated 40kHz signal. But as soon as I connect the circuit to it, I get unusual single spike with length anywhere between 1us to 20us and it looks something like this:signal

What could be the problem? Is it maybe a faulty microcntroller?

EDIT:

If I use function generator at 40kHz and some modulation, the MOSFET is switching correctly.

EDIT2:

I have this assembled on a breadboard and the uC is running from 16MHz external crystal, do you think this could be the cause?

I used a new attiny85 and added a series resistor as was suggested but now, if I connect the MOSFET driving circuit to the uC I get gibberish from the uC although it does slightly resemble the wanted signal.

And again if I disconnect the driving circuit, the signal coming out is exactly what is wanted.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ Why do you have the BJT push-pull stage at all? Can't you just drive the gate of the MOSFET directly from the microcontroller? \$\endgroup\$
    – tcrosley
    Commented Jan 17, 2015 at 18:35
  • \$\begingroup\$ @tcrosley I've only added it because I thought that this was the problem at first, so I just left it there for now. \$\endgroup\$
    – Golaž
    Commented Jan 17, 2015 at 18:37
  • \$\begingroup\$ Is it possible that the power supply is insufficient? Stick your scope on the 5V line and check what's going on. \$\endgroup\$
    – user39382
    Commented Jan 17, 2015 at 18:40
  • \$\begingroup\$ @duskwuff I've done that and it seems to be alright, also the reset doesnt get triggered. \$\endgroup\$
    – Golaž
    Commented Jan 17, 2015 at 18:41
  • \$\begingroup\$ Where are the base resistors on the BJTs? \$\endgroup\$ Commented Jan 17, 2015 at 18:43

5 Answers 5

6
\$\begingroup\$

I notice that you do not have a single decoupling capacitor in the schematic. Each time the MOSFET switches on or off, there can be some very high transient currents. If you don't have any decoupling capacitors, those transient currents will work against the resistance and inductance of the power rails and cause all sorts of problems like noise and resetting the MCU.

The MCU should have a 100nF capacitor or so. Also put another between the collectors of the push-pull stage.

Finally, think about where the current is flowing when you switch the transistor. There's a loop current flows through when you turn it off, and another loop when you turn it on:

schematic

simulate this circuit – Schematic created using CircuitLab

Adjust your layout to make these loops as small as possible. A smaller loop means a smaller inductance, and you want a small inductance to minimize the voltage variation when you create those transient high currents.

There's also a less obvious loop through the drain of M1. Remember that M1 has some capacitance, and as you turn it on or off some current must flow through M1 to change the voltage across that capacitance. It would be too messy if I drew all the arrows though, so just remember that Vcc is as important as ground, and keep all those connections short.

\$\endgroup\$
1
  • \$\begingroup\$ Works perfectly, didn't know that transient currents can have such a significant effect on the power supply. Thanks. \$\endgroup\$
    – Golaž
    Commented Jan 18, 2015 at 11:30
3
\$\begingroup\$

Probably there is a grounding issue, the high current is putting a transient on the microcontroller ground. Try powering the micro from a separate power supply and running two conductors to the power circuit, with its own 5V supply.

There's nothing wrong with using the two BJTs with no base resistor (they're emitter followers) in fact you can use a single gate resistor rather than two (tie the emitters together directly).

\$\endgroup\$
0
\$\begingroup\$

You're talking about a MOSFET, but you've depicted a Bipolar Junction Transistor (BJT) in your schematic. You really ought to have a current limiting resistor between the microcontroller and the bases of Q1 and Q2. To pick a value, assume there is a voltage drop of 0.7V between the base and the collector (connected to GND) of Q2. The current drawn through that path will be multiplied up by the BJT beta factor. That is to say the current through the emitter-colector junction of Q2 will be (at most) beta * ( 0.7V / R ), where R is the resistor you put in series with the base and beta is a property of your BJT from its datasheet. If you want to skip all the math, just put like a 150 ohm resistor in there and see if you get a better outcome.

\$\endgroup\$
2
  • \$\begingroup\$ I am takling about MOSFET because at first there wasnt push-pull stage and I got the same result. \$\endgroup\$
    – Golaž
    Commented Jan 17, 2015 at 18:24
  • 1
    \$\begingroup\$ Huh? Those BJTs are in a common-collector, not common-emitter configuration. No base resistors necessary or desired. The whole point of the BJTs is to amplify the current the MCU can deliver to the MOSFET. \$\endgroup\$
    – Phil Frost
    Commented Jan 17, 2015 at 20:50
0
\$\begingroup\$

I think the problem is due to the high currents that flow charging up the BJT input caps and MOSFET gate caps at the rising/falling edge. This high current getting pulled through the output resistance of the uC is causing a voltage drop. Remember voltages across capacitors cannot change instantly and some oscillations are unavoidable.

However, I think this problem could easily be solved by replacing the BJT stage with two common emitter inverter stages, with ~1k Ohm collector resistor on the first and the same or less (100 or so minimum) for the next stage. You would need two NPN BJT's and some resistors (values can vary a lot, just in the 1k then 500 range). From the uC to the base-input of the first BJT put some small sized resistor (around 200 Ohm or so).

schematic

simulate this circuit – Schematic created using CircuitLab

All this does is buffer the output through two inverters. Almost anytime you see a signal behaving normally when unloaded and have some droop or oscillations when connected to their load, you can be sure it is a 'loading problem'. This just means the output resistance of the original signal is low enough to drive the pin, but not the load you are trying to connect to it. So try a buffer! If the beta of the BJT's is 80+ it should saturate the output voltages at the rails.

Consider a switch to high at the uC output. Now the only capacitance seen by the uC is one base-emitter junction, and it's high transient spike is limited by the 200Ohm resistor. This high output turns the BJT on and causes the output node (collector) to drop to the saturation voltage (very low, maybe .2V). This in turn causes the 2nd stage to stop conducting, and the MOSFET gate is pulled up to VDD through the 500Ohm resistor. This charge/discharge speed can be set by the value of the output resistor. Lower values of resistance will cause a faster switch but also dissipate more power and cause larger transient spikes.

I will also say that maybe there isn't even a problem here. A small dip like that at the output is not low enough to turn off the LED. If you zoom in on any signal enough it will start to look dirty.

\$\endgroup\$
0
\$\begingroup\$

The spike seen in the micro signal is either the power supply droop, (you are pulling a 600ma pulse from the supply), or the micro pin cannot supply enough current to drive the transistor base.

When you see this spike on the micro signal check to see if you have a similar spike on your micro Vcc line. Adding decoupling caps on the 5v line at one or more places (such as R3, Q1, and micro Vcc) can help. You may need larger then the suggested 100nf.

The micro output line needs to supply a moderately high current (for a brief time) to the transistor bases. This is about 4.3v/47 or 91ma for the NPN base. This is beyond the capability of a single output pin of an Atiny micro. One solution to this may be to parallel 2 or 3 of the micro pins together and switch them at the same time, this would give more drive current capability.

\$\endgroup\$
3
  • \$\begingroup\$ this answer is just plain wrong. \$\endgroup\$ Commented Jan 17, 2015 at 21:59
  • \$\begingroup\$ Yes, the original version was incorrect for this circuit arrangement. That is why I was in the process of editing. Sorry. \$\endgroup\$
    – Nedd
    Commented Jan 17, 2015 at 22:22
  • \$\begingroup\$ The "you need to swap the bjts" version. \$\endgroup\$ Commented Jan 17, 2015 at 22:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.