Author Topic: ICSP Microchip issues ..or all me?  (Read 11080 times)

0 Members and 1 Guest are viewing this topic.

Offline PoeTopic starter

  • Regular Contributor
  • *
  • Posts: 246
ICSP Microchip issues ..or all me?
« on: February 02, 2015, 09:27:07 pm »
I'm accustom to programming PICs in a socket like the Picstart plus.  To enter the 21st century, I got a used PICkit3 and tried ICSP.

So far, not so good.  Is it me or the PICkit?

I soldered a 16f883 to a breakout board with a decoupling cap, bulk cap and a LED/resistor tied to one pin.  The Vpp, PGC, PGD pins are only connected to the PIC and less than an inch away.  Continuity all checks out.  Configuration is setup to use the internal oscillator and MCLR is internally tied to VDD.

Although the Vdd and ground pins are connected to the PIC, I powered the 'target' from a bench supply(5V).  Made sure that the "Power target circuit from PICkit3" checkbox was unchecked before doing that.  MPLAB shows a 5.0V on the PICkit3.

It worked for a dozen times, then started giving me errors.  "Target ID not expected value"... even though it's the same value (all zeros) that it was when it was working.

I looked at the programming lines and they look correct, I think.  I see Vpp ramp up to 13V then a few milliseconds later I see a burst on the data and clock lines.

The user manual talks about excessive capacitance on the Vdd line.  The other lines I can understand, but if I'm powering the target from a bench power supply, why should this matter?

I removed power to the target and used the PICkit3's power, it worked a couple times.  Now it appears completely random. 

Do I need anything else, or should I simply be able to power a PIC with an external 5V supply, and attach the unused pins to the PICkit?

Does the MCLR/Vpp pin need a pullup to Vdd as in their chart?  Does the PGM pin need tied to ground?

Edit:  Swapped out the PIC for a new one and removed the bulk cap.  The Target ID is still all zeros, but MPLAB doesn't give an error.  Very odd. 

Appears to work better without the bulk cap... not sure why that's an issue as I have it powered for at least a minute before programming.

SOLVED: PGM pin needs pulled low when using a PICkit to program.  Contrary to datasheet, it doesn't matter what config bits are set.
« Last Edit: July 11, 2016, 06:59:16 pm by Poe »
 

Offline Maxlor

  • Frequent Contributor
  • **
  • Posts: 565
  • Country: ch
Re: ICSP Microchip issues ..or all me?
« Reply #1 on: February 02, 2015, 09:44:27 pm »
As per the PICkit 3 User Guide, page 22, the setup you describe seems correct. The only thing I'm not sure about is whether the internal pullup for !MCLR suffices. Maybe try adding the external pullup resistor and see if that improves things?

I've also noticed that with some computers, not all USB sockets work equally well. With some, I've notice the PICkit3 sometimes freezing up (reconnect it to fix it), switching sockets helps. And it's not just limited to the PICkit3, I noticed the same with my Saleae too.
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Re: ICSP Microchip issues ..or all me?
« Reply #2 on: February 02, 2015, 09:44:54 pm »
Does this version have the low-voltage programming option? If so, make sure that the appropriate pin is tied to the inactive state (Usually RB3).
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: ICSP Microchip issues ..or all me?
« Reply #3 on: February 02, 2015, 09:45:53 pm »
PICstart plus? Blimey! I think I may have one of those somewhere from a decade+ ago!

MCLR should always have a 10k pullup unless it's in production on a chip that has an option to use it for GPIO. For debugging, I don't recommend overriding MCLR with a GPIO. MCLR is fundamental to the programming and debugging function.

PGM is only for low voltage programming, forget about it, but make sure your config bits have LVP off.

I have some 16F886's here, same chip just more memory, so zip up your code directory and I'll take a look.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: ICSP Microchip issues ..or all me?
« Reply #4 on: February 02, 2015, 10:05:42 pm »
Quote
Very odd

Read the datasheet and it wouldn't be odd anymore.
================================
https://dannyelectronics.wordpress.com/
 

Online Andy Watson

  • Super Contributor
  • ***
  • Posts: 2085
Re: ICSP Microchip issues ..or all me?
« Reply #5 on: February 02, 2015, 10:17:17 pm »
PGM is only for low voltage programming, forget about it, but make sure your config bits have LVP off.
Don't forget about it! I have experience of this programming problem with the 16f877 and its like. Sometimes the parts programmed ok; sometimes not. The parts always behaved in the PIC programmer but were random when using the ICSP on the product board. The problem was cured by pulling RB3 to VSS with a 100k - i.e. RB3 cannot be allowed to float during programming - irrespective of the LPV bit -  even in high-voltage programming.
 
The following users thanked this post: Poe

Offline PoeTopic starter

  • Regular Contributor
  • *
  • Posts: 246
Re: ICSP Microchip issues ..or all me?
« Reply #6 on: February 02, 2015, 10:28:01 pm »
Disconnecting the PICkit and reconnecting didn't appear to do anything.
Low voltage programming is disabled in the configuration, but I'll try that next.

I tied a 10k from MCLR to Vdd and it did... something. 

When powered by the PICkit it almost always connects with a device ID of all zero.  No error.

When programming it says:
"Failed to get Device ID"
"Programming/Verify complete"
...about 10% of the time.

When powered by the power supply, it say:
"Target Device ID (00000000) does not match expected Device
ID (00002020)."

When programming..
"Programming...
The following memory regions failed to program correctly:
Program Memory
Address: 00000000 Expected Value: 00002826 Received Value: 00000000
Programming failed"

I don't see anything in the datasheet that would explain the device ID thing.  Maybe a page number hint?
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: ICSP Microchip issues ..or all me?
« Reply #7 on: February 02, 2015, 10:30:20 pm »
Just hacked up a breadboard with the 886. It is the same chip but more memory.


Here is my code, with the minimum to get going.

Code: [Select]
#include <xc.h>

#pragma config LVP=OFF
#pragma config PWRTE=OFF
#pragma config WDTE=OFF
#pragma config MCLRE=ON

int main(void)
{
TRISBbits.TRISB5=0;

while (1)
{
PORTB=0b00100000;
PORTB=0b00000000;
}
}

I first tried this on MPLAB 8.92 with ICD 3, no problem.

I then plugged in PICkit 3 to test that, I got the same error as you, ie wrong target. Weird.

Switched to MPLAB X 2.30. Migrated the project. Worked fine with the PICkit 3 (it re-loaded some new PICkit firmware).

Switched back to MPLAB 8.92 and it started working, again it reloaded the PICkit firmware.

« Last Edit: February 02, 2015, 10:37:51 pm by Howardlong »
 
The following users thanked this post: Poe

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: ICSP Microchip issues ..or all me?
« Reply #8 on: February 02, 2015, 10:36:55 pm »
PGM is only for low voltage programming, forget about it, but make sure your config bits have LVP off.
Don't forget about it! I have experience of this programming problem with the 16f877 and its like. Sometimes the parts programmed ok; sometimes not. The parts always behaved in the PIC programmer but were random when using the ICSP on the product board. The problem was cured by pulling RB3 to VSS with a 100k - i.e. RB3 cannot be allowed to float during programming - irrespective of the LPV bit -  even in high-voltage programming.

Never encountered that before, but worth keeping in mind. I have a device I designed 12 or 13 years ago based on the PIC16F877/877A, I don't know how many were sold as I gave away the IP, but it's many thousand. That has RB3/PGM floating during programming, and it's the end user who programs it via a serial port. Maybe if it's already had its LVP bit programmed it's a problem, I don't know.
 

Offline Gixy

  • Regular Contributor
  • *
  • Posts: 232
  • Country: fr
Re: ICSP Microchip issues ..or all me?
« Reply #9 on: February 02, 2015, 10:42:21 pm »
Useful article of well known Olin Lathrop on this subject:
http://www.embedinc.com/picprg/icsp.htm
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: ICSP Microchip issues ..or all me?
« Reply #10 on: February 02, 2015, 10:57:10 pm »
I think you are right.

I just erased the chip, unplugged everything, started again, and the fault reappeared.

Code: [Select]
Resetting...
PK3Err0040: The target device is not ready for debugging.
Please check your configuration bit settings and program
the device before proceeding.

Programming...
Programming/Verify complete

Running...
PK3Err0040: The target device is not ready for debugging.
Please check your configuration bit settings and program
the device before proceeding.

Put link to ground on RB3/PGM, erased, tried again, no problem.



Learn something new every day! Nice tip, although I don't use these old chips with LVP much these days it has to be said.

Edit: can't make an erased chip fail with an ICD 3 or Real ICE either, maybe they did something fancy with those debuggers. But yes, thanks for the tip, I won't forget that one.
« Last Edit: February 02, 2015, 11:18:56 pm by Howardlong »
 

Offline PoeTopic starter

  • Regular Contributor
  • *
  • Posts: 246
Re: ICSP Microchip issues ..or all me?
« Reply #11 on: February 03, 2015, 12:29:50 am »
SUCCESS!

Connecting PGM to ground via a 10k resistor worked.  Thank you so much!

 :-+ :)


 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: ICSP Microchip issues ..or all me?
« Reply #12 on: February 03, 2015, 12:54:02 am »
Quote
That has RB3/PGM floating during programming

That depends on the lvp fuse setting.
================================
https://dannyelectronics.wordpress.com/
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: ICSP Microchip issues ..or all me?
« Reply #13 on: February 03, 2015, 02:03:02 am »
Quote
That has RB3/PGM floating during programming

That depends on the lvp fuse setting.

Yes we figured that out already. Unfortunately when the part is new or erased, the default is that LVP is enabled.

It is not in the device's Main data sheet. It is hidden away in the programming spec, under the low voltage programming bit description in a rather vague way, but more specifically it is in the errata. Yet another reason to always read the errata, even a brief scan is worth it so you are aware.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: ICSP Microchip issues ..or all me?
« Reply #14 on: February 03, 2015, 11:58:44 am »
Quote
It is not in the device's Main data sheet.

Then you didn't read the datasheet carefully, because it is right there, in plain sight and couldn't have been more clearly stated.

================================
https://dannyelectronics.wordpress.com/
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: ICSP Microchip issues ..or all me?
« Reply #15 on: February 03, 2015, 09:48:17 pm »
Quote
It is not in the device's Main data sheet.

Then you didn't read the datasheet carefully, because it is right there, in plain sight and couldn't have been more clearly stated.

Go on then, put us out of our misery, where is it stated in the DS for the device in question that you need to hold PGM low while performing a high voltage program?
 

Offline PoeTopic starter

  • Regular Contributor
  • *
  • Posts: 246
Re: ICSP Microchip issues ..or all me?
« Reply #16 on: February 04, 2015, 04:32:38 pm »
Gotta say, if it's there in the datasheet I don't see it. 
Maybe he meant errata?  I see it there and I must have glossed over that bit initially.
No matter.  Thanks again for the help.
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: ICSP Microchip issues ..or all me?
« Reply #17 on: February 04, 2015, 05:26:16 pm »
Gotta say, if it's there in the datasheet I don't see it. 
Maybe he meant errata?  I see it there and I must have glossed over that bit initially.
No matter.  Thanks again for the help.

Indeed, suddenly it's all been a bit quiet on the matter too I notice. I am sure it was the DS itself that was being referred to, the programming and errata sheets I'd mentioned myself had been discounted.

Generally speaking, even if you don't know the ins and outs of a chip these days I find it's worth taking a brief look at the errata early on for an executive summary. It still hits me every once in a while though on new chips, wasting half a day on so on something that's not you.

Anyway, it'd not be half as much fun if we weren't learning something new every day.
 

Offline neslekkim

  • Super Contributor
  • ***
  • Posts: 1305
  • Country: no
Re: ICSP Microchip issues ..or all me?
« Reply #18 on: February 04, 2015, 06:54:24 pm »
Quote
It is not in the device's Main data sheet.

Then you didn't read the datasheet carefully, because it is right there, in plain sight and couldn't have been more clearly stated.

Go on then, put us out of our misery, where is it stated in the DS for the device in question that you need to hold PGM low while performing a high voltage program?

Page 27: http://ww1.microchip.com/downloads/en/DeviceDoc/41287D.pdf

"b) make certain that RB3/PGM is held low during entry into ICSP."
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: ICSP Microchip issues ..or all me?
« Reply #19 on: February 04, 2015, 08:47:14 pm »
Quote
It is not in the device's Main data sheet.

Then you didn't read the datasheet carefully, because it is right there, in plain sight and couldn't have been more clearly stated.

Go on then, put us out of our misery, where is it stated in the DS for the device in question that you need to hold PGM low while performing a high voltage program?

Page 27: http://ww1.microchip.com/downloads/en/DeviceDoc/41287D.pdf

"b) make certain that RB3/PGM is held low during entry into ICSP."

Thank you, but I believe that only applies if Master Clear is disabled, and we have enabled the master clear pin, as the code showed. In addition even if it wasn't, it's either (a) or (b) that needs to be satisfied, and (a) is satisfied with the LVP config bit cleared in the code.

Code: [Select]
#pragma config LVP=OFF
.
.
#pragma config MCLRE=ON

Quote
3. If the device Master Clear is disabled, verify that either of the following is done to ensure proper entry into ICSP mode:
a) disable Low-Voltage Programming (Config Word 1<12> = 0); or
b) make certain that RB3/PGM is held low during entry into ICSP.
« Last Edit: February 04, 2015, 11:13:35 pm by Howardlong »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf