Author Topic: PIC ICSP Programming Circuit  (Read 7559 times)

0 Members and 1 Guest are viewing this topic.

Offline girishvTopic starter

  • Regular Contributor
  • *
  • Posts: 128
  • Country: in
PIC ICSP Programming Circuit
« on: July 17, 2020, 01:11:07 am »
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?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13378
Re: PIC ICSP Programming Circuit
« Reply #1 on: July 17, 2020, 03:33:59 am »
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.
« Last Edit: July 17, 2020, 03:39:58 am by Ian.M »
 
The following users thanked this post: girishv

Online kripton2035

  • Super Contributor
  • ***
  • Posts: 2747
  • Country: fr
    • kripton2035 schematics repository
Re: PIC ICSP Programming Circuit
« Reply #2 on: July 17, 2020, 06:32:58 am »
Quote
N.B. some of the most egregious /MCLR circuit mis-implementations originated from Microchip's own application notes, technical briefs, user manuals and datasheets.
so where are the good working ones ?
 

Offline woofy

  • Frequent Contributor
  • **
  • Posts: 415
  • Country: gb
    • Woofys Place
Re: PIC ICSP Programming Circuit
« Reply #3 on: July 17, 2020, 10:36:19 am »
Gotta love that floating reset sw.  ;)

Offline girishvTopic starter

  • Regular Contributor
  • *
  • Posts: 128
  • Country: in
Re: PIC ICSP Programming Circuit
« Reply #4 on: July 17, 2020, 10:39:26 am »
N.B. some of the most egregious /MCLR circuit mis-implementations originated from Microchip's own application notes, technical briefs, user manuals and datasheets.

The switch hanging in breeze was a rookie mistake :-[

I am have never used the PIC before. Could you point to an good working schematic for ICSP?
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 4253
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #5 on: July 17, 2020, 11:40:40 am »
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.
 

Offline girishvTopic starter

  • Regular Contributor
  • *
  • Posts: 128
  • Country: in
Re: PIC ICSP Programming Circuit
« Reply #6 on: July 17, 2020, 12:11:39 pm »
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.

I simplified the circuit as attached based on the feedback received.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13378
Re: PIC ICSP Programming Circuit
« Reply #7 on: July 17, 2020, 12:15:18 pm »
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. 
« Last Edit: July 17, 2020, 01:57:20 pm by Ian.M »
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 4253
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #8 on: July 17, 2020, 12:54:06 pm »
MCLR serves two purposes:
1) Putting a HV chip into program mode via Vpp; and
2) 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:
Quote
PIC16F87XA devices have a noise filter in the MCLR Reset path. The filter will detect and ignore small
pulses.

However, the datasheet for the 16F877A still includes a capacitor on MCLR when used for resetting:
1025250-0

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.

 
The following users thanked this post: Ian.M

Online kripton2035

  • Super Contributor
  • ***
  • Posts: 2747
  • Country: fr
    • kripton2035 schematics repository
Re: PIC ICSP Programming Circuit
« Reply #9 on: July 17, 2020, 04:22:46 pm »
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 icsp
there 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
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 4253
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #10 on: July 17, 2020, 05:35:47 pm »
@kripton2035

The 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.pdf

The 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.

 
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2513
  • Country: gb
Re: PIC ICSP Programming Circuit
« Reply #11 on: July 17, 2020, 05:59:33 pm »
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 Guide

Then...

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 ]
« Last Edit: July 19, 2020, 10:25:24 am by NivagSwerdna »
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 4253
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #12 on: July 17, 2020, 07:03:29 pm »
Assuming your part is 5V tolerant.  ;)
 
The following users thanked this post: NivagSwerdna

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13378
Re: PIC ICSP Programming Circuit
« Reply #13 on: July 17, 2020, 07:30:42 pm »
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!
 
The following users thanked this post: NivagSwerdna

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 4253
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #14 on: July 17, 2020, 07:36:10 pm »
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.
« Last Edit: July 17, 2020, 07:45:51 pm by jpanhalt »
 

Offline NivagSwerdna

  • Super Contributor
  • ***
  • Posts: 2513
  • Country: gb
Re: PIC ICSP Programming Circuit
« Reply #15 on: July 17, 2020, 09:13:18 pm »
R107 4.7K-10K  :palm: oops (I should have read the guide I quoted)
« Last Edit: July 17, 2020, 09:15:06 pm by NivagSwerdna »
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13378
Re: PIC ICSP Programming Circuit
« Reply #16 on: July 17, 2020, 09:40:02 pm »
That's why its good to come here for peer review . .  .
 
The following users thanked this post: NivagSwerdna

Offline girishvTopic starter

  • Regular Contributor
  • *
  • Posts: 128
  • Country: in
Re: PIC ICSP Programming Circuit
« Reply #17 on: July 18, 2020, 01:42:11 pm »
The OP circuit looks like some kind of Frankenstein monster offspring from an Arduino and a PIC ICSP!

I could not have found better words to describe! >:D 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.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2838
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #18 on: July 18, 2020, 09:01:38 pm »
All you need unless your circuit uses the programming pins (pins 12 and 13).

1026184-0
 
The following users thanked this post: girishv

Online kripton2035

  • Super Contributor
  • ***
  • Posts: 2747
  • Country: fr
    • kripton2035 schematics repository
Re: PIC ICSP Programming Circuit
« Reply #19 on: July 19, 2020, 06:28:48 am »
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 ?
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 4253
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #20 on: July 19, 2020, 10:16:03 am »
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 ?

That 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.
« Last Edit: July 19, 2020, 11:12:12 am by jpanhalt »
 

Online kripton2035

  • Super Contributor
  • ***
  • Posts: 2747
  • Country: fr
    • kripton2035 schematics repository
Re: PIC ICSP Programming Circuit
« Reply #21 on: July 19, 2020, 12:09:54 pm »
would a shottky diode from target vcc to pic vcc be enough to power by programmer and not power the lcd with backlight ?
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 4253
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #22 on: July 19, 2020, 12:32:59 pm »
"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.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13378
Re: PIC ICSP Programming Circuit
« Reply #23 on: July 19, 2020, 04:35:24 pm »
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.
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 4253
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #24 on: July 19, 2020, 05:12:28 pm »
Here is what I was worried about:
1026688-0

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?
 

Online NorthGuy

  • Super Contributor
  • ***
  • Posts: 3325
  • Country: ca
Re: PIC ICSP Programming Circuit
« Reply #25 on: July 19, 2020, 08:07:39 pm »
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.
 
The following users thanked this post: Ian.M, jpanhalt

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2838
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #26 on: July 20, 2020, 01:47:08 am »
I tend to disable the "Low voltage programming" in the PIC fuses
and 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.

1026916-0
 

Online NorthGuy

  • Super Contributor
  • ***
  • Posts: 3325
  • Country: ca
Re: PIC ICSP Programming Circuit
« Reply #27 on: July 20, 2020, 04:44:49 am »
I tend to disable the "Low voltage programming" in the PIC fuses
and set the PGM pin as I/O.

When 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.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2838
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #28 on: July 20, 2020, 05:03:24 am »
I tend to disable the "Low voltage programming" in the PIC fuses
and set the PGM pin as I/O.

When 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.

If you are doing 'High Voltage Programming', is this even possible?
Wouldn't that prevent you from ever disabling LVP?
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2838
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #29 on: July 20, 2020, 05:59:03 am »
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.

1026960-0

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.
 

Offline girishvTopic starter

  • Regular Contributor
  • *
  • Posts: 128
  • Country: in
Re: PIC ICSP Programming Circuit
« Reply #30 on: July 20, 2020, 12:07:20 pm »
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.

The MCU in question is PIC16F684, not PIC16F648A.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13378
Re: PIC ICSP Programming Circuit
« Reply #31 on: July 20, 2020, 12:40:42 pm »
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.

« Last Edit: July 20, 2020, 12:44:36 pm by Ian.M »
 
The following users thanked this post: girishv

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2838
  • Country: us
Re: PIC ICSP Programming Circuit
« Reply #32 on: July 20, 2020, 07:44:12 pm »
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.

The MCU in question is PIC16F684, not PIC16F648A.

The 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.


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.

It'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.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13378
Re: PIC ICSP Programming Circuit
« Reply #33 on: July 20, 2020, 08:16:04 pm »
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!)
 

Offline girishvTopic starter

  • Regular Contributor
  • *
  • Posts: 128
  • Country: in
Re: PIC ICSP Programming Circuit
« Reply #34 on: July 21, 2020, 12:17:30 am »
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.

The MCU in question is PIC16F684, not PIC16F648A.

The 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.


 :-[ It was a typo. I am sorry for creating confusion. The chip used is PIC16F684.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf