# PIC keeps resetting: Am I seeing side-effects from breadboard use?

I'm using PIC18F4680 and am having problems running it form a 40 MHz external clock source or 10 MHz crystal in HSPLL mode. Using 10 MHz crystal in HS mode seems to be fine and 5 MHz crystal in HSPLL mode also works fine.

What happens is that the PIC starts, works for a few seconds and then shuts down for a while and starts again. The total period of the cycle is around 5 seconds out of which the PIC works stops working early in the second second.

I've also noticed that sometimes when I add a large enough discharged capacitor to the power bus of the breadboard, the PIC will work fine. Interesting point is that this only happens if I add the capacitor while the PIC is already running. If I power the breadboard with the capacitor there or I place a capacitor that hasn't been completely discharged the problem remains.

I've read on some sites that problems similar to mine can happen due to increased power consumption of the PIC on higher frequency and higher lowest operating voltage. In those cases, if there are some short voltage drops on the power supply, they are more likely to reach the lowest operating voltage of the PIC on that frequency so it's a good idea to have additional capacitors on the breadboard to solve that issue. Since under full load at 40 MHz, the whole circuit uses around 64 mA, my first idea was to put some $10 \mbox{ } \mu F$ tantalum capacitors hoping that they'd be big enough and have low enough ESR to fix the problem. One didn't help and the second didn't help either. So I added a $100 \mbox{ } \mu F$ aluminium capacitor and that didn't help either. Then I added a $470 \mbox{ } \mu F$ aluminium capacitor to no effect. In the end, I added a 1 mF aluminium electrolytic capacitor and then for the first time the circuit worked fine until turned off and on the power. I should also note that for testing purposes I'm using Vcc of 5.5 V which is the highest rated voltage for this microcontroller. This should leave me some room until the 4.2 V which is the lowest operating voltage at 40 MHz

Next, I've read that sometimes floating outputs can cause glitches, so I put some $10 \mbox{ }k \Omega$ pull-down resistors at all unused pins and that didn't help either. After that I've read that sometimes there could be problems if the oscillator inputs are floating, so I tried connecting them to GND using some $10 \mbox{ }M \Omega$ resistors and that didn't help.

Due to length of wire going from the oscillator output to the oscillator input at the PIC, I expected problems with it, but I didn't expect problems with the 10 MHz crystal which is very close to the oscillator pins on the PIC. Also with crystal, I'd expect problems in HS mode too, if the oscillator signal distortion due to breadboard was the problem, but in HS mode, the PIC works fine.

I normally use 33 pF capacitors for the crystals, but I've tried with 15 pF too and I couldn't detect any change.

I should also note that this PIC has fail-safe clock monitor and internal/external oscillator switchover. I've tried enabling both of them, hoping that they would at least confirm that the problem is with the oscillator, but they don't help with the problem. There is no difference is they're on or off.

I've also disabled for testing purposes watchdog timer, brown-out reset and stack over/underflow reset. I think that I turned off all the reset sources for this chip. Also the program is in an infinite loop, so it's not ending.

The PCF8583 doesn't have any problems and it continues to operate correctly even when PIC is resetting itself, but on the other hand it has much lower minimum voltage.

Unfortunately, I don't have an oscilloscope, but I did to some testing with a sound (96 kHz sample rate) card and I've noticed when the RTC is on, there is some 25 Hz noise on the power line. The program I'm using reports some 300 mV peak to peak, but I don't know how much to trust it and I don't know if that would be enough to cause any problems for the PIC. When everything is off, the noise is around 100 mV peak to peak, so that should be fine.

In case it helps, here's the picture of the breadboard itself: (right click-> view image for full size)

So does anyone have any idea what's going on here?

In the end, I could just run the PIC at 20 MHz, but should I need more processing power, I'd like to be able to run it at 40 MHz.

UPDATE

I've placed another regulator at the breadboard itself and the noise picked up by the sound card is much lower now (around 50 mV peak to peak), but it didn't influence the main problem.

• Hmm, I was going to suggest WDT and brown-out, but you've disabled those. Do you know that there are some errata with the brownout for that PIC? I have never tried running a PIC that fast on a bread board. We use the 18F4580 all the time with 10MHz oscillator and HSPLL. They work fine. – Rocketmagnet Apr 21 '12 at 11:01
• Forget the breadboard (I never use them) and use a proper PCB, it'll save a lot of time. – Leon Heller Apr 21 '12 at 11:30
• @Leon Heller It may save a lot of time, but at this moment, the PCB is more expensive than my time, especially since I don't even have a list of all major components I'll be using. – AndrejaKo Apr 21 '12 at 11:36
• @AndrejKo This sounds like one of those problems that makes me want to curl up into a ball and cry. Are you SURE your time is worth so little? I'd just make the PCB - it's usually so much fun too! – AngryEE Apr 21 '12 at 15:51
• @AndrejaKo: If you don't mind waiting a week or so, I've had great success with this group PCB order: dorkbotpdx.org/wiki/pcb_order. If you don't want to make your own, that is – Chris Laplante Apr 21 '12 at 18:32

This is some pretty old advice, and I don't know if it will be relevant for your micro, but about 4 years ago I did a project with a PIC18F which encountered strange spurious resets. After reading the report and re-jogging my memory here is what seems to have solved it:

Do you have the Low Voltage Programming Enable configuration bit enabled? Is your PGM pin on PORTB? If so, you may want to consider disabling both Low Voltage Programming Enable and Port B A/D Enable to digital inputs on reset. According to my old report, what was happening was we left PORTB floating while they were analog inputs and triggered the PGM pin. Looking back I don't know if this diagnosis was correct, but we did end up finishing that project successfully so it may be worth a shot.

• Interesting! Just a few minutes ago, I noticed that having programmer connected affected the issue and now this answer. I disabled the port B A/D and the LVP and it's working fine so far. It could be some sort of strange interaction on the PGM pin. – AndrejaKo Apr 21 '12 at 21:50
• @AndrejaKo, that sounds very familiar from what I experienced. I hope it remains stable... finicky hardware can be extremely frustrating when you're trying to get something done :S – Jon L Apr 21 '12 at 22:05
• Well, it's been running fine for 21 minutes and 30 seconds. I hope it stays that way. I'll just leave it running over night and see if it resets. – AndrejaKo Apr 21 '12 at 22:09
• Great! I'm glad it solved the issue. – abdullah kahraman Apr 22 '12 at 9:45
• Made my day bro, I spent one entire day trying to figure out why in the earth my PIC 16F887 was resetting every few msec. The low voltage in circuit prog was set and the floating PGM pin was picking noise triggering the reset. +1 rep for you – Gianluca Ghettini Apr 26 '15 at 20:22

With a setup like this it is going to be almost impossible for us to say exactly what is going wrong. What we can say, however, is what is wrong. There are a lot of things wrong, or at least not as right as it cold be. Any one of these things could be the real source of your problem, but it also could require the combination of issues that when added up equal the problem you are seeing.

The only real way to debug this is to fix anything you know is wrong, regardless of if it is the smoking gun or not. Eventually the problem will be fixed one way or another.

When an MCU like this is not running correctly you almost always have to focus on the basics: Power, Clock, and Reset. With a breadboard, all three of those are suspect!

The #1 suspect for me is the 40 MHz clock. 40 MHz is quite fast to be running over a wire floating in the air. It's also fast to be stuffing into a breadboard, where the "signal distribution system" is not really designed for high speeds. If this were a PCB I would be telling you to make sure your trace impedance is consistent and to properly terminate your signals. Unfortunately you can't really do that on a breadboard. The best thing I can tell you is to keep your wires as short as possible-- and then make them even shorter! Use an o-scope on the clock signal, probed directly at the PIC pin, with the GND lead of the probe also directly at the closest GND pin on the PIC. That will tell you a lot about your clock.

(Try to borrow an o-scope if you can. It's going to be hard to debug things without one.)

The #2 suspect is power. Power is also a huge problem with breadboards, since the inductance and resistance of the wire is relatively high. Here again, keep the wires short. I also note that you don't have any decoupling caps on the 40 MHz oscillator. For the OSC I would go with a 0.1 uF and something larger (4.7 uF to 100 uF) in parallel. Your PIC could also use something larger in parallel with the 0.1 uF caps. Normally the larger caps would not be required, but nothing is normal with a breadboard.

Suspect #3 is reset. You didn't give us any info on the reset signal, and I'd say that it is the lowest of what I suspect, but you should check it anyway. Put an o-scope on it and see what's happening. You might be able to simply use a volt-meter. If the voltage on the reset pin is close to the threshold level then you need to fix it.

Now, let's go over the things you tried:

You did a lot of experiments with placing caps on the power lines, with few or confusing results. This is one of those times when you just have to put some caps there and don't worry about if they are doing anything positive or not. It could be that your power is noisy, but is only one of several things causing the problem. Add larger caps in parallel with the 0.1 uF caps at the PIC. Add caps to the 40 MHz oscillator. Make sure the leads are as short as possible. Then move on to the next thing.

Extra caps on power is one of those things that's unlikely to cause problems. That's why you can just put some on and not worry about them too much. Especially with 10-100 uF caps.

Later, once everything is working, you can remove these caps one at a time and see if the problem returns. If it doesn't return then the caps were not the problem. But for now you need to remove this as a potential problem but adding caps.

While floating pins could be a problem they are rarely a big enough problem to cause an MCU to crash. It's worth fixing, since it causes other issues, but is very unlikely to be the problem here. Note: a simple way to stop unused pin from floating is to set them as outputs! High or low, doesn't matter. But if the PIC is driving those pins then they can't float.

• A good answer. All those long untidy wires just made me think that trying to get this working on a nasty breadboard wasn't worth the time and misery. – Rocketmagnet Apr 21 '12 at 14:50
• Nice list! I'll report results when I go through it. – AndrejaKo Apr 21 '12 at 16:16

You didn't mention the PGM (sometimes called LVP) pin. This must be tied low or LVP disabled in the conifig bytes.

Are you sure this PIC can take 40 MHz in directly? Some can only reach 40 MHz via the internal PLL. I didn't check the datasheet but you should. Even if so, I wouldn't expect 40 MHz on a breadboard to behave well. I do think you should be able to get the PIC running with a 10 MHz crystal and the internal 4x PLL though if you're careful with the breadboard and put bypass caps in the right places.

This sort of question comes up regularly. Instead of repeating all the typical issues, see https://electronics.stackexchange.com/a/29620/4512.

• Seems like we have two correct answers here :) – abdullah kahraman Apr 22 '12 at 9:46

I must agree with David. There are so many long wires, and 40MHz on a breadboard is quite optimistic. I can't believe your time is really worth so little that you can't afford to make a little prototype PCB. These things cost only about £30 from PCB Train. I'm sure there'l be someone near you that can supply similar.

Why not do this. Design a PCB which has the PIC, oscillator and regulator as SMD components, then a whole load of perf board strips. This way you can still do your prototyping, but be sure that the PIC is happy.

• Ah, I love Altium's 3D! By the way, £30 can be high for a student :) It's better to use a perf board or better, a home-made PCB. – abdullah kahraman Apr 21 '12 at 15:20
• Should manage to make a home-made PCB, I'll definitely try with this idea. – AndrejaKo Apr 21 '12 at 16:11
• @AndrejaKo - Cool. Give us a tick then :) - Or even just put two rows of pin strips, so you can plug it into a breadboard. – Rocketmagnet Apr 21 '12 at 16:12

if you have an external variable F generator, consider using that to test layout /chip for issues. and find external F that causes failure.and remember extended ground cables act as antenna for noise cross talk.

probelook like u need a logic probe , dvm or scope... http://search.digikey.com/us/en/products/DP%2052/BKDP52-ND/227492

Put cap across clock chip V+/gnd and consider twisted pair for 40MHZ if far away. Pic xtal has input and output.. check inverted output DC level= v/2? .. does Pic get warm? ha..

I suggest 10MHz Xtal PLL mode @ 40MHz to avoid layout issues.

"The HSPLL mode makes use of the HS mode oscillator for frequencies up to 10 MHz. A PLL then multiplies the oscillator output frequency by 4 to produce an internal clock frequency up to 40 MHz. The PLL is only available to the crystal oscillator when the FOSC3:FOSC0 Configuration bits are programmed for HSPLL mode (= 0110)."

• I actually did try using HSPLL and 10 MHz crystal, but in HSPLL mode it shows same results as the oscillator. It works fine in HS mode. – AndrejaKo Apr 21 '12 at 16:18
• Also the PIC doesn't get warm during use, as far as I can see. – AndrejaKo Apr 21 '12 at 16:19