Author Topic: PIC16F722 programing troubles especialy for debug mode  (Read 13110 times)

0 Members and 1 Guest are viewing this topic.

Offline Feanor

  • Regular Contributor
  • *
  • Posts: 56
PIC16F722 programing troubles especialy for debug mode
« on: December 16, 2010, 12:26:23 pm »
I can program for release but not for debug!

I have connected up a PIC16F722 to an RJ11 header for use with my ICD3. I have supplied power via a 240V to 35V step down transformer, rectified, smoothed with large capacitor and regulated with a LM7805. The output voltage is 5.15V according to the oscilloscope.

I can program the device when I am just programing and not debugging the program works, changing the clock speed and toggling PORTB indefinitely. However when trying to debug the program does not run at all. I often but not always receive the error:

The following memory regions failed to program correctly:
Debug Executive
Programming failed

I am not sure what is going wrong. The problem seems to be worse when I use my own power supply and not the ICD3 on board power supply. So far I am investigating three potential sources of the problem, I am not sure at all if these are the sources I am just guessing at this stage.

1. Capacitance added to the power terminals of my PIC16F722 the ICD3 quick start has a picture showing that no capacitance should be added to the power terminals of the micro, I thought this was a mistake on their part.
2. I have missed a configuration bit required for debugging.
3. Cross talk and or noise on my in circuit serial programing lines.

Any other advice on whether capacitance should be removed from the micro power terminals, or other potential problems I have missed, would be much appreciated.

Here is the simple program I am using to get started.

#include <htc.h>

__CONFIG(INTCLKO & WDTDIS & PWRTDIS & BORDIS &
DEBUGEN & UNPROTECT);


void main(void)
{
// port directions: 1=input, 0=output
TRISB = 0b00000000;
OSCCON = 0xff;

while (1){
PORTB = 0xff;
_delay(1000);
PORTB = 0x00;
_delay(1000);

}
}

The PIC is being used for a switch mode current controlled variable voltage supply, hence the large diode bridge seen on the board. The two other chips are latching BCD to HEX converters and the small MOSFETS are 2N7000's. None of these other components are connected.
 

Offline migsantiago

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: 00
    • MigSantiago's Web Site
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #1 on: December 16, 2010, 02:41:21 pm »
Hey there

When I debug any PIC I never add the DEBUG configuration bit, I allow MPLAB to add it for me. I also never code protect the PIC, which is OK in your config function.

I also found some debugging glitches when using compiler optimizations. Try to select the Lite compiling mode of HiTech.

RB7 and RB6 are PGD and PGC. By asking MPLAB to debug your PIC, those pins will be disabled for I/O and enabled for ICSP debugging. It's OK not to connect anything in there such as capacitors, just like you said.

The ICD Vdd and Vss must be directly connected to the Vdd and Vss of the PIC power supply. Do not connect anything between them (such as voltage regulators, diodes, resistors, etc.).
 

Offline Feanor

  • Regular Contributor
  • *
  • Posts: 56
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #2 on: December 18, 2010, 05:01:31 am »
Check, check and check. I tried removing the DEBUGEN from the configuration bits with no change in the problem. Power pins of the PIC are directly connected to the ICD3. I am now beginning to wonder if the little break out board I am using is causing the problems see pictures. Or my PGD and PGC wires are too long (green and blue and white in the picture).

Can still get it to program in program only mode, I guess there is a great deal less communication required for that mode. I have attatched a scope waveform of the PGD signal. Looks a bit messy to me any ideas out there as to weather this could be causing the problem?
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11010
  • Country: my
  • reassessing directives...
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #3 on: December 18, 2010, 01:00:10 pm »
pls post your schematics, i will analyze it, i'm an expert on this 8)
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline migsantiago

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: 00
    • MigSantiago's Web Site
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #4 on: December 18, 2010, 02:14:41 pm »
An schematic rather than a soldered board would be easier to review.
 

Offline Feanor

  • Regular Contributor
  • *
  • Posts: 56
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #5 on: December 19, 2010, 03:58:19 am »
Sorry, I should have put up a schematic at the beginning. Here it is. As you can see I have not connected any of the other devices, just the PIC16F722 and the ICD header and the power supply. The transformer is a microwave oven transformer being used as a step down not step up. The Diode bridge is the big silver square as shown in the photos, the voltage regulator is a standard 7805.

At the moment I can program/verify in debug mode but when I click run the PIC does nothing. The oscillator frequency remains unchanged (8MHz), PORTB remains input. When I am in program only mode my simple program works, the oscillator frequency speeds up(16MHz), and PORTB becomes an output and toggles at about 2kHz.

Thanks for the help so far. I feel I am close to getting this working.
 

Offline migsantiago

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: 00
    • MigSantiago's Web Site
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #6 on: December 19, 2010, 03:02:44 pm »
Connect MCLR to Vdd through a 10k resistor.

Connect MCLR to Vpp from the ICSP port.

Read the ICD3 manual, check out what PICs can be programmed with or without using an ICD header (RJ11).
 

Offline Feanor

  • Regular Contributor
  • *
  • Posts: 56
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #7 on: December 20, 2010, 09:35:31 am »
I added the 10k resistor between MCLR and Vdd. MCLR and Vpp were already connected.

There has been no change I am afraid.

The 16F722 does not need a special header, but one is available for it.

I am starting to think that my physical connections are the problem and do not support the extra communications required during debug. I will try soldering up another one with better connections. 
 

Offline migsantiago

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: 00
    • MigSantiago's Web Site
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #8 on: December 20, 2010, 02:57:53 pm »
I think I have a PIC16F722. If you send some MPLAB project to me I could test it and debug it with my Pickit2.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11010
  • Country: my
  • reassessing directives...
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #9 on: December 21, 2010, 11:49:34 am »
try to power from pickit/icd without internal Vsupply, see if any problem. if no problem, then i think its in the internal supply circuit. i see your icsp connection is straight forward, except in the int. V and icd V meet up, sorry i'm no expert on that :P
« Last Edit: December 21, 2010, 12:09:28 pm by shafri »
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Feanor

  • Regular Contributor
  • *
  • Posts: 56
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #10 on: December 21, 2010, 12:34:25 pm »
I think I have a PIC16F722. If you send some MPLAB project to me I could test it and debug it with my Pickit2.

I do not have your email address. I have attached a zip file with a full project that displays some numbers on the 8 seven segment displays and uses the ADC.

In program only mode this program runs, segments light up and all. I have not tested it much and am not sure if the ADC is working yet, etc. I only did this tonight.

In debug mode it does not run at all. Segments do not light up, oscillator frequency does not change, all pins are input tristated.

I think I will be able to complete the project without debug mode. I will just have to debug the old fashioned way with a meter and an oscilloscope. 

Nice tutorials on your web page by the way!
 

Offline Feanor

  • Regular Contributor
  • *
  • Posts: 56
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #11 on: December 21, 2010, 12:36:52 pm »
try to power from pickit/icd without internal Vsupply, see if any problem. if no problem, then i think its in the internal supply circuit. i see your icsp connection is straight forward, except in the int. V and icd V meet up, sorry i'm no expert on that :P


I have tried power from both ICD and from the power supply shown in the schematic there is no real change.
 

Offline scrat

  • Frequent Contributor
  • **
  • Posts: 608
  • Country: it
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #12 on: December 21, 2010, 01:40:03 pm »
Could you please post a screenshot of the configuration bits settings window, after setting these settings as the active ones (unchecking "Configuration bits set in code")?
One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man. - Elbert Hubbard
 

Offline migsantiago

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: 00
    • MigSantiago's Web Site
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #13 on: December 21, 2010, 01:51:56 pm »
I do not have your email address. I have attached a zip file with a full project that displays some numbers on the 8 seven segment displays and uses the ADC.

...

Nice tutorials on your web page by the way!

OK, I got your file. I'm testing it today or tomorrow.

Thanks for visiting my site.  ;D
 

Offline Feanor

  • Regular Contributor
  • *
  • Posts: 56
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #14 on: December 22, 2010, 06:37:18 am »
Could you please post a screenshot of the configuration bits settings window, after setting these settings as the active ones (unchecking "Configuration bits set in code")?
Sure, this error does not come up often but I was lucky enough to catch it this time. Most of the time the program/verify is successful but there is no evidence of the program actually running.
 

Offline Feanor

  • Regular Contributor
  • *
  • Posts: 56
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #15 on: December 22, 2010, 06:47:31 am »
OK, I got your file. I'm testing it today or tomorrow.

Thanks for visiting my site.  ;D

I can not thank you enough. I have completely run out of ideas no apart from desolder everything and start again. I have begun the project just using program only and debugging manually. To help you test I have attached a screen shot of PIN6 that is RA4. I got this screen shot by using program only mode.
 

Offline migsantiago

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: 00
    • MigSantiago's Web Site
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #16 on: December 22, 2010, 02:54:02 pm »
I looked in my PIC stash and I just found a PIC16LF727, which is a PIC16F722's cousin. At first, I just wrongly selected PIC16F727 on the device selection. The pickit2 couldn't enter debug mode (unexpected devide id).

Than I switched to PIC16LF727 and voila! the PIC was detected.

Quote
Initializing PICkit 2 version 0.0.3.63
Found PICkit 2 - Operating System Version 2.32.0
PICkit 2 Unit ID = MigSantiago XD
Target power not detected - Powering from PICkit 2 ( 3.30V)
PIC16LF727 found (Rev 0x7)
PICkit 2 Ready

But when I tried to debug it, this happened...

Quote
Resetting
Programming Target (22/12/2010  08:25:27 a.m.)
PIC16LF727 found (Rev 0x7)
Erasing Target
Programming Program Memory (0x0 - 0x1D7)
Verifying Program Memory (0x0 - 0x1D7)
Programming Debug Executive (0x-1F00 - 0x1FFF)
Verifying Debug Executive (0x1F00 - 0x1FFF)
Programming Debug Vector
Verifying Debug Vector
Programming Configuration Memory
Verifying Configuration Memory
PK2Error0028:  Unable to enter debug mode
PICkit 2 Ready

Running Target
PICkit 2 Ready

I kept looking for errors or misconfigurations but found nothing. The Pickit2 could not debug the PIC16LF727. It even crashed MPLAB.

Make sure that the PIC can actually work with the internal oscillator while working at 5V or 3.3V. I also added some config bits...

Code: [Select]
#include "pic16f72x.h"

__CONFIG(INTIO & WDTDIS & MCLREN & PWRTDIS & BORDIS & UNPROTECT & PLLEN);

Sorry man, it seems that you will need to ask from the experts help, the Microchip support team.

Try debugging the PIC using an external crystal and not the internal oscillator.
« Last Edit: December 23, 2010, 03:22:56 am by migsantiago »
 

Offline Feanor

  • Regular Contributor
  • *
  • Posts: 56
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #17 on: December 23, 2010, 11:26:03 am »
Thank you so much for all the help. I am continually amazed by the kindness of people on this forum, not least migsantiago.

I am onto the Microchip support now, I will let you know what I do to fix it if it is eventually fixed.

Ciao.
 

Offline migsantiago

  • Frequent Contributor
  • **
  • Posts: 381
  • Country: 00
    • MigSantiago's Web Site
Re: PIC16F722 programing troubles especialy for debug mode
« Reply #18 on: December 23, 2010, 03:13:07 pm »
Good luck man. I'm also interested in what they say.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf