PIC16F722 programing troubles especialy for debug mode - Page 1
Forum section: electronics / beginners

author: Feanor
author_rank: Regular Contributor
timestamp: December 16, 2010, 12:26:23 pm
content: 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 ExecutiveProgramming failedI 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=outputTRISB = 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.

author: migsantiago
author_rank: Frequent Contributor
timestamp: December 16, 2010, 02:41:21 pm
content: Hey thereWhen 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.).

author: Feanor
author_rank: Regular Contributor
timestamp: December 18, 2010, 05:01:31 am
content: 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?

author: Mechatrommer
author_rank: Super Contributor
timestamp: December 18, 2010, 01:00:10 pm
content: pls post your schematics, i will analyze it, i'm an expert on this

author: migsantiago
author_rank: Frequent Contributor
timestamp: December 18, 2010, 02:14:41 pm
content: An schematic rather than a soldered board would be easier to review.

author: Feanor
author_rank: Regular Contributor
timestamp: December 19, 2010, 03:58:19 am
content: 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.

author: migsantiago
author_rank: Frequent Contributor
timestamp: December 19, 2010, 03:02:44 pm
content: 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 programmedwith or withoutusing an ICD header (RJ11).

author: Feanor
author_rank: Regular Contributor
timestamp: December 20, 2010, 09:35:31 am
content: 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.

author: migsantiago
author_rank: Frequent Contributor
timestamp: December 20, 2010, 02:57:53 pm
content: I think I have a PIC16F722. If you send some MPLAB project to me I could test it and debug it with my Pickit2.

author: Mechatrommer
author_rank: Super Contributor
timestamp: December 21, 2010, 11:49:34 am
content: 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

author: Feanor
author_rank: Regular Contributor
timestamp: December 21, 2010, 12:34:25 pm
content: Quote from: migsantiago on December 20, 2010, 02:57:53 pmI 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!

author: Feanor
author_rank: Regular Contributor
timestamp: December 21, 2010, 12:36:52 pm
content: Quote from: shafri on December 21, 2010, 11:49:34 amI have tried power from both ICD and from the power supply shown in the schematic there is no real change.

author: scrat
author_rank: Frequent Contributor
timestamp: December 21, 2010, 01:40:03 pm
content: 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")?

author: migsantiago
author_rank: Frequent Contributor
timestamp: December 21, 2010, 01:51:56 pm
content: Quote from: Feanor on December 21, 2010, 12:34:25 pmOK, I got your file. I'm testing it today or tomorrow.Thanks for visiting my site.

author: Feanor
author_rank: Regular Contributor
timestamp: December 22, 2010, 06:37:18 am
content: Quote from: scrat on December 21, 2010, 01:40:03 pmSure, 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.

author: Feanor
author_rank: Regular Contributor
timestamp: December 22, 2010, 06:47:31 am
content: Quote from: migsantiago on December 21, 2010, 01:51:56 pmI 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.

author: migsantiago
author_rank: Frequent Contributor
timestamp: December 22, 2010, 02:54:02 pm
content: 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.QuoteBut when I tried to debug it, this happened...QuoteI 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:#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.

author: Feanor
author_rank: Regular Contributor
timestamp: December 23, 2010, 11:26:03 am
content: 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.

author: migsantiago
author_rank: Frequent Contributor
timestamp: December 23, 2010, 03:13:07 pm
content: Good luck man. I'm also interested in what they say.