PIC ICSP Programming Circuit - Page 1
Forum section: electronics / general

author: girishv
author_rank: Regular Contributor
timestamp: July 17, 2020, 01:11:07 am
content: Hi,I am redoing a layout of an legacy PIC board. I don't have schematic of the board. I have drawn the schematic of ICSP programming section on my own.Will this do the job?

author: Ian.M
author_rank: Super Contributor
timestamp: July 17, 2020, 03:33:59 am
content: Where's the PIC? (I *ASS*U*ME* directly in parallel with J2).Also, (nitpick) the bottom of the switch is flapping in the breeze!So you want to short a charged 0.1uF capacitor directly with a switch? It had better be an elastomer contact one, as with a metal contact switch, the surge current is only limited by the loop inductance and the capacitor's ESR and it will radiate a significant EMI pulse while its ringing. Contact damage is also possible. To mitigate this insert a 47R resistor in the discharge path.Diodes are lousy for isolaton of /MCLR(Vpp), If you put them the way round that blocks Vpp from reaching the reset circuit,(as you have D8) they leave /MCLR floating when the reset circuit is supposed to be holding it low. Whether or not it resets is a matter of luck involving D8's leakage current, junction capacitance, and the exact input characteristics of the /MCLR pin. I strongly recommend putting a 10K isolation resistor in place of D8.N.B. some of the most egregious /MCLR circuit mis-implementations originated from Microchip's own application notes, technical briefs, user manuals and datasheets.

author: kripton2035
author_rank: Super Contributor
timestamp: July 17, 2020, 06:32:58 am
content: Quoteso where are the good working ones ?

author: woofy
author_rank: Frequent Contributor
timestamp: July 17, 2020, 10:36:19 am
content: Gotta love that floating reset sw.

author: girishv
author_rank: Regular Contributor
timestamp: July 17, 2020, 10:39:26 am
content: Quote from: Ian.M on July 17, 2020, 03:33:59 amThe switch hanging in breeze was a rookie mistakeI am have never used the PIC before. Could you point to an good working schematic for ICSP?

author: jpanhalt
author_rank: Super Contributor
timestamp: July 17, 2020, 11:40:40 am
content: There are differences in Microchip's recommendations that depend on the chip. Specifically, D8 is not needed. D7, if used to protect things attached to VCC from VPP, should be reversed. However, the 10 k resistor is probably adequate. C10 may not be needed.What's the purpose of the push-button switch? The programmer should take care of that.

author: girishv
author_rank: Regular Contributor
timestamp: July 17, 2020, 12:11:39 pm
content: Quote from: jpanhalt on July 17, 2020, 11:40:40 amI simplified the circuit as attached based on the feedback received.

author: Ian.M
author_rank: Super Contributor
timestamp: July 17, 2020, 12:15:18 pm
content: I didn't want to imply that *ALL* Microchip's suggested reset circuits are bad, as many were appropriate to the the specific PIC or generation of PIC they were intended for. However Microchip documentation sticks around for a very long time, and a little too much 'copypasta' with insufficient QC was often used when writing new documents, to the point that in the first revision of older device datasheets it wasn't uncommon to find a whole paragraph about hardware features that didn't even exist! When your device datasheet or programmer user guide suggest a reset circuit, please sanity check it!D7 speeds up discharging C10 if the Vdd rail briefly drops out. However as the reset RC time constant is only 1ms and one usually has enough bulk capacitance to ride through an order of magnitude longer than that, its fairly pointless. On the other hand, if you are also using an external power supervisor IC with its open collector output in parallel with the switch, D7 then serves to protect the supervisor from the up to 13.5V programming voltage of the early generations of FLASH PICs.You usually don't have to worry about the Vdd rail rising during programming as the programmer's buffers will draw at least 1mA from Vdd, and at 4.5V Vdd, the minimum supply during full programming for the early FLASH PICs, and abs.max. Vpp at 13.5V there can only be 0.9mA through a 10K pullup from /MCLR to Vdd.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 17, 2020, 12:54:06 pm
content: MCLR serves two purposes:1) Putting a HV chip into program mode via Vpp; and2) Resetting a chip.The requirements for each purpose differ and to an extent conflict. That is, a capacitor is contraindicated for VPP programming, at least for later chips.I interpreted the TS was interested in programming. In that event, C10 is not needed. If one is also interested in resetting, then some way to soften the reset is may be needed.One typically sees C10 recommended for older chips, but not for newer chips. See, PIC16F887, Fig. 14-11 and PIC16F1789, Fig.29-3 for example. This statement is common:QuoteHowever, the datasheet for the 16F877A still includes a capacitor on MCLR when used for resetting:I don't know that it makes much difference, but with my usual enhanced mid-range chips, I tend to omit it. Knowing the actual chip for which the TS posted this question might help. There also seem to be recommendations for the ICD-2 programmer/debugger that may not apply to ICD-3 and later programmers/debuggers. Similarly, the PK-3 with its weak power supply may be more affected than PK-4 and later.Microchip seems to be particularly fuzzy on what should be done for the MCLR pin as well as for what it calls "isolation" circuits. Its forums are some help, but there is also a variety of opinions there.

author: kripton2035
author_rank: Super Contributor
timestamp: July 17, 2020, 04:22:46 pm
content: it's quite strange that there is NO simple, trusted published schematic that connect any PIC with ICSP.I have a pic that I simply cannot program with icsp, it's working with the pic inside a tl866, but not with icspthere is only a lcd display on it, with no pin shared with icsp. I tried many things and it does not work.edit: it is a pic 16f88

author: jpanhalt
author_rank: Super Contributor
timestamp: July 17, 2020, 05:35:47 pm
content: @kripton2035The 16F87/88 are low-voltage programmable chips. If it is working in another device, then it may well have code protect enabled and/or be set to high-voltage programming only.This document describes in detail what to do:http://ww1.microchip.com/downloads/en/DeviceDoc/39607c.pdfThe most sure way is to use high-voltage programming and erase the chip as your first step. Then, set your configuration registers and program. Once the chip is erased, you can re-enable LVP if you want.What are you using to program it? Is it in circuit or bare? If in circuit, are you powering by the programmer or target?If it is in circuit, it is possible that the data, clock, and/or MCLR lines have stuff on them that is preventing programming.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: July 17, 2020, 05:59:33 pm
content: The OP circuit looks like some kind of Frankenstein monster offspring from an Arduino and a PIC ICSP!Firstly, follow the guidelines in the PICKit User GuideThen...All you need is PGD/PGC and /MCLR. For your own reset... just short to GND and in normal operation pull up to VCC.Here's my latest creation....[ Attachment Invalid Or Does Not Exist ][ Attachment Invalid Or Does Not Exist ][ Attachment Invalid Or Does Not Exist ]

author: jpanhalt
author_rank: Super Contributor
timestamp: July 17, 2020, 07:03:29 pm
content: Assuming your part is 5V tolerant.

author: Ian.M
author_rank: Super Contributor
timestamp: July 17, 2020, 07:30:42 pm
content: Yes, don't do that unless you have a production programmer you know is rated to drive a 1K load on Vpp, and if you are using an older PIC with HV programming, your design had better draw at least 8mA from Vdd all the time to stop Vdd rising, as the programmer is going to be dumping around 9mA into it.Microchip's older development programmers and debuggers weren't rated to drive loads of less than 5K on Vpp. You can go a *bit* lower, so a 4K7 /MCLR pullup is unlikely to cause problems with ICSP.One trap for the unwary is using an older PIC in a low voltage design, when the PIC needs significantly more voltage to bulk erase it for reprogramming. Its very easy to kill 3.3V only chips sharing Vdd. I heard of one engineer who lost his desk to a fire tht caused his whole company to evacuate: IIRC his PICkit 3 over-charged and set on fire the LiPO his PIC was running off!

author: jpanhalt
author_rank: Super Contributor
timestamp: July 17, 2020, 07:36:10 pm
content: I didn't know PK3 was specified to be a LiPo charger too. Oh well. Nothing is foolproof. People get hit by meteorites too.EDIT:Let me clarify, I meant the above tongue-in -cheek. Generally, I use an ICD3 rather than PK. Unless it is almost a bare chip, I power by target. It's just more convenient in my set-up.

author: NivagSwerdna
author_rank: Super Contributor
timestamp: July 17, 2020, 09:13:18 pm
content: R107 4.7K-10Koops (I should have read the guide I quoted)

author: Ian.M
author_rank: Super Contributor
timestamp: July 17, 2020, 09:40:02 pm
content: That's why its good to come here for peer review . . .

author: girishv
author_rank: Regular Contributor
timestamp: July 18, 2020, 01:42:11 pm
content: Quote from: NivagSwerdna on July 17, 2020, 05:59:33 pmI could not have found better words to describe!BTW, I am the OP.I have never worked on the PIC. I was asked to redo a layout of legacy board with PIC16F684. As they have an inventory of PIC16F648's, they can roll out more boards without changing the design.I did look around on Microchip forum and Web. I found a circuit similar to one I posted originally. I thought, it might do the job! It was good I asked here.

author: MarkF
author_rank: Super Contributor
timestamp: July 18, 2020, 09:01:38 pm
content: All you need unless your circuit uses the programming pins (pins 12 and 13).

author: kripton2035
author_rank: Super Contributor
timestamp: July 19, 2020, 06:28:48 am
content: how to separate correctly vcc of the programmer from vcc of the circuit ?so that the programmer only powers up the pic to program, and not all the circuit ?

author: jpanhalt
author_rank: Super Contributor
timestamp: July 19, 2020, 10:16:03 am
content: Quote from: kripton2035 on July 19, 2020, 06:28:48 amThat is not usually done. VCC of programmer must be connected to VCC of the circuit (target) even when power is by target. Otherwise,it will not recognize the chip. At least it is that way with ICD3.You have two choices in the menu: 1) Programmer powers everything; and 2) Target provides power.Now, if you have power hungry peripherals, say an LCD with backlight, you can unplug it during programming. However, if you try to do debugging with it unplugged you may have problems depending on your program, so you may need to modify the program too.For me, the easy way has just been to power by target.EDIT: One can set up a breadboard to program only the MCU. In fact, PicStart Plus was an early programmer from Microchip with a built-in ZIF socket for doing that. It is way outdated. I assume you want to program "in circuit" but without powering the circuit.

author: kripton2035
author_rank: Super Contributor
timestamp: July 19, 2020, 12:09:54 pm
content: would a shottky diode from target vcc to pic vcc be enough to power by programmer and not power the lcd with backlight ?

author: jpanhalt
author_rank: Super Contributor
timestamp: July 19, 2020, 12:32:59 pm
content: "Target" is the PIC + everything else it is connected to. I can't visualize how you would place the diode in the VCC line.If you consider just an LCD, putting a diode in its VCC connection will do nothing. You also have to consider that many chips can be "back powered" by pins that are not labeled "VCC." You can see that in PIC's, for example.

author: Ian.M
author_rank: Super Contributor
timestamp: July 19, 2020, 04:35:24 pm
content: The programmer/debugger needs a direct connection to target PIC Vdd, however it is possible to include a Schottky diode in the feed from the target board's Vdd rail to the PIC so if the target board is unpowered, the programmer can still power the PIC to program it, without having to power up everything else on the target board.The downsides are slightly less Vdd voltage to the PIC and reduced ADC accuracy if you are using Vdd as the reference. Also don't do it unless /MCLR is enabled as the programmer needs to be able to keep the PIC in Reset before program mode entry and between programming phases to keep its non-ICSP I/Os Hi-Z.

author: jpanhalt
author_rank: Super Contributor
timestamp: July 19, 2020, 05:12:28 pm
content: Here is what I was worried about:If VCC to the PIC's VCC has a blocking diode and is floating (i.e., mot powered), then ICSPDAT and ICSPCLK will forward bias those diodes to VCC.Maybe it will work. I don't know and have never tried it, as I never saw a need to do it. It is much easier to just power by the target. Have you actually tried it?

author: NorthGuy
author_rank: Super Contributor
timestamp: July 19, 2020, 08:07:39 pm
content: For PIC16F88, you need to make sure the PGM pin is tied down (through a resistor or driven by the programmer), even if you only use HVP programming.

author: MarkF
author_rank: Super Contributor
timestamp: July 20, 2020, 01:47:08 am
content: I tend to disable the "Low voltage programming" in the PIC fusesand set the PGM pin as I/O.I only use "High voltage programming".Then just add a simple jumper between the PIC/ICSP and the rest of your circuit.With the jumper, you can then switch between "programmer powered" and "circuit powered".This way you can have the PCB manufactured, program the PIC and then solder a jumper for delivery/testing.

author: NorthGuy
author_rank: Super Contributor
timestamp: July 20, 2020, 04:44:49 am
content: Quote from: MarkF on July 20, 2020, 01:47:08 amWhen you program the device, the programmer does bulk erase first. This restores the default LVP=ON setting. If the programmer resets the PIC while in this state, and PGM is high, the PIC may enter LVP mode causing the programming to fail. Not all PICs with PGM pin are vulnerable to this, but many are.

author: MarkF
author_rank: Super Contributor
timestamp: July 20, 2020, 05:03:24 am
content: Quote from: NorthGuy on July 20, 2020, 04:44:49 amIf you are doing 'High Voltage Programming', is this even possible?Wouldn't that prevent you from ever disabling LVP?

author: MarkF
author_rank: Super Contributor
timestamp: July 20, 2020, 05:59:03 am
content: Not sure. But it looks like the OP is using a pic16f648a.According to the Errata, the state of the PGM pin during 'High voltage programming' doesn't matter.For safety, put a 100KΩ resistor to GND on the PGM pin.That size resistor will not impact the rest of the circuit if you want to use the PGM pin.

author: girishv
author_rank: Regular Contributor
timestamp: July 20, 2020, 12:07:20 pm
content: Quote from: MarkF on July 20, 2020, 05:59:03 amThe MCU in question is PIC16F684, not PIC16F648A.

author: Ian.M
author_rank: Super Contributor
timestamp: July 20, 2020, 12:40:42 pm
content: Life's too short to wade through Microchip's (incomplete) errata, and anecdotal evidence on their forum to figure out exactly which of the early LVP capable PICs can be affected by glitches or high levels on PGM at HV programming mode entry, or while HV programming is in progress.In all cases, if a PIC has a seperate PGM pin for LVP mode entry, wire it to pin 6 (AUX/LVP) of the ICSP connector, and if the target board is capable of driving it with a 'stiff' logic '1', add an isolation resistor between it and the rest of the target board. Ensure HV programming is selected in whatever software your programmer uses, and simply let the programmer handle it.The fuse to disable LVP programming cant be disabled in LVP mode. If its left enabled, you cant disable /MCLR or use the PGM pin for I/O. Also a floating PGM pin at runtime can cause unwanted LV Programming mode entry, which if its brief enough has apparent symptoms closely resembling an unintended device reset.

author: MarkF
author_rank: Super Contributor
timestamp: July 20, 2020, 07:44:12 pm
content: Quote from: girishv on July 20, 2020, 12:07:20 pmThe pic16f684 doesn't have a PGM. So, this discussion is mute.I mentioned the pic16f648a because you said it might be a replacement with a PCB design change.Quote from: Ian.M on July 20, 2020, 12:40:42 pmIt's just good engineering practice to 'wade' through the manufacture's documentation for the device you're using. Complete or not. The more you know about a device the better. Why leave it to 'Murphy'?If it's for a personal project, then by all means roll-the-dice.

author: Ian.M
author_rank: Super Contributor
timestamp: July 20, 2020, 08:16:04 pm
content: Yes,its good practice to read the documentation and all relevant errata, and absolutely essential for commercial product development, but when the 'smoking gun' that there is probably a hardware issue is *NOT* in the errata but is buried in a several years old forum thread where it was admitted off-the-cuff by a Microchip 'staffer', if you don't have sufficient background to remember that forum thread, you'll be rolling-the-dice anyway, without even realising it.I'd be much more impressed with Microchip if they'd implement a hardware bug-tracker, updated by level two and higher support and the chip development teams, and publicly searchable and viewable. (Not publicly or level one support updatable to prevent it being spammed with non-bugs by numpties!)

author: girishv
author_rank: Regular Contributor
timestamp: July 21, 2020, 12:17:30 am
content: Quote from: MarkF on July 20, 2020, 07:44:12 pmIt was a typo. I am sorry for creating confusion. The chip used is PIC16F684.