2.7. I've Got Troubles

The most common problems with getting PICmicro MCUs running involve making sure the few external components are of the appropriate value and properly connected to the PICmicro MCU. Following are some hints to help get things up and running.

Make sure the /MCLR pin is connected to 5 volts either through some kind of voltage protected reset circuit or simply with a 4.7K resistor. If you leave the pin unconnected, its level floats around and sometimes the PICmicro MCU will work but usually it won't. The PICmicro MCU has an on-chip power-on-reset circuit so in general just an external pull-up resistor is adequate. But in some cases the PICmicro MCU may not power up properly and an external circuit may be necessary. See the Microchip PICmicro MCU data books for more information.

Be sure you have a good crystal with the proper value capacitors connected to it. Capacitor values can be hard to read. If the values are off too much, the oscillator won't start and run properly. A 4MHz crystal with two 22pf (picofarad) ceramic disk capacitors is a good start for most PICmicro MCUs. Once again, check out the Microchip data books for additional thoughts on the matter.

Make sure your power supply is up to the task. While the PICmicro MCU itself consumes very little power, the power supply must be filtered fairly well. If the PICmicro MCU is controlling devices that pull a lot of current from your power supply, they can put enough of a glitch on the supply lines to cause the PICmicro MCU to stop working properly. Even an LED display can create enough of an instantaneous drain to momentarily clobber a small power supply (like a 9-volt battery) and cause the PICmicro MCU to lose its place.

Check the PICmicro MCU data sheets. Some devices have features that can interfere with expected pin operations. The PIC16C62x parts (the 16C620, 621, 622, 16F627 and 628) are a good example of this. These PICmicro MCUs have analog comparators on PORTA. When these chips start up, PORTA is set to analog mode. This makes the pin functions on PORTA work in an unexpected manner. To change the pins to digital, simply add the lines:

Symbol CMCON = $1f
Poke CMCON, 7

near the front of your program.

Any PICmicro MCU with analog inputs, such as the PIC16C7xx, PIC16F87x and PIC12C67x series devices, will come up in analog mode. You must set them to digital if that is how you intend to use them:

Symbol ADCON1 = $9f
Poke ADCON1, 7

Another example of potential disaster is that PORTA, pin 4 exhibits unusual behavior when used as an output. This is because the pin has an open collector output rather then the usual bipolar stage of the rest of the output pins. This means it can pull to ground when set to 0, but it will simply float when set to a 1, instead of going high. To make this pin act in the expected manner, add a pull-up resistor between the pin and 5 volts. The value of the resistor may be between 1K and 33K, depending on the drive necessary for the connected input. This pin acts as any other pin when used as an input.

All of the PICmicro MCU pins are set to inputs on power-up. If you need a pin to be an output, set it to an output, or use a PICBASIC™ command that does it for you. Once again, review the PICmicro MCU data sheets to become familiar with the idiosyncrasies of a particular part.

Start small. Write short programs to test features you are unsure of or might be having trouble with. Once these smaller programs are working properly, you can build on them.

Try doing things a different way. Sometimes what you are trying to do looks like it should work but doesn't, no matter how hard you pound on it. Usually there is more than one way to skin a program. Try approaching the problem from a different angle and maybe enlightenment will ensue.