• AVR Freaks

PICKit2 and PIC18F452

Author
jsluke
Starting Member
  • Total Posts : 69
  • Reward points : 0
  • Joined: 2010/11/05 09:24:51
  • Location: 0
  • Status: offline
2010/12/27 03:34:58 (permalink)
0

PICKit2 and PIC18F452


I am implementing a simple chasing LEDs application using PIC18F452, PICKit 2 and MPLAB IDE v8.35 and when I try to program the device (Debugger->Program) I get a PK2Error0027.

I have attached my wiring diagram.

My code is =>

#include <p18cxxx.h>

void delay_ms(unsigned int duration);

void main()
{
    unsigned char J=1;
    while (1) {
        LATC=J;
        delay_ms(500);
        J=J<<1;
        if (J==0) {
            J=1;
        }
    }
}

void delay_ms(unsigned int duration) // delay in miliseconds for 4.0MHZ crystal
{
    unsigned int i;
    for(;duration!=0;duration--)
    {
        for(i=0;i<=50;i++)
        {
            _asm
                nop
                nop
                nop
            _endasm
        }
        _asm
            nop
            nop
        _endasm
    }
}
When I try to program the device I get the following error =>

Initializing PICkit 2 version 0.0.3.63
Found PICkit 2 - Operating System Version 2.32.0
Target power not detected - Powering from PICkit 2 ( 3.60V)
PIC18F452 found (c0)
PICkit 2 Ready

Programming Target (27/12/2010  09:54:58)
PIC18F452 found (c0)
Erasing Target
Programming Program Memory (0x0 - 0x19F)
Verifying Program Memory (0x0 - 0x19F)
PK2Error0027:  Failed verify (Address = 0x7C - Expected Value 0x20DA - Value Read 0xE0E)
PICkit 2 Ready
I tried to program the device again (after taking a few minutes to type up this post) without making any changes and this time I get a different error =>

Programming Target (27/12/2010  10:25:31)
PIC18F452 found (c0)
Erasing Target
Programming Program Memory (0x0 - 0x19F)
Verifying Program Memory (0x0 - 0x19F)
Programming Debug Executive (0x-7DC0 - 0x7FFF)
Verifying Debug Executive (0x7DC0 - 0x7FFF)
Programming Debug Vector
Verifying Debug Vector
Programming Configuration Memory
Verifying Configuration Memory
PK2Error0028:  Unable to enter debug mode
PICkit 2 Ready
Any suggestions?

Thanks.

James.

Attached Image(s)

#1

12 Replies Related Threads

    Ian.M
    Super Member
    • Total Posts : 13272
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re:PICKit2 and PIC18F452 2010/12/27 04:05:46 (permalink)
    0
    Yes.  See the help file for that error:

    PK2Error0027: Failed verify (Address - Expected Value - Value Read)

    Description: A verify operation failed. The error message specifies the memory type and address involved, and gives the expected value and the value actually read. A verify operation on a previously programmed and code protected part will fail, as the code protection feature returns all zeroes when the memory is read.
    Note: PICkit 2 Debug Express will terminate the verify operation upon the first incorrect value read from the target. Only this first incorrect value will be reported. There may be others.
    Suggested Actions: Ensure the device is not code protected. Check the ICSP connections as described in Using In-Circuit Serial Programming (ICSP). If the target device has AVdd and AVss pins, check that these are properly connected. Verify that PIC18FXXJXX, PIC24X, and dsPIC33F devices have an appropriate capacitance on the Vddcore/Vcap pin in accordance with the device data sheet. Some PIC18F devices may require up to 10 uF of capacitance on the Vdd pin to program properly.
    I don't see *ANY* decoupling capacitors in your circuit - Add 0.1uF ceramic across each Vss/Vdd pin pair right next to the chip and a 10uF electrolytic from Vdd to Vss anywhere convenient on your board then try again in PROGRAMMER (not debugger mode) with a full chip erase first. If that works, return to debugger mode and retry what you did above.


    post edited by Ian.M - 2010/12/27 04:13:05
    #2
    Stefan Uhlemayr
    Super Member
    • Total Posts : 4292
    • Reward points : 0
    • Joined: 2005/05/12 12:25:46
    • Location: Germany
    • Status: offline
    Re:PICKit2 and PIC18F452 2010/12/27 04:08:38 (permalink)
    0
    jsluke

    Any suggestions?
    Yes - connect all the supply-pins of your PIC to the appropriate voltage-level and place a 0.1uF ceramic capacitor close to each vdd/vss-pair.

    Hope this helps,Smile
    Stefan
    #3
    Stefan Uhlemayr
    Super Member
    • Total Posts : 4292
    • Reward points : 0
    • Joined: 2005/05/12 12:25:46
    • Location: Germany
    • Status: offline
    Re:PICKit2 and PIC18F452 2010/12/27 04:28:52 (permalink)
    0
    Some more things:

    1) Your code (accessing LATC) is not according to your schematic (LED's on PORTA).
    2) You haven't configured the output-port, so all the pins are still in input-mode.
    3) You haven't posted your PIC-configuration, and as a general rule: ALWAYS do it in your code, not via the MPLAB-menu
    4) Never leave unconnected pins floating - at least configure them as outputs on the PIC-startup
    5) You may put a pulldown-resistor to the "PGM"-pin (pin 38) - it may not hurt...Smile

    Greetings,
    Stefan
    post edited by Stefan Uhlemayr - 2010/12/27 04:29:54
    #4
    jsluke
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2010/11/05 09:24:51
    • Location: 0
    • Status: offline
    Re:PICKit2 and PIC18F452 2010/12/27 06:15:55 (permalink)
    0
    Thanks Ian (& thanks Stefan)

    I have attached a modified wiring diagram.  Is this now correct?

    For info, I previously had this working using the PIC18F14K50 but decided to move to the PIC18F452 so that I could work through the projects in this book => Advanced PIC Microcontroller Projects in C.

    James.

    Attached Image(s)

    #5
    Ian.M
    Super Member
    • Total Posts : 13272
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re:PICKit2 and PIC18F452 2010/12/27 07:52:52 (permalink)
    0
    Fix Stefan's point 5 and you should be OK.  If the PGM pin is left floating, it tends to drift high during programming, and this tends to interrupt programming and give errors similar to the one you had.   As you are using a PICkit 2 you could juct connect it to PK2 pin 6 (AUX) but personally I'd put a 10K pull-down on it.  Once LVP is disabled, it cant cause a problem, but as programming usually starts with a bulk erase that re-enables LVP and the CONFIG doesn't get rewritten till near the end, you cant leave it floating while programming with any expectation of reliability.

    Also consider the PIC18F4520.  Its mostly upwards compatible with the '452  but will be about 30% cheaper and has a lot of new nice features. [Here] is the migration document.
    #6
    jsluke
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2010/11/05 09:24:51
    • Location: 0
    • Status: offline
    Re:PICKit2 and PIC18F452 2010/12/27 08:00:47 (permalink)
    0
    Thanks Ian

    I put in a 10K pull down resistor on pin 38 and fixed the coding issues identified by Stefan.

    It's now working fine.

    Thanks to both of you for your help.

    James.
    #7
    jsluke
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2010/11/05 09:24:51
    • Location: 0
    • Status: offline
    Re:PICKit2 and PIC18F452 2011/01/12 02:54:59 (permalink)
    0
    Ian

    I've now run into a separate issue with the PIC18F452 that is being discussed in a separate thread.  I'm finding it almost impossible to integrate an SD Card for data storage.  I've been working with the Microchip libraries (FSIO, SD-SPI, etc) and it's just a nightmare.

    I'm now thinking that I need to switch chips (again) to one of the chips covered in the out of the box demo.  The prime candidate is the PIC18F46J50 as I've already worked with that chip using the PIC18 Starter Kit.

    My problem is that the PIC18F46J50 is supplied in surface mount packaging and I'm still at an early stage of product development.  I need a chip that I can breadboard with.  I need to integrate accelerometers, a GPS module, two gyros and an SD Card.  I also need to fit my finished prototype into a particular case.

    I've just discovered the PIC18F46J50 FS USB Demo Board.

    Is this demo board something that I could practically integrate onto a breadboard and wire up my other components (e.g. the GPS, gyros, SD Card, etc)?  Obviously, after breadboarding I need to build a prototype PCB and after that I would like to implement 10 prototypes for testing.

    Thanks.

    James.
    #8
    Ian.M
    Super Member
    • Total Posts : 13272
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re:PICKit2 and PIC18F452 2011/01/12 07:10:21 (permalink)
    0
    I wouldn't call that module breadboard friendly at all.  Close inspection of this photo:

    with close attention to the silk screen box round the ICSP header which we know is approx 0.6" long and a count of the PIM's target board connector pins adjacent to it, give me 12 pins in 0.6" or 0.05" spacing.  0.05" spacing pins in a square are NOT breadboard friendly. sad
    #9
    jsluke
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2010/11/05 09:24:51
    • Location: 0
    • Status: offline
    Re:PICKit2 and PIC18F452 2011/01/12 07:36:46 (permalink)
    0
    Yes - I hadn't done the maths but I had looked at the photo and was concerned.

    Any ideas on any products that would allow me to breadboard the 18F46J50?

    Thanks.

    James.
    #10
    Ian.M
    Super Member
    • Total Posts : 13272
    • Reward points : 0
    • Joined: 2009/07/23 07:02:40
    • Location: UK
    • Status: offline
    Re:PICKit2 and PIC18F452 2011/01/12 10:19:18 (permalink)
    0
    Look at the 28 pin DIP PIC18F26J50 - Same core, same FLASH and RAM, most of the same peripherals so really easy to port the code to.

    Alternatively if you get the 0.8mm pitch 44 pin TQFP package and one of these:

    From [HERE]* or similar from a number of other suppliers, you can breadboard that part.

    *I have never used this particular supplier . . .

    #11
    jsluke
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2010/11/05 09:24:51
    • Location: 0
    • Status: offline
    Re:PICKit2 and PIC18F452 2011/01/12 13:29:30 (permalink)
    0
    Thanks Ian - I've ordered the PIC18F26J50 and will give that a try.

    James.
    #12
    jsluke
    Starting Member
    • Total Posts : 69
    • Reward points : 0
    • Joined: 2010/11/05 09:24:51
    • Location: 0
    • Status: offline
    Re:PICKit2 and PIC18F452 2011/01/27 14:48:25 (permalink)
    0
    Ian

    I've been working with the PIC18F26J50 for quite a few days now but have run into a dead end.  Basically, I'm using code from the Starter Kit with a slight modification (hardware profile) to cover the 18F26J50 instead of the 18F46J50.  I was wondering if you could take a quick look at this thread and make any suggestions => ( http://www.microchip.com/forums/tm.aspx?tree=true&m=548114 ).

    The last couple of posts cover the port from the 18F46J50 to the 18F26J50.

    Thanks.

    James.
    #13
    Jump to:
    © 2020 APG vNext Commercial Version 4.5