I have the worst kind of electrical problem you can possibly have: an intermittent problem that I can't reliably repeat. >.<
I have an ATmega328P in a TQFP package soldered onto a PCB (schematic and board attached) with the following crystal: TSX-3225 16.0000MF09Z-AC3 Epson Timing | Mouser
I have two sources of power for the chip: the ICSP header from my EvilMadSCientist ISP shield, or a regulator running off of 12 V.
My main problem: When I plug in 12 V, the chip quite frequently fails to start up. The symptom that I saw was black bars on the top row of my 16x2 LCD screen. I tracked this down to it appearing that the crystal oscillator for the ATmega is not starting. I found this by probing one of the crystal load caps with a x10 scope probe and finding a flat line. When I apply power via the ICSP header from USB, the chip starts up much more reliably (but not totally reliable), and I can see a 16 MHz signal on the crystal cap.
My bigger problem is that this is intermittent. I can't reliably induce it, and it doesn't always appear. In fact, just now I plugged and unplugged 12 V from my project several times, and each time it started up. Yesterday it wouldn't start up no matter how many times I plugged in 12 V. Just before this, it wouldn't start up, so I tried to take a picture of the flat line on my oscilloscope. As soon as I probed the cap (again with x10 probe), the oscillator started up and the project started working.
The crystals Mouser page says a load capacitance of 9 pF, but the datasheet says the load capacitance can be anywhere from 7 pF to infinity. I put 18 pF on both ends of the crystal. Would this be causing a problem?
What could be causing this unreliable startup, and how might it be fixed?
The 12 V supply is a 1500 mA rated plug pack for my external hard drive. It should be more than beefy enough to drive this project.
Digital Amplifier SMD Schematic.pdf (26.3 KB)
Digital Amplifier SMD Board.pdf (51.9 KB)
Just tried it again, uC wouldn't start when I applied 12 V to the regulator. I managed to probe the load cap and got a picture of the flatline. It's attached as pic 31. However, the oscillator started up shortly after I probed it and showed a signal like pic 30, also attached. The chip also stopped frequently when I removed the probe.
I noticed that if I touch the chip (and likely some of the surrounding circuitry due to my big fingers), I can make the chip start up, but it seems to run slower and very intermittent. If I remove my finger, it stops working.
Could this be temperature related? The chip is unable to start "cold", but if I force a start by probing and let it run for a minute or so, the die warms up slightly and puts it into a region where it can reliably start. After it cools down, it goes back to its old problem again.
How would I fix this?
Change the fuses so the processor runs from the internal oscillator. Thoroughly test. If the problem disappears you know for certain the crystal + capacitors (or the driver circuitry) is the culprit. If the problem persists you know the culprit lies elsewhere and the crystal driver failing to start is just a symptom. (Or you have more than one problem.)
I believe Atmel calls for a ground plane under a crystal. I don't see one on your board layout. Did you include one?
##############################################################
atmega328_384_8.name=ATmega328 Optiboot @ 38,400baud w/ 8MHz Int. RC Osc.
atmega328_384_8.upload.tool=avrdude
atmega328_384_8.upload.protocol=arduino
atmega328_384_8.upload.maximum_size=30720
atmega328_384_8.upload.speed=57600
atmega328_384_8.bootloader.tool=avrdude
atmega328_384_8.bootloader.low_fuses=0xE2
atmega328_384_8.bootloader.high_fuses=0xDE
atmega328_384_8.bootloader.extended_fuses=0x05
atmega328_384_8.bootloader.path=optiboot
atmega328_384_8.bootloader.file=optiboot/optiboot_atmega328.hex
atmega328_384_8.bootloader.unlock_bits=0x3F
atmega328_384_8.bootloader.lock_bits=0x0F
atmega328_384_8.build.mcu=atmega328p
atmega328_384_8.build.f_cpu=8000000L
atmega328_384_8.build.core=arduino
atmega328_384_8.build.variant=standard
Pasted the above into my boards.txt, burnt the bootloader for it to set the fuses, and reuploaded my sketch. LCD refresh seems a little more noticeable, so that's a clue it's probably working at a slower speed. Also, no signal is present on the crystal, so I assume it's running off the internal now. It's working now both off of 12 V and the ICSP shield, but that doesn't tell much because I had to warm the chip up to get it to work in the first place. I'll let it sit for an hour or two then try again.
I have ground planes on the top and bottom of the board.
(Or you have more than one problem.)
I already have more than one problem. This is my third topic on this same project. >.<
Jiggy-Ninja:
However, the oscillator started up shortly after I probed it and showed a signal like pic 30, also attached. The chip also stopped frequently when I removed the probe.
I noticed that if I touch the chip (and likely some of the surrounding circuitry due to my big fingers), I can make the chip start up,
Your fingers are capacitors too :). Do you have pull-up resistor attached to reset pin?
I would try with internal osc. as moderator suggested.
Anyway, 18pf on both ends is ok only if stray capacitance (Cs) is equal 0. Cstray is hard to measure but I've seen examples where they assume is somwhere between 2 and 5pf. Said that, I would try with 14pf caps on both ends (check this formula http://www.adafruit.com/blog/2012/01/24/choosing-the-right-crystal-and-caps-for-your-design/)
Edit: Glad to see it's working with internal osc. I don't think is a termal problem.
Not sure if it's working yet. If it's a thermal problem as I suspect, I need to wait for the chip to cool to ambient before I can be sure.
Trying to get it working to burn the new fuses in, it didn't start working immediately after I placed my finger on it, it took several seconds. I can tell when it works because I have an LCD that refreshes and a knob I can turn to change a setting. The several seconds is what leads me to believe it's right on the edge of a thermal problem, not a capacitive one. Though I didn't even think about my skin capacitance as a possibility, thank you for that. One more variable I can test.
Anyway, if the problem was too much capacitance (since you recommend lowering it), wouldn't it be odd that my finger would start it up? Wouldn't it add capacitance?
It depends on how you add the capacitance. If you add a series capacitor, the equivalent capacitance lowers (opposed to series resistors which raises resistance). Maybe your fingers where connected (somehow ) in series to the circuit.
I've gone back and forth between between the standard UNO settings and the internal oscillator settings, and it's pretty definitive. I only have a problem when the fuses are set to use an external clock.
I plugged it in, and it worked off of 12 V. Unplugged it, plugged in the ICSP header and burned the UNO bootloader + fuses, and it locked up as soon as the fuses were written, and the rest of the bootloader burning process failed. Switching back and forth multiple times, it was only when the external oscillator was set that I had a problem. I didn't take any scope measurements during this testing.
It seems like the chip is the problem, because the problem seems to go away after it runs for a while and presumably warms up. I'll order a new chip and see if I can replace it and see if the problem goes away. Running off the 8 MHz oscillator won't be a problem for this project, but my next one is going to be a DIY frequency generator, so I'll need at least crystal accuracy for the timing signals. I would like to solve this problem for the sake of my next project.
Or a pin. The pin warms, expands, makes better contact with its pad. Check for resistance from pin to pad.
Wouldn't that be quite difficult to do without applying pressure to the pin, thus making better contact than normal and giving a false low reading (if that is indeed the problem)?
Besides, I've inspected the joints on the chip that the crystal connects to under 5x magnification, and they look well soldered. The best pic I could get of the joints is attached.
Also, this circuit used to work just fine. I drove to school and back once playing music with it. It's only recently that it's started to fail.
I had an atmega88 board with the smd crystal making intermittent connections on one corner. It was very hard to find the problem (i couldn't tell just by looking at it, even with a microscope) but after removing it and re-working it back on it finally became stable. It has been working reliably for over a year now.
The crystal or the chip had an intermittent connection?
It was the smd crystal. It reacted very similar to what you described. I used a hot air re-work station to remount it.
I reflowed the crystal with my soldering iron, and now it appears to be working off the external oscillator each time I plug it in, even after letting it sit for a while. Looks like the problem was the crystal rather than the chip. I'll double-check tomorrow just to be sure. If I don't post again, assume it worked. Now if I could just get my switching reg to start up, this project will be a complete success.
Thank you very much everyone for your advice.