PIC18: Cannot program, Invalid Device ID, Circuitry on MCLR? - Page 1
Forum section: electronics / general

author: smoothVTer
author_rank: Regular Contributor
timestamp: January 11, 2017, 02:47:59 pm
content: Hello:I cannot program a PIC18 in-circuit on the target device board. The messages from MPLAB X read:QuoteI have inherited this design from another engineer who has since left the country. I've simplified the schematic below to only the relevant sections:Using MPLAB X, ICD3, with a PIC18F46J50. I have all updated drivers and new install of MPLAB.In firmware development phase, I've been using a Explorer 8 development board with a plug in module for this exact same processor except it is in the leaded version; programming works flawlessly from day one on the Explorer 8 dev board. On the product board, programming fails.I have no idea what the intention of D1A/B, R6, C3 is.Has anyone ever seen this particular arrangement on circuitry on MCLR and know its intention?Personally I have never seen this arrangement before, but I am fairly certain the prior engineer knew what they were doing; they just did not document the intention behind this before.Could D1A/B, R6, C3 be affecting the programming of my in-circuit device?I have quadruple-checked my programming connections PGD, PGC, VPP/MCLR, VDD, GND They are all good.J5/6 and J16/17 are external pushbutton switches on portB; no external pullups, the intention is to use the weak internal pullups of the PIC for these pins. These two pins are shared with PGD and PGC. Could this be a source of the programming problem?

author: DTJ
author_rank: Super Contributor
timestamp: January 11, 2017, 02:57:47 pm
content: To be certain try removing the two 100R resistors, remove D1 and test.

author: wraper
author_rank: Unknown
timestamp: January 11, 2017, 03:21:47 pm
content: C1 will fight pulling down of MLCR. Replace D1B with 4.7k resistor and she'll be fine.

author: smoothVTer
author_rank: Regular Contributor
timestamp: January 11, 2017, 03:43:01 pm
content: Unfortunately I cannot only remove D1B ... D1A/B are in the same package. I would have to remove both D1A and D1B at the same time, but since I am not sure what the function of D1A is, I do not know if they are providing some sort of protection or isolation which if removed would damage the PIC in-circuit. Any idea?

author: Ian.M
author_rank: Super Contributor
timestamp: January 11, 2017, 04:03:28 pm
content: The 'reset circuit' components C3, D1A,D1B serve no useful function as there is an internal weak pullup on /MCLR, and D1B prevents C6 holding /MCLR low while its charging. Disconnect it and try a simple 10K pullup on /MCLR.See:http://www.microchip.com/forums/m692754.aspxOther causes of programming problems can include excessive load on Vdd if the programmer is supplying power, or poor decoupling - especially Vcore or Vcap. The datasheet generally specifies a ceramic cap. Tantalums will usually also work, but Aluminium electrolytics tend to have excessive ESR and poor high frequency performance.

author: wraper
author_rank: Unknown
timestamp: January 11, 2017, 04:07:59 pm
content: Quote from: smoothVTer on January 11, 2017, 03:43:01 pmD1A is to discharge the cap when Vcc goes down. That is to prevent reset problems if you reapply the power fast enough, and cap still stays charged. D1A is not required at all, and, frankly, all of that circuit either. You could put different diode in sot-23 which has only one diode inside and bodge a resistor. But frankly, I really doubt previous engineer was fully understanding what he was doing.BTW this circuit does not provide any protection of the MLCR pin whatsoever.

author: wraper
author_rank: Unknown
timestamp: January 11, 2017, 04:14:30 pm
content: Quote from: Ian.M on January 11, 2017, 04:03:28 pmYep, the only thing it does, messes up with programming. If there was a resistor or just direct connection instead of D1B, it would at least do an external reset.

author: Ian.M
author_rank: Super Contributor
timestamp: January 11, 2017, 04:21:49 pm
content: A 5.6K resistor instead of D1B would work as all Microchip programmers and debuggers since the ICD2 and PICkit 2 are specced to drive a load of up to 5K on /MCLR. You can usually get away with 4K7 isolation resistors - lower is problematic. A direct connection is also likely to be problematic as excessive capacitance on /MCLR can cause the programmer to report a Vpp error or can cause programming mode entry problems resulting in various other errors.

author: smoothVTer
author_rank: Regular Contributor
timestamp: January 11, 2017, 06:25:57 pm
content: Hello everybody, thank you once again for your timely and productive help. I keep saying this but I wish I could buy you all a beer.(1) First I removed the entire D1, C3, and R6 circuitry. From your analysis as well as what I've read on Microchip's site, I agree that this could most likely cause programming issues. I removed D1/C3/R6 and added in place a 10k pullup from VDD to MCLR. I tried programming again, and again failed with the same message.(2) I moved on to removing all other possible sources of interference: R5 and R8. R5 & R8 share the PGD and PGC pins and go straight into the high side of separate common-mode chokes, which are connected to N.O. momentary switches. I believe the prior engineer was looking to minimize EMI interference into the button inputs, remove some common mode noise, or slow down edge rates. Whatever the reason,once I removed R5 & R8, I was able to program and communicate with my PIC18 in-circuit successfully.Even though J5 and J17 are left open floating ( giving no DC path to ground ), it seems the nature of the common-mode choke will still load down whatever is attached (? this is only my initial supposition ) to the other coupled side. What do you think? How does this common-mode choke ( with no DC path ) affect the clock/data lines?Plan moving forward: I am going to try better isolating the chokes from PGC/PGM using increased values of series resistors in place of R5 / R8 and see if I can successfully program in circuit once I solder in, say, 500 or 1k ohm in lieu. I will report back if I am successful or not.

author: PA0PBZ
author_rank: Super Contributor
timestamp: January 11, 2017, 06:40:26 pm
content: Quote from: smoothVTer on January 11, 2017, 06:25:57 pmTwo wires closely wound together leaving the other end open will create a nice capacitor.

author: smoothVTer
author_rank: Regular Contributor
timestamp: January 11, 2017, 06:57:08 pm
content: SOLVEDI changed R5 & R8 from 100 ohms to 470 ohms. This seems to have isolated the CM chokes enough to allow correct PIC programming. I'll keep a weary eye out for future programming errors and make a note in my reports in case an issue like this sneaks up again on someone else.About the note for the non-standard ICSP port pinout: I am aware of this and quadruple-checked my connections to and from the programmer, had to do some creative micro wire soldering to match what is on the PCB.

author: jaromir
author_rank: Unknown
timestamp: January 11, 2017, 07:29:59 pm
content: The "non-standard" ICSP pin layout is actually somehow better than "standard" where PGC and PGD are on adjacent lines, making it more susceptible to crosstalk between the lines, especially on longer lines from programmer - see herehttp://www.embedinc.com/picprg/icsp.htm- I've been bitten by this problem in past.

author: wraper
author_rank: Unknown
timestamp: January 12, 2017, 01:42:30 am
content: Quote from: smoothVTer on January 11, 2017, 06:25:57 pmMy guts tells me that previous engineer is an idiot.