Main page Castellano  Deutsch  English 

When the PIC doesn't "co-operate" ...

Using a PIC is easy: write some code, burn it into the Flash-ROM, put the PIC in your application circuit, supply voltage and it works — well, mostly ...

For all supporters of Murphy's law, here are some ideas what may go wrong.

The PIC doesn't work at all

Possible causes:

  1. The PIC is not inserted correctly.
    Sounds stupid, but it is not impossible to put a PIC the wrong way around, bend a pin or get a socket with bad contacts.
  2. Missing supply voltage.
  3. Oscillator failure.
    My favourite. If speed and accuracy doesn't matter I would recommend the use of the internal oscillator. It simplifies the board design and you get two extra I/O pins.
  4. The PIC stays in RESET state.
    Besides of the simple cause that the /MCLR pin is "accidentally" held "low", there are other not so visible situations which may prevent the PIC from running:
  5. The debugger logic is enabled.
    When debugger logic is enabled, the PIC executes the first instruction and then halts. Therefore, after debugging your software you must re-program the PIC in normal mode before using it within the application circuit.
  6. The PIC seems to have passed away.
    In my experience, PIC are "hard to die". Even after reversing the supply voltage, there is hope. Before transforming it into a nice sculpture you may try to recover the PIC by erasing it several times.

The PIC doesn't work as intended

Possible causes:

  1. Wrong register bank selected.
    The op-code of the mid-range PIC 12Fxxx/16Fxxx can only hold the lower 7 bits of the register address. To permit more than 128 registers they are organized in two or four banks. When writing assembler code, before accessing a register, you must ensure that the corresponding bank is selected within the STATUS register.
    If MASM generates a "List file", the editor of 'PicProm' can show both, the HEX file and the corresponding source lines, which permits a visual verification of the generated code.
    (With MASM you indeed can use the pseudo instruction "banksel" before every register access, which will generate the required instructions to set the bank bits properly, but I would not recommend this method for two reasons: first, apparently you can't put a label in the same line, and second, this pseudo instruction always generates code — even if the bank bits are already correctly set — thus blowing up code size and increasing execution time.)
  2. Wrong code page selected.
    The op-code of the mid-range PIC 12Fxxx/16Fxxx can only hold the lower 11 bits of a call or jump target address, which gives a direct address range of 2 KWords. When your code exceeds these 2 KWords, you must ensure that the corresponding target page is selected within the PCLATH register before executing a "goto" or "call".
  3. The Watchdog Timer periodically resets the device.
    If the Watchdog Timer is enabled — which is the default state —, make shure to distribute "clrwdt" instructions within the code in such a way that on normal operation at least every 10 ms one of them is executed.
    Before deactivating the Watchdog Timer in the Configuration Word you should take into consideration, that this is the only way for a PIC to "recover itself" when it is trapped in an endless loop for some software malfunction.
  4. The I/O ports are not initialized properly.
    On "Power-on Reset" some port pins may be configured as analog input and always read '0'. This is device dependent. See the data sheet for correct port initialization.
  5. Instruction with I/O port as target.
    When modifying port data, you should be aware that the instruction will read the current – external – state of all port pins and write the result to all output buffers of the port. This may give unexpected results. Some examples:
  6. Missing main loop.
    Simply spoken, once powered up, the PIC will execute instructions from program memory until it is powered down. There is no "halt" instruction and the "END" statement of an assembler code block has no meaning with respect of code execution.
    Thus, the program must contain a (never ending) main loop or — if the program should only run once after power-up — at least terminate with a "goto $" instruction to avoid the execution of empty program memory.
  7. Stack overflow.
    The 12Fxxx/16Fxxx PIC have only 8 stack levels for "call" instructions and the interrupt routine. If your program makes a too excessive use of nested subroutines a stack overflow may occur — and there is no special handling provided. The program will simply crash.
    Therefore, when loading the HEX file, 'PicProm' will analyze it and gives a warning if stack overflow might occur during program execution.
  8. Missing bypass capacitor.
    A decoupling capacitor of 100nF should be provided as close as possible to the Vdd and Vss pins of the PIC. My preferred way for PDIP-devices is soldering a small SMD capacitor directly between the pins.

back to the main page