Trouble with ATmega328p - 8MHz internal oscillator and 3.3v supply

Hello,

I have encountered an issue setting up my ATmega328p to run on a 3.3v supply using its internal oscillator. I followed the "Minimal Circuit (Eliminating the External Clock)" section in this tutorial: http://arduino.cc/en/Tutorial/ArduinoToBreadboard, and I successfully bootloaded the "ATmega328 on a breadboard (8MHz internal clock)" firmware onto the board. I am testing the board by having it switch an LED using a MOSFET connected to a 3.3v supply regulated off of an Arduino UNO's 5v supply, and the blink sketch works as expected when I give the ATmega328p 5v.

The problem arises when I try to power the ATmega328p off of the regulated 3.3v line that the MOSFET is switching. When I try this, the LED stays off for a few seconds, switches on, and stays on. The issue can't be with the internal oscillator (it's performance with the 328p on the 5v line showed acceptable calibration for my needs, and I'm able to upload sketches), and 3.3v is within the operable range for the 328p, so I am puzzled as to what might be wrong. Why does it work on 5v, but not on 3.3v?

Any help would be greatly appreciated!

Sorry, I don't think I was very clear, so I'll have a second go.

The ATmega328p is using the MOSFET to switch power to the LED. The LED is always receiving 3.3v when it is switched on, which comes from a line regulated down from an UNO's 5v line via an external voltage regulator. When I power the ATmega328p via the 5v line from the UNO, there is no problem. When I power the ATmega328p via the 3.3v line from the external voltage regulator, the problem occurs.

The problem also occurs when I ditch the external regulator, and power everything via the 3.3v line from the UNO.

I may know what the issue is. Some mosfets do need minimum voltage to work fine, some work just with 5V, others with 9V and so on. Could you specify your mosfet model?

Here is the datasheet: http://www.fairchildsemi.com/ds/BS/BS170.pdf

The threshold voltage has a max of 3, but the supply is clearly putting out 3.3v, and I was under the impression it would be in the saturation region as long as the gate-source voltage is greater than the threshold voltage.

Why don't you try with a simple npn transistor?

mart256 is right. That is not a 'logic level' mosfet. It is a normal mosfet.
I can see in the datasheet that it starts working at 3V, but that is not enough.
Try a 'logic level' mosfet that is fully on at 3.3V, but using a simple transistor (with resistor to base) would solve it too.

I had a few of these Intelligent Power and Sensing Technologies | onsemi lying around, so I tried the same circuit with one of them in place of the MOSFET, and it still does not work. I set up the transistor in a common emitter configuration, and while the LED blinks when the ATmega328p is powered via the 5v line, it does not light up at all when the power to the ATmega328p is switched to the 3.3v line.

When the MOSFET was in the circuit, powering the ATmega328p via the 3.3v line caused the LED to turn on and stay on after a few seconds, but when the transistor was in the circuit with the ATmega328p on the 3.3v line, the LED did not turn on at all. I don't know if this is of any consequence.

I've also attached photos of the circuit I'm testing: both with the transistor in place, one with the ATmega328p on 5v, the other with it on 3.3v.

I do not have an oscilloscope, so I can't be sure of what I am seeing, but I just noticed something of interest.

I ran the blink sketch at 5 second intervals instead of 1 second intervals to see what I could see with my cheap digital multimeter, and with the ATmega328p on the 5v line, I saw what I expected to see (5v for 5 seconds, 0v for 5 seconds, repeat). With the ATmega328p on the 3.3v line, the voltage started close to 0v, and in less than 5 seconds climbed steadily to 400mv. Once it got to 400mv, it jumped momentarily to about 4v, and then dropped back to 0v to begin the cycle again. This is rather puzzling to me, but voltage spikes generally mean collapsing magnetic fields, at least from what I know.

I found this (http://forum.arduino.cc/index.php/topic,66785.0.html) in the forums on inductors in Arduinos, but CrossRoads mentioned that 2011 UNO boards shipped without the inductor. I got my UNO in 2012 as best I can remember.

Which resistor are you using in the base of npn transistor? Is it npn or pnp?

The transistor is npn. I do not know if this answers your question, but so far I have been hooking up the base directly to the ATmega328p's digital pin 13. I just tried putting a potentiometer in series with the line from pin 13 to the base of the transistor, and it did not fix the problem.

You should do some research before using transistors. You can damage the pin if you dont limit the current to 20 mA max.
Calculate with ohms law a resistor that fits with 3,3v and 20 mA (its around 1.7k).
Good luck.

I did as you said, but the problem has not been fixed. I am pretty sure that these particular transistors are dealing with the higher than normal base current, because they work as expected when I power the ATmega328p with 5v and do not include any base resistor.

I think that the problem is with the microcontroller at 3.3v. Now that I know there is a voltage spike on pin 13 when it is powered with 3.3v, I have observed a flicker of the LED that indicates that the transistor is working as it should. This could also explain why the MOSFET turned on after a few seconds and stayed on. Are there any other bootloaders that I could try with 3.3v and the ATmega328p's internal 8MHz crystal? The one I am using currently (see first post) appears to have some issue with 3.3v.

I took a better look at the photos.
Do you use pin13 as output ?

That pin is for the system led, it will turn on in the bootloader when the Arduino is reset or powered on.

When you use a ATmega328p on a breadboard, you must connect both grounds and both Vcc and AVcc to 5V or 3.3V.
You should also have a 100nF decoupling capacitor from GND to 5V (or 3.3V).
You may not connect an output to the base of a transistor, you need a resistor.
Something might already be damaged.

A 7805 voltage regulator must have capacitors at the input and output. For example 100nF.
Without those it can go wild oscillating.

A ATmega328p running at 8MHz should have a bootloader for 8MHz (if you use a bootloader) and also a sketch compiled for 8MHz.

When you have it properly connected, and use the right resistors and decoupling capacitors, and with new components that are not damaged, then... everything should work just fine.

... And try powering the circuit from 2 AA batteries in series. I use ATmegas at 3.x volts all the time w/o issues. You do need to be mindful that you have the fuses correct, however. On a tablet now, so cannot access my Dev server to get the fuse settings, but I am certain you can get them from the boards.txt file for 8MHz use.
This looks like it explains low-power settings well: https://www.sparkfun.com/tutorials/309

Ray