I am building a localization system for a robot. The robot works on two 12V DC motors and is connected to its own circuit and battery. I connected the motor encoders to a pic18f4520 microcontroller. Each time I start the motors the pic halts and stops working. Things to take into consideration:

  • The motors and the PIC work on two different circuits and power sources, the only common things are the encoders but the same problem occurs even when they are completely removed (so the problem is not from the encoders)
  • Grounded everything (EVERYTHING including the reset pin)
  • Grounded the outer shell of the motors
  • Put one to three 10nF capacitors between the motor positive and negative pins
  • Wrapped the motors and PIC in aluminium foil
  • The microcontroller doesn't halt when the motors are fed with 3V or lower

What's even weirder is that even when nothing is attached to the microcontroller, as soon as we bring a DC motor close to it (closer than 40cm) it halts. Any ideas how to fix this?

  • 4
    \$\begingroup\$ A schematic would help very much. \$\endgroup\$ Apr 10, 2012 at 14:59
  • 3
    \$\begingroup\$ MCLR is active low in PIC18F4520. So, if you ground it, it will reset the microcontroller. \$\endgroup\$ Apr 10, 2012 at 15:01
  • \$\begingroup\$ A schematic doesn't really add much it's just a DC motor and a simple microcontroller (nothing connected to it). I meant that I bypassed the reset, it's 5V all the time. \$\endgroup\$
    – Raz
    Apr 10, 2012 at 15:18
  • 4
    \$\begingroup\$ @Rami: It's not up to you to decide what is important for us to know or not. If your judgement could be trusted, you wouldn't be having this problem. If you're not going to cooperate then we should just close the question and move on. \$\endgroup\$ Apr 10, 2012 at 15:26
  • 4
    \$\begingroup\$ A circuit is ALWAYS useful. Your "grounded everything" would have been shown to be wrong with a circuit diagram. Are motors unidirectionally driven? Are the motors PWM driven. HOW ARE the motors driven???? MOSFETS?, relays?, act of parlaiment ?. Circuit please. Decoupling where. Unused pins part of everything grounded? ...? \$\endgroup\$
    – Russell McMahon
    Apr 10, 2012 at 16:29

2 Answers 2


The usual suspects:

  1. Make sure MCLR is held solidly high, or that the MCLR function is internally disabled. I don't remember if MCLR can be internally disabled on the 18F4520.

  2. Make sure the PGM pin is not floating, or that low voltage programming is disabled.

  3. Make sure there are bypass caps on every power pin, and that they connect back to a near ground pin with as short a loop area as you can manage. All the ground pins must be tied together, prefereably right under the PIC.

  4. Make sure all power and ground pins are connected. This includes the analog power and ground, even if you're not using any of the analog peripherals.

  5. Either make sure your power voltage is really clean or disable the brownout reset feature. The brown out detect circuitry is less than ideal on some PICs, so the first thing to do when you suspect something like this is to disable brownout reset in the code and see how that changes the symptoms. I have seen fast positive glitches on the power trigger the brownout detect, for example.

  6. Decouple the digital and high power supplies. At the very least, put a Shottky diode in series with the digital supply so that short dropouts due to sudden power load changes don't drop the digital supply too. Of course the voltage will have to be adjusted to compensate for the diode drop. Depending on the supply, you may be able to put the diode within the voltage control feedback loop.

  7. Don't forget the reverse diode accross any coil, which includes any motor winding. If the coil is driven bi-directionally, then make sure there is a fast diode in reverse to at least the power and ground on each coil lead.

  8. Pay attention to the ground layout. Preferably this is a plane or mostly a plane with occasional "jumpers" that connect points on the other layer. Keep high frequency currents, like those between the PIC and its crystal, off the common ground plane. Use a local ground for the PIC and it's immediate surrounds, then tie that to the main ground in one location. Remember that everything you do to minimize radiation works the other way too and helps with susceptibility.

While circuit topology, like forgeting inductor catch diodes, can cause problems like this, after all the really stupid stuff the most common cause is bad layout.

  • 2
    \$\begingroup\$ Wow, that's a great answer for a question like this. One thing I don't understand is, he wrapped the motor with aluminium foil, if there is a bad layout with great EMI receiving, will it still pick-up? \$\endgroup\$ Apr 11, 2012 at 7:27
  • 2
    \$\begingroup\$ @abdullah: Wrapping with aluminum foil isn't very meaningful, especially if the foil was left floating or we don't know exactly what it was connected to and how it was connected. A properly designed shield will protect against capacitive pickup, but not necessarily against RF. Since the OP is refusing to cooperate, we may never know what exactly he did, especially since other statements he has made are contradictory and we therefore can't know what to trust. \$\endgroup\$ Apr 11, 2012 at 12:58

I've resolved a similar issue on a Dspic33 by disabling clock switching and fail-safe clock monitor configuration bit when working in a breadboard.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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