Microchip PIC18 not having an error programming

Discussion in 'Embedded Systems and Microcontrollers' started by aterhune1984, Feb 7, 2011.

  1. aterhune1984

    Thread Starter New Member

    Nov 24, 2010
    25
    0
    Hello all,
    I am trying to program a Microchip and all connections seem to be connected correctly. I have a 4.7KOhm resistor to pull up MCLR, VPP, VSS, as well as PGC and PGD connected. There is also a 1Uf cap connected between VPP and Ground. When programming I recieve the message

    "Device ID Revision = 00000007

    Programming...
    The following memory regions failed to program correctly:
    Program Memory
    Address: 00000000 Expected Value: 000000a5 Received Value: 000000ff
    Programming failed"

    My code is as follows, This builds with no errors or warnings but just does not program, The PIC is a Pic18F1320 and I get the same message regardless of being powered from 3V from the circuit or 5V from the pickit3 express.
    <code>

    #include <p18f1320.h>
    #include <usart.h>
    #include <delays.h>
    #include <stdlib.h>
    #include <adc.h>

    //PROTOTYPES
    void serial(void);
    void openusart(void);
    void oscillator(void);
    char * itoa( int value, char * string );
    void OpenUSART( unsigned char config,
    unsigned int spbrg);
    void openadc(void);
    void ConvertADC( void );
    char BusyADC( void );
    int ReadADC( void );
    //PROTOTYPES

    //Configuration bits--------------------
    #pragma config OSC = INTIO2, FSCM = OFF
    #pragma config PWRT = OFF, BOR = OFF
    #pragma config WDT = OFF
    #pragma config MCLRE = OFF
    #pragma config STVR = OFF, LVP = OFF, DEBUG = OFF
    #pragma config CP0 = OFF, CP1 = OFF
    #pragma config CPB = OFF, CPD = OFF
    #pragma config WRT0 = OFF, WRT1 = OFF
    #pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF
    #pragma config EBTR0 = OFF, EBTR1 = OFF
    #pragma config EBTRB = OFF
    //End Configuration bits----------------

    void openusart(){
    // Start configuration of USART
    OpenUSART( USART_TX_INT_OFF & //CONFIGURE USART
    USART_RX_INT_OFF &
    USART_ASYNCH_MODE &
    USART_EIGHT_BIT &
    USART_CONT_RX &
    USART_BRGH_HIGH, 8);
    // End configuration of Usart
    ADCON1bits.PCFG5 = 1;
    ADCON1bits.PCFG6 = 1;
    }

    void openadc(){
    ADCON1=0b01100011;
    ADCON2=0b10001001;
    }

    void oscillator(){
    OSCCON = 0b01110000;
    }

    //variable definitions
    char time[8];
    char printresulty[8];
    char printresultx[8];
    char printresultz[8];
    int resulty;
    int resultx;
    int resultz;
    //end variable definitions

    //START MAIN CODE-----------------------
    void main(){
    oscillator(); // call oscillator config
    openusart(); // call usart config
    openadc(); // call adc config
    while(1){

    //ADConversion start
    ADCON0=0b00010001;
    Delay10TCYx(4);
    ConvertADC();
    while( BusyADC() );
    resulty = ReadADC();
    //ADConversion end

    //ADConversion start
    ADCON0=0b00001101;
    Delay10TCYx(4);
    ConvertADC();
    while( BusyADC() );
    resultx = ReadADC();
    //ADConversion end

    //ADConversion start
    ADCON0=0b00001001;
    Delay10TCYx(4);
    ConvertADC();
    while( BusyADC() );
    resultz = ReadADC();
    //ADConversion end

    //Convert values to something I can display in Hyperterminal
    itoa (resulty,printresulty);
    itoa (resultx,printresultx);
    itoa (resultz,printresultz);
    //end Convert values to something I can display in Hyperterminal

    //Start Spitting out data in Hyperterminal
    putrsUSART((const rom far char *)"Y = ");
    putsUSART(printresulty);
    putrsUSART((const rom far char *)", X = ");
    putsUSART(printresultx);
    putrsUSART((const rom far char *)", Z = ");
    putsUSART(printresultz);
    putrsUSART((const rom far char *)"\n\r");
    Delay10KTCYx(10);
    //End Spitting out data in Hyperterminal
    }
    //End MAIN CODE
    }
    </code>

    Thanks so much, I have build several tries and all recieve this same message so hopefully its something in the code or something I am doing wrong.
     
  2. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    I have never used pickit3 express but the programming of microchip's mcu is almost same for all programmer i.e...
    In microchip's mcu ,the VPP is for the high voltage programming and its the MCLR pin (Master clear) normally we dont pull up the mclr at programming time we supply the VPP (high programming voltage),Vdd is the power supply pin and Vss is for ground and at programming time we apply the clock signal to PGC pin and the data signal to PGD pin.Now their is also an another way for programming avaliable only in some new device i.e.. low voltage programming here we dont have to put the Vpp (high voltage) to MCLR we just pull up it to Vdd supply line (I use 10K) but the problem is that this feature is only avaliable if the device's LVP (Low Voltage Programming) config bit is on if it is not on you have to use the high voltage programming process.The high voltage programming process is always available either the LVP bit is on or not.

    One more thing when posting code add tags like this "
    Code ( (Unknown Language)):
    1.  your code here [\code]"
    2.  
    3. Good Luck
     
    Last edited: Feb 7, 2011
  3. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Sounds similar to the error I get with the PICKIT2 when it isn't connected up properly. Try without the capacitor and resistor and recheck all connections. I'd just power from the PICKIT .
     
  4. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    My Junebug kit www.blueroomelectronics.com schematic shows a PK2 clone to 18F1320 in its manual.

    As stated in the previous message, it's either not connected properly, you've got something on RB6 or RB7, poor contact (breadboards are not that reliable), long programming wires (keep em short 5" or so) or a duff PIC.

    Posting a schematic or photo of your setup would be helpful.
     
  5. aterhune1984

    Thread Starter New Member

    Nov 24, 2010
    25
    0
    So the junebug thing is useful. I am doing this surface mount so I am using a 18F1320 QFN and the other 20 pin package, I have tried several methods of soldering. Is there a way to tell if the chip is fried from the heat of soldering? Would this give me that message too? I will post a pic of the circuit(schematic) when I get home, wont be until later tonight but that's what I am facing so far. I just need to get it consistently programming because this will be a non-serviceable and re-programmable part eventually.
     
  6. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    Yes the Junebug is useful :) The PK2 has a diagnostic mode, not sure if the PK3 offers the same thing.

    PICs are really robust and not so easy to kill. QFN can be tricky to solder.
     
  7. aterhune1984

    Thread Starter New Member

    Nov 24, 2010
    25
    0
    Alright, All I have tried is still not working. I am running out of parts to fry... Since these are all SMT parts its difficult to test. I can program the 18F1220 DIP on a breadboard just fine but cant do the 18F1320 SMT part which is basically the same part with more memory. Please take a look and see if you can find something I am doing wrong... Thanks
     
  8. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    You need to hook up the analog VSS & VDD even if you don't use em.
     
  9. aterhune1984

    Thread Starter New Member

    Nov 24, 2010
    25
    0
    Alright, I made the change, I will not get to test it until tomorrow but I will be sure to let you know. Hopefully this will work, I was about at the end of my rope.
     
  10. aterhune1984

    Thread Starter New Member

    Nov 24, 2010
    25
    0
    Quick question... I wanted to ask Why AVDD and AVSS need to be connected even if I'm not using them? I do not see any references to this in the datasheet... just for future reference...
     
  11. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,887
    1,012
    Why did you start with surface mount when you were not certain how everything is hooked up? Seems a heck of a lot easier to breadboard a through hole and work out the bugs first. Just curious.
     
  12. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    All VDD & VSS need to be connected, just think of it as a rule rather than exception. Did it work?
     
  13. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    AVDD and AVSS are there for the ADC only don't have any thing to do with the chips power supply but you can't leave them floating. And it's in the data sheet
     
  14. aterhune1984

    Thread Starter New Member

    Nov 24, 2010
    25
    0
    I did breadboard the whole thing months ago but the only thing is the version of the chip that works on a breadboard has avss and avdd connected to vss and vdd instead of separate pins on the surface mount parts. Would have been nice if I had known that I needed to connect them but at least I know now...
     
  15. aterhune1984

    Thread Starter New Member

    Nov 24, 2010
    25
    0
    That was the problem. Just wanted to give an update to all that helped me. I am now able to successfully program the chip.. .. Thanks blueroomelectronics!
     
Loading...