PIC18F4550 dont start

Discussion in 'Embedded Systems and Microcontrollers' started by Vindhyachal Takniki, May 12, 2016.

  1. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    348
    6
    I have connected used PIC18F4550 in one of project. Problem is PIC never start up.
    In start of code in main function, i have toggled a pin continuously.
    I want my system freq to be of 4Mhz. There is no USB used. Using Hi-tech PICC18-PRO V9.80 with MPLABX.
    I think its configuration bits issues. Tried external osc & then internal osc but sysem never runs. Voltage at reset pin is +5V & vdd pin is +5V. Both vdd & Vss are connected.I have checked on CRO

    Programming in MCU is done by PICkit3 debugger & software programmer(Beta version) & software version 0.2.0.2

    Case1: 4Mhz crystal is connected with 22pF load caps.
    Code (C):
    1.  
    2. //#pragma config CONFIG1L = 0x0
    3. __CONFIG(1, PLLDIV_1 & CPUDIV_OSC1_PLL2 & USBDIV_1);
    4. //#pragma config CONFIG1H = 0x0
    5. __CONFIG(2, FOSC_XT_XT & FCMEN_OFF & IESO_OFF);
    6. //#pragma config CONFIG2L = 0x3E
    7. __CONFIG(3, PWRT_ON & BOR_ON & BORV_3 & VREGEN_ON);
    8. //#pragma config CONFIG2H = 0x1E
    9. __CONFIG(4, WDT_OFF & WDTPS_32768);
    10. //#pragma config CONFIG3H = 0x81
    11. __CONFIG(5, CCP2MX_ON & PBADEN_OFF & LPT1OSC_OFF & MCLRE_ON);
    12. //#pragma config CONFIG4L = 0x85
    13. __CONFIG(6, STVREN_ON & LVP_ON & ICPRT_OFF & XINST_OFF);
    14. //#pragma config CONFIG5L = 0x0
    15. __CONFIG(7, CP0_ON & CP1_ON & CP2_ON & CP3_ON);
    16. //#pragma config CONFIG5H = 0xC0
    17. __CONFIG(8, CPB_OFF & CPD_OFF);
    18. //#pragma config CONFIG6L = 0xF
    19. __CONFIG(9, WRT0_OFF & WRT1_OFF & WRT2_OFF & WRT3_OFF);
    20. //#pragma config CONFIG6H = 0xE0
    21. __CONFIG(10, WRTC_OFF & WRTB_OFF & WRTD_OFF);
    22. //#pragma config CONFIG7L = 0xF
    23. __CONFIG(11, EBTR0_OFF & EBTR1_OFF & EBTR2_OFF & EBTR3_OFF);
    24. //#pragma config CONFIG7H = 0x40
    25. __CONFIG(12, EBTRB_OFF);
    26.  
    Case2: Internal 8Mhz osc
    Code (C):
    1.  
    2. //#pragma config CONFIG1L = 0x29
    3. __CONFIG(1, PLLDIV_2 & CPUDIV_OSC2_PLL3 & USBDIV_2);
    4. //#pragma config CONFIG1H = 0x89
    5. __CONFIG(2, FOSC_INTOSC_EC & FCMEN_OFF & IESO_ON);
    6. //#pragma config CONFIG2L = 0x3E
    7. __CONFIG(3, PWRT_ON & BOR_ON & BORV_3 & VREGEN_ON);
    8. //#pragma config CONFIG2H = 0x1E
    9. __CONFIG(4, WDT_OFF & WDTPS_32768);
    10. //#pragma config CONFIG3H = 0x81
    11. __CONFIG(5, CCP2MX_ON & PBADEN_OFF & LPT1OSC_OFF & MCLRE_ON);
    12. //#pragma config CONFIG4L = 0x85
    13. __CONFIG(6, STVREN_ON & LVP_ON & ICPRT_OFF & XINST_OFF);
    14. //#pragma config CONFIG5L = 0x0
    15. __CONFIG(7, CP0_ON & CP1_ON & CP2_ON & CP3_ON);
    16. //#pragma config CONFIG5H = 0xC0
    17. __CONFIG(8, CPB_OFF & CPD_OFF);
    18. //#pragma config CONFIG6L = 0xF
    19. __CONFIG(9, WRT0_OFF & WRT1_OFF & WRT2_OFF & WRT3_OFF);
    20. //#pragma config CONFIG6H = 0xE0
    21. __CONFIG(10, WRTC_OFF & WRTB_OFF & WRTD_OFF);
    22. //#pragma config CONFIG7L = 0xF
    23. __CONFIG(11, EBTR0_OFF & EBTR1_OFF & EBTR2_OFF & EBTR3_OFF);
    24. //#pragma config CONFIG7H = 0x40
    25. __CONFIG(12, EBTRB_OFF);
    26.  
    Mod edit: fixed code tags.
     
    Last edited by a moderator: May 12, 2016
  2. odm4286

    Active Member

    Sep 20, 2009
    155
    5
    Really hard to troubleshoot this without a schematic. I'd double check your configuration bits and make sure you don't have it set where MCLR must be held high in order for the PIC to run.
     
  3. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    MCLR set hi is good no matter if you check it or not.

    I always start with the internal Oscar as a sanity check. You seem to have it set for an external resonator. I can't guide you as I don't have that compiler and setting config bits is highly pragmatic.

    Get to know fig 2-1 of the data sheet intimately and then the manual for your compiler.

    You may be able to upload your code into a fresh project and inspect what the config bits are actually set to in case you have a fowl up there.
     
  4. JohnInTX

    Moderator

    Jun 26, 2012
    2,340
    1,022
    Can you single-step through the code using the PK3 debugger? If so, you know that the oscillator is running and the PIC has started up.
    If not, for the resonator/XTAL configuration, scope the OSC pins to see if the clock is running or measure the voltage on the OSC pins with a DVM - it should be around 1/2 Vdd if the oscillator is running.

    Another way to know if the PIC comes up is to just initialize PORTD to be output 0 and reset the PIC. If the port goes from floating around to hard low, the PIC got at least that far.
     
  5. dannyf

    Well-Known Member

    Sep 13, 2015
    1,769
    358
    Go to a minimal configuration and turn as many fuses off as you can. And gl from there.
     
  6. Vindhyachal Takniki

    Thread Starter Member

    Nov 3, 2014
    348
    6
    I have tried below setting for internal oscillator & code was running. In mian code I have toggled a pin with certain delay.
    Although delay was not accurate. I think that because OSCCON is set to default.
    On single stepping into code by mplab I was able to debug code.

    But when I tried using 4Mhz external oscilltor again code not run.
    Below are setting fro external 4Mhz crystal. I have put DMM on OSC1 & OSC2 it comes out to arounf 2.1V.
    But I have put CRO probe across it there is no sine wave just dc across two.

    Code (Text):
    1. Config setting for internal osc which is working, pin is toggling:
    2.  
    3. //#pragma config CONFIG1L = 0x29
    4. __CONFIG(1, PLLDIV_2 & CPUDIV_OSC2_PLL3 & USBDIV_2);
    5. //#pragma config CONFIG1H = 0x89
    6. __CONFIG(2, FOSC_INTOSC_EC & FCMEN_OFF & IESO_ON);
    7. //#pragma config CONFIG2L = 0x3E
    8. __CONFIG(3, PWRT_ON & BOR_ON & BORV_3 & VREGEN_ON);
    9. //#pragma config CONFIG2H = 0x1E
    10. __CONFIG(4, WDT_OFF & WDTPS_32768);
    11. //#pragma config CONFIG3H = 0x81
    12. __CONFIG(5, CCP2MX_ON & PBADEN_OFF & LPT1OSC_OFF & MCLRE_ON);
    13. //#pragma config CONFIG4L = 0x85
    14. __CONFIG(6, STVREN_ON & LVP_OFF & ICPRT_OFF & XINST_OFF);
    15. //#pragma config CONFIG5L = 0x0
    16. //__CONFIG(7, CP0_ON & CP1_ON & CP2_ON & CP3_ON);
    17. //#pragma config CONFIG5H = 0xC0
    18. __CONFIG(8, CPB_OFF & CPD_OFF);
    19. //#pragma config CONFIG6L = 0xF
    20. __CONFIG(9, WRT0_OFF & WRT1_OFF & WRT2_OFF & WRT3_OFF);
    21. //#pragma config CONFIG6H = 0xE0
    22. __CONFIG(10, WRTC_OFF & WRTB_OFF & WRTD_OFF);
    23. //#pragma config CONFIG7L = 0xF
    24. __CONFIG(11, EBTR0_OFF & EBTR1_OFF & EBTR2_OFF & EBTR3_OFF);
    25. //#pragma config CONFIG7H = 0x40
    26. __CONFIG(12, EBTRB_OFF);
    27.  
    28.  
    29.  
    30.  
    31.  
    32.  
    33.  
    34.  
    35.  
    36.  
    37.  
    38.  
    39.  
    40.  
    41.  
    42. config setting for external 4Mhz osc, which is not working:
    43.  
    44. __CONFIG(1, PLLDIV_1 & CPUDIV_OSC1_PLL2 & USBDIV_2);
    45. //#pragma config CONFIG1H = 0x0
    46. __CONFIG(2, FOSC_XT_XT & FCMEN_OFF & IESO_OFF);
    47. //#pragma config CONFIG2L = 0x3E
    48. __CONFIG(3, PWRT_ON & BOR_ON & BORV_3 & VREGEN_ON);
    49. //#pragma config CONFIG2H = 0x1E
    50. __CONFIG(4, WDT_OFF & WDTPS_32768);
    51. //#pragma config CONFIG3H = 0x81
    52. __CONFIG(5, CCP2MX_ON & PBADEN_OFF & LPT1OSC_OFF & MCLRE_ON);
    53. //#pragma config CONFIG4L = 0x81
    54. __CONFIG(6, STVREN_ON & LVP_OFF & ICPRT_OFF & XINST_OFF);
    55. //#pragma config CONFIG5L = 0xF
    56. //__CONFIG(7, CP0_OFF & CP1_OFF & CP2_OFF & CP3_OFF);
    57. //#pragma config CONFIG5H = 0xC0
    58. __CONFIG(8, CPB_OFF & CPD_OFF);
    59. //#pragma config CONFIG6L = 0xF
    60. __CONFIG(9, WRT0_OFF & WRT1_OFF & WRT2_OFF & WRT3_OFF);
    61. //#pragma config CONFIG6H = 0xE0
    62. __CONFIG(10, WRTC_OFF & WRTB_OFF & WRTD_OFF);
    63. //#pragma config CONFIG7L = 0xF
    64. __CONFIG(11, EBTR0_OFF & EBTR1_OFF & EBTR2_OFF & EBTR3_OFF);
    65. //#pragma config CONFIG7H = 0x40
    66. __CONFIG(12, EBTRB_OFF);
     
  7. dannyf

    Well-Known Member

    Sep 13, 2015
    1,769
    358
    then post that configuration and change it to use a crystal.
     
  8. Robin Mitchell

    Well-Known Member

    Oct 25, 2009
    732
    199
    Do you have the correct capacitors on the external crystal oscillator? And while you may have the external source selected there are several options such as high speed, external clock input (not a crystal), and 32.768KHz oscillators.
     
Loading...