Mosfet gate voltage

When I apply power to my breadboarded ATmega 328 with a small DC motor driven through a logic level mosfet, the voltage measures about 5v then drops to around 2v after 4 or 5 seconds. EDIT: I'm referring to the voltage between the output pin and mosfet gate. The rest of the circuit measures 5v where it should measure 5v.

Power:
I'm using 6 AA rechargeable NiMH batteries through a 7805 regulator decoupled with .1uF and 22uF on the input and .1uF and 10uF on the output. Edit: 1.5A regulator

Mosfet wiring and datasheet:
see attached photo. I also put a 100 Ohm resistor in series from output pin to mosfet gate per Crossroads and others in other posts.

ATmega 328 wiring:

Motor:

Code:

int StartSpeed=0; // you have to experiement to find the magic number. 
int StopSpeed=255;//Again experiment ok 
const int MotorPin=3;
int i=StartSpeed;
unsigned long TimeNow;
unsigned long PreviousMillis=0;
long Delay=10; // experiment with the value ok, the lower the value the steeper the gradiend of speed

void setup()
{
  pinMode(MotorPin,OUTPUT);
  digitalWrite(MotorPin,LOW);
}

void loop()
{
  if (i<StopSpeed)
  {
    unsigned long CurrentMillis=millis();
    if (CurrentMillis-PreviousMillis>=Delay)
    {
      PreviousMillis=CurrentMillis;
      i ++;
    }
  }
  analogWrite(MotorPin,i);
}

Things I have tried to fix:

  1. 0.1uF capacitor in series with the flyback diode
    no change

  2. switching regulator
    no change
    http://www.murata-ps.com/data/power/oki-78sr.pdf

  3. changing output pins
    no change

  4. changing ATmega 328
    no change

  5. changing code to non-PWM using just digital write high

digitalWrite(motorPin, HIGH);

no change

  1. Swapping out motor
    no change

  2. swapping LED and current limiting resistor for motor
    works fine

  3. using same code, same power, and same ATmega 328 plugged into the Arduino
    works fine!
    This is what puzzles me most because I assumed that I had damaged the two ATmega 328's that I am using, but this tells me that they aren't damaged.

Any suggestions are greatly appreciated. Thanks in advance.

How you power the motor? It is a 3V motor.

TeslaIaint:
When I apply power to my breadboarded ATmega 328 with a small DC motor driven through a logic level mosfet, the voltage measures about 5v then drops to around 2v after 4 or 5 seconds.

Is this the input voltage to the circuit (i.e. the 7805 output voltage), the voltage at the I/O pin that drives the MOSFET gate, the voltage delivered to the motor, or something else?

Can you provide a good quality picture of the breadboard setup?

The regulator is going into thermal limit... small dc motors draw in the 100 to 300 mA range and the load on the regulator is about 2 watts of power, more than enough for it to thermal limit. the regulator will adjust the voltage to the point where it is just at the maximum package temperature listed in the spec... I used to use the smaller versions for thermally stabilizing a cyrstal oscillator, very handy when building accurate frequency counters. crystal, silicone insulated wire and wrapped in a bit of glass wool and stuffed onto a cavity carved from a small styrofoam block and plugged with a larger piece of foam makes an Excellent poor man's Crystal Oven.. The only heat loss is through the power and oscillator leads and If one carefully wraps the resistance wire used to load the regulator around both crystal and regulator it becomes very thermally stable when properly insulated, perhaps the only use for a mistreated voltage regulator.

Bob

I edited my first paragraph. I should have clarified that the voltage to the mosfet gate from the output pin is 2v and the rest of the circuit measures 5v where it should measure 5v. I'm having a hard time understanding why when I use the same ATmega chip, same mosfet motor circuit, and same power supply works as expected when the chip is in the arduino board but doesn't work when I have the Atmega chip on the breadboard as a standalone. When I say "works" I mean that I measure 5v between output pin and mosfet gate and the motor is running.
Thanks for the replies.

One thing I note - you should have a resistor between the output pin and the gate of the MOSFET. The gate is, to all intents and purposes, a capacitor. When you first apply power it is equivalent to a short circuit, rapidly changing to an open circuit. The initial current into that capacitor is known as the "inrush" current, and can be quite high, but short lived. If it exceeds the 40mA that the IO pin can provide (an ideal short circuit is 0? resistance, so Ohms Law says that will cause infinity amps to flow), which is will be - albeit for a short time - you risk killing the IO pin. You need a minimum of 125? resistance in that connection (R=V/I = 5/0.04 = 125) - slightly more is better, so say 150? or 220? should suit it fine.

That said, have you thought that maybe it's simply the fact that it's in a breadboard that is causing your problems? Breadboards have notoriously bad pin connections, and chips are especially bad due to the limited length of their pins.

thanks majenko,

I do have a 100 ohm series resistor between the I/O pin and the mosfet gate, but I'll try a 220 ohm resistor.

You are right about the breadboard. I am planning to solder the entire circuit into a perf board, but I just wanted to use a breadboard first to test my circuit wiring because I don't have many spare parts.

If I insert the ATmega chip back into the arduino board, power the board from the same batteries and regulator and wire the I/O pin to the mosfet gate the motor runs as it should and I measure 5V between the I/O pin and mosfet gate. Any idea why that works but the standalone arduino doesn't? Could it be the values of the decoupling capacitors that the arduino uses? That's one more thing I would like to check before I solder the circuit into the perf board.

Is the low voltage you are measuring only evident on that IO pin, or can it be seen on other IO pins / power pins as well?

For decoupling you should have (my personal rule of thumb):

  • 100nF on every Vcc / Vdd / AVcc / AVdd / whatever name it gives it power pin on every chip.
  • =10µF on the power for every group of 3 or so chips.

  • =10µF at the board "entry" point for the power

Particularly noisy chips (PWM drivers, audio amplifiers, etc) may demand more decoupling - check their data sheets.

Docedison:
The regulator is going into thermal limit... small dc motors draw in the 100 to 300 mA range and the load on the regulator is about 2 watts of power, more than enough for it to thermal limit.

No-load current for the motor is 200mA per the specs. Assuming 7.2V input (6xNiMH @1.2V each) and 250mA total current, I estimate (7.2 - 5) * .25 = 0.55W ... Even without a heatsink, a 7805 should last quite a bit longer than a few seconds, indeed probably wouldn't need a heatsink to dissipate half a watt or so. The motor's stall current is much higher of course, 2.1A. That might be a problem.

@Tesla, two questions:

  1. Is there any mechanical load on the motor, or is it just spinning free?
  2. Is the 7805 getting hot?

Something to try, test the drive capability of the MCU. Remove the motor and MOSFET, try to drive a purely resistive load from the ATmega. Connect a 220-ohm resistor from an output pin to ground. Drive the pin high, measure the pin voltage. Now connect the resistor from the pin to +5V and drive it low, again measure the pin voltage.

Be sure to use decoupling caps as described by majenko.

Still would like a picture of the setup if possible.

If you are getting a voltage(*) across the gate resistor then the MOSFET is toast.

(*) for more than a microsecond!

[ edit: MOSFET gates are static-sensitive and you have to be careful when handling them ]

As I described above, the motor works fine when the ATmega is plugged back into the arduino board, and I use the same circuit components including the mosfet. I also read 5V from the output pin to the mosfet gate.

When the ATmega 328 is back on the breadboard as a standalone, I have even tried switching out the mosfets and get the negative results.

what is "Voltage(*)" ?

It sounds to me that you have faulty wiring or a a faulty connection. Post a schematic and a few photos of your setup. Confirm that you have connected the Avcc pin of the atmega328p to +5V, even if you are not using the ADC?

PS - also connect a 0.1uF ceramic capacitor directly between the Vcc and ground pins of the atmega328p

Ok, I just scanned the thread rather quickly so maybe I'm missing something, but there may be a fundamental problem with how you are trying to measure the gate voltage on the mosfet. The value can only be accurately read with a DMM if the analogWrite(pin, value) command is sending a value of 0 or 255, and the gate voltage will read 0vdc and +5vdc respectively.

At any other PWM value your DMM will not respond to the PWM signal in any meaningful way, the number it displays is pretty meaningless, it's just not designed to read a digital switching signal. A scope is the only way to look at the gate signal while being controlled with a PWM signal.

Lefty

Yea, I'm reading it with the DMM when it is fully on (255). I also have tried code without the PWM by just using digital write.

@Tesla, two questions:

  1. Is there any mechanical load on the motor, or is it just spinning free?
  2. Is the 7805 getting hot?

Something to try, test the drive capability of the MCU. Remove the motor and MOSFET, try to drive a purely resistive load from the ATmega. Connect a 220-ohm resistor from an output pin to ground. Drive the pin high, measure the pin voltage. Now connect the resistor from the pin to +5V and drive it low, again measure the pin voltage.

The motor is just spinning free, and the 7805 is not getting hot. In fact I can't find any part of the circuit getting hot. I tried connecting the 220-ohm resistor and read 4.74V when driven high from output to ground. It measures 0.47V when driven low from output to +5V.

Here are some photos of my circuit.

Thanks for the pics, nothing is jumping out at me I'm afraid. I would disconnect AREF from Vcc, and I would add two 0.1µF caps, one from AREF to ground, and one from AVCC to ground. I'd be surprised if that was causing the problem though.

TeslaIaint:
The motor is just spinning free, and the 7805 is not getting hot. In fact I can't find any part of the circuit getting hot. I tried connecting the 220-ohm resistor and read 4.74V when driven high from output to ground. It measures 0.47V when driven low from output to +5V.

Those voltage readings are good. So if we use a 220-ohm resistor between the MCU and MOSFET gate, and just drive the pin with digitalWrite() rather than PWM, when the pin is driven high, what are the voltages on either side of the 220-ohm resistor?

Those voltage readings are good. So if we use a 220-ohm resistor between the MCU and MOSFET gate, and just drive the pin with digitalWrite() rather than PWM, when the pin is driven high, what are the voltages on either side of the 220-ohm resistor?

You want me to take the motor out of the circuit or leave it in?

TeslaIaint:
You want me to take the motor out of the circuit or leave it in?

Leave it in please

I measure anywhere from 1.2V to 4.96V on both sides of the resistor. It jumps all around. I'm going to try to wire up a TIP 120 and see how the motor responds to that.

Yet when driving a pure resistive load, the voltage looked steady, correct? Does the motor spin at a constant speed or does it act as though it's getting variable voltage?

Yes, when driving the pure resistive load, the voltage was steady. Sometimes the motor spins at a constant speed and sometimes it acts as though it's getting a variable voltage.

I'm really starting to believe it's a breadboard issue. I wired up the TIP 120, and it worked fine. I switched back to the mosfet, and it worked as advertised, and I even measured the right voltages in the right places.

A little later I will solder this circuit onto a perfboard and test it. I'll let you know what happens.

Thanks for all your help!