I have developed several products using in-circuit programming of PICs without any problems. However, the latest product is causing problems:
The design uses a PIC16F876A running at 3.3V. The PGC and PGD pins are dedicated solely for programming, and MCLR has a 10K pull-up, but is also taken to the programming socket.
My problem is that although on occasion I have been able to use ICD2 to program and/or debug the product, most of the time programming fails, reporting memory locations as holding a value of 0x000 instead of the required value. If I erase the device through ICD2, MPLAB says the erase has succeeded, but if I then verify that the device is blank it fails, saying address 0x0 reads a value of 0x0 instead of 0x3FFF. If I read the device all locations read 0x00.
ICD2 correctly recognises the target device as a PIC16F867A, revision 0x8.
I know from previous experience that there are issues using in-circuit programming at 3.3V (particularly that Code Protection cannot be re-programmed at less than 5V, so if it is set there is no way of programming at 3.3V). However, my design is 5V tolerant, so I have tried configuring ICD2 to power the target. ICD2 then passes self-test and shows valid level on the target Vdd (4.8V), Target Vpp (12.6V) and MPLAB ICD 2 Vpp (12.7V), but programming still fails, with memory contents reading 0x00.
I have watched PGC and PGD on a scope while attempting to program (inside the ICD2 to confirm no problems with the connecting cable), and they have valid data levels. I have tried two different ICD2's (both of which work on other products), and I have run MPLAB on two different computers. I have also tried four different targets, but I get the same results every time.
I can unplug the ICD2 from the new product and plug it instead into a different target that uses a PIC18F252 running at 3.6V, then change the project on MPLAB, and I can program it using power from either the target or from the ICD2.
I am running out of ideas. Can anyone offer any suggestion why I should have this problem?