Electronic – DC motor halting pic18f

dc motormicrocontrollerpic

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?

Best Answer

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.