Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ICD2 and PIC18F2550 issue

Status
Not open for further replies.

Iuri

Member level 2
Joined
May 14, 2011
Messages
50
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,288
Activity points
1,630
I'm newby at PIC programming, actually this is my first time with him, and I have a issue.

I'm using ICD2, MPLAB IDE with C18 Compiler and PIC18F2550 just to toggle one led on/off (classic hello world application).

Below is my current schematic, the circuitry is mounted in a breadboard and the power is supplied by the ICD2.

schematic.png

This is my current code:

#include <p18f2550.h>

#pragma config FOSC = INTOSC_XT
#pragma config WDT = OFF

void main()
{
int delay;
TRISC = 0x00;

while (1)
{
PORTC = 0xff;

for (delay = 0; delay < 32000; delay++);

PORTC = 0x00;

for (delay = 0; delay < 32000; delay++);
}
}

This is what is happening...

When I set in MPLAB Programmer>Program everything seems good:

Programming Target...
...Validating configuration fields
...Erasing Part
...Programming Program Memory (0x0 - 0x17F)
Verifying...
...Program Memory
...Verify Succeeded
Programming Configuration Bits
.. Config Memory
Verifying configuration memory...
...Verify Succeeded
...Programming succeeded
05-Jan-2012, 22:30:21

MPLAB ICD 2 ready for next operation

And then I press "Release from Reset" and nothing happens. :sad:

If I try to Program in Debug mode the response is even worst. :cry:

Resetting Target
MPLAB ICD 2 ready for next operation
Programming Target...
...Validating configuration fields
...Erasing Part
...Programming Program Memory (0x0 - 0x17F)
...Loading DebugExecutive
...Programming DebugExecutive
...Programming Debug Vector
...Programming RSBUG
Verifying...
...Program Memory
...Debug Executive
...Debug Vector
...Verify Succeeded
Programming Configuration Bits
.. Config Memory
Verifying configuration memory...
...Verify Succeeded
Connecting to debug executive
ICD0083: Debug: Unable to enter debug mode. Please double click this message for more information.
MPLAB ICD 2 ready for next operation

I spend +6 hours, read alot of information, triple checked the connections and still the same thing.

Please if you know how to fix it help me!

Thanks you all.

Iuri~
 

You need to disable LVP.

Try adding this extra config line:

Code:
#pragma config LVP = OFF                 // disable Low Voltage Programming
 

You need to disable LVP.

Try adding this extra config line:

Code:
#pragma config LVP = OFF                 // disable Low Voltage Programming

Still the same for both situations ( Debug/Program ).
 

Ah.... looked at your diagram more closely and have just noticed that your LED is on RC4 (USB-). That might be a problem, as if memory serves, USB pins can only be configured as input.

EDIT: Checked the datasheet and sure enough, section 10.3 contains the sentance:

Unlike other PORTC pins, RC4 and RC5 do not have
TRISC bits associated with them. As digital ports, they
can only function as digital inputs.
You will need to move your LED to a non-USB pin.

---------- Post added at 01:39 ---------- Previous post was at 01:11 ----------

There is another problem with your schematic:

Vusb should have a 0.47uF ceramic capacitor connected, with the other side of the capacitor going to Vss. I seem to remember that the capacitor needs to be there even if you are not using USB.
 
Last edited:

I wasn't notated.. the led is blinking but very weak even if I drop half value of resistor, maybe when him is turned on somehow the mcu reset, don't know why

I put the capacitor and still the same and the debug still doesn't working.

Thank you.

Iuri~
 

Which pin is your LED connected to now?

What is your PIC supply voltage?
 

oh man... I figured out why the led brightness is so weak! one 4Mhz xtal was connected into mcu, I just disconnect him and the led brightness back to expected.

using RB4 (pin 25) at this moment.

My problem now is in debug mode.. it do not want to work at all!

thank you again!

---------- Post added at 00:11 ---------- Previous post was at 00:10 ----------

5v, supplied by ICD2 board (USB).
 

I think that you need to connect external power to ICD2 (or the target board). I don't think USB power does the job.

Check ICD2 documentation to be sure.
 

strange... in MPLAB ICD2 Setup Wizard they allow me to set "power from ICD2" even in debug mode. I'll check the documentation for sure, actually this should have been done sice the beginning.
A simply 5v regulator will ensure if that's the problem. I will come with result.

thank you!

Iuri~
 

... and if you are going to use PORTB, you would be wise to add this config statement:

Code:
#pragma config PBADEN = OFF             // disable PORTB a/d converter

You should use LAT register for PIC18 output, use PORT register only for input.

Here is how I think your code should be written:

Code:
// simple LED flashing exercise

#include <p18f2550.h>

#pragma config FOSC = INTOSC_XT         // internal oscillator for CPU
#pragma config WDT = OFF                // disable watchdog timer
#pragma config LVP = OFF                // LVP MUST be off
#pragma config BOR = OFF                // no brown out reset
#pragma config MCLRE = ON               // MCLR in use (so 10k to +5v essential)
#pragma config PWRT = ON                // power up timer on
#pragma config PBADEN = OFF             // disable PORTB a/d converter

void main()
{
int delay;

    TRISB = 0x00;                       // all output
    TRISC = 0x00;                       // 0,1,2,6,7 output (RC3, 4, 5 used by USB)
    
    while (1)
    {
        LATB = 0xff;                    // LEDs on
        LATC = 0xff;                    // LEDs 0,1,2,6,7 on
        
        for (delay = 0; delay < 32000; delay++);    // delay about 2 seconds to allow user to see LED lit
        
        LATB = 0x00;                    // LEDs off
        LATC = 0x00;                    // LEDs off
        
        for (delay = 0; delay < 32000; delay++);    // delay about 2 seconds to allow user to see LED off 
    }
}
 
Last edited:

PBADEN = OFF already done.. thanks for the tips!

I build the regulator ( 7805 ) and now I got this error when I try to connect the programmer

ICDWarn0020: Invalid target device id (expected=0x92, read=0x0)

and this if I try to program

ICDWarn0052: MPLAB ICD 2 cannot validate a target device. Please make sure that the target device is connected and properly powered. Select "OK" to continue, or "CANCEL" to abort the operation
 

Not a good sign ...

Can you get back to the situation you had before?

I must admit - I have never had much luck using target power. ICD2 seems much more reliable for me using a regulated 9V DC supply to the ICD2 "puck".

But then I always assumed that this was because I use a really old revision ICD2.

A restart of the PC seems to be needed regularly for me. Might be worth a try...
 

Vusb should have a 0.47uF ceramic capacitor connected, with the other side of the capacitor going to Vss. I seem to remember that the capacitor needs to be there even if you are not using USB.

Actually, that is not the case, if you do not indeed on implementing the USB interface, you can run the PIC18F2550 fine without the capacitor for Vusb.

I wasn't notated.. the led is blinking but very weak even if I drop half value of resistor, maybe when him is turned on somehow the mcu reset, don't know why

I put the capacitor and still the same and the debug still doesn't working.

I believe your problem maybe your Fosc, the PLL maybe enable by default, which means your are running the device at a much faster Fosc than you intend.

The weak glowing LED is sometimes an indication of a very fast blinking LED.

You maybe running a Fosc of 48MHz instead of 4MHz.

I recommend setting all the configuration bits related to the oscillator, disabling the PLL.

BigDog

---------- Post added at 04:32 ---------- Previous post was at 04:24 ----------

When I set in MPLAB Programmer>Program everything seems good:

And then I press "Release from Reset" and nothing happens. :sad:

Your posting of the programming of the device in programmer mode seems to indicate a successful programming of the flash, including a "Verify Succeeded."



If I try to Program in Debug mode the response is even worst. :cry:

When you switch from programmer to debugger mode, did you ensure the correct build configuration was selected.

Project -> Build Configuration -> Release (For Programmer Mode)

Project -> Build Configuration -> Debug (For Debugger Mode)

Without the debugger code, the ICD2 will issue an error like, "ICD0083: Debug: Unable to enter debug mode. Please double click this message for more information"

BigDog
 

I restarted the computer and checked the breadboard connections and works again ( with ICD2 supply ).

I believe your problem maybe your Fosc, the PLL maybe enable by default, which means your are running the device at a much faster Fosc than you intend.

The weak glowing LED is sometimes an indication of a very fast blinking LED.

You maybe running a Fosc of 48MHz instead of 4MHz.

I recommend setting all the configuration bits related to the oscillator, disabling the PLL.

At this moment I'm using the internal oscilator as MCLK and Programmer mode is woking good with ICD2 supply, will try it out later BigDog. I need to set the Debug mode up first!

When you switch from programmer to debugger mode, did you ensure the correct build configuration was selected.

Project -> Build Configuration -> Release (For Programmer Mode)

Project -> Build Configuration -> Debug (For Debugger Mode)

Without the debugger code, the ICD2 with issue an error like, "ICD0083: Debug: Unable to enter debug mode. Please double click this message for more information"

Yes, already done and nothing.
 

if you mean "Build All", yes.

---------- Post added at 02:19 ---------- Previous post was at 02:15 ----------

I moved to another computer with Windows XP, the the last one was Seven 64 bits, and remade some connections on breadboard and it works ( also in ICD2 supply )!

I'll teste with regulator again.

Thank you!

Iuri~

---------- Post added at 02:37 ---------- Previous post was at 02:19 ----------

It do not want to work with the regulator.

The manual of my ICD2 manufacturer tells me to connect Vdd from the ICD2 with Vcc from my power supply. Seems really weird to me, do you recomend this?

Iuri~
 
Last edited:

Good news guys, i pluged the Vdd from ICD2 with Vcc from my power supply and everything worked out!

Now i gonna design a development board for pic18F2550 so I can get deeper and better in the pic programming world

Thank you for your time!

Iuri~
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top