PIC18F4550 dont start

Thread Starter

Vindhyachal Takniki

Joined Nov 3, 2014
594
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.
C:
//#pragma config CONFIG1L = 0x0
__CONFIG(1, PLLDIV_1 & CPUDIV_OSC1_PLL2 & USBDIV_1);
//#pragma config CONFIG1H = 0x0
__CONFIG(2, FOSC_XT_XT & FCMEN_OFF & IESO_OFF);
//#pragma config CONFIG2L = 0x3E
__CONFIG(3, PWRT_ON & BOR_ON & BORV_3 & VREGEN_ON);
//#pragma config CONFIG2H = 0x1E
__CONFIG(4, WDT_OFF & WDTPS_32768);
//#pragma config CONFIG3H = 0x81
__CONFIG(5, CCP2MX_ON & PBADEN_OFF & LPT1OSC_OFF & MCLRE_ON);
//#pragma config CONFIG4L = 0x85
__CONFIG(6, STVREN_ON & LVP_ON & ICPRT_OFF & XINST_OFF);
//#pragma config CONFIG5L = 0x0
__CONFIG(7, CP0_ON & CP1_ON & CP2_ON & CP3_ON);
//#pragma config CONFIG5H = 0xC0
__CONFIG(8, CPB_OFF & CPD_OFF);
//#pragma config CONFIG6L = 0xF
__CONFIG(9, WRT0_OFF & WRT1_OFF & WRT2_OFF & WRT3_OFF);
//#pragma config CONFIG6H = 0xE0
__CONFIG(10, WRTC_OFF & WRTB_OFF & WRTD_OFF);
//#pragma config CONFIG7L = 0xF
__CONFIG(11, EBTR0_OFF & EBTR1_OFF & EBTR2_OFF & EBTR3_OFF);
//#pragma config CONFIG7H = 0x40
__CONFIG(12, EBTRB_OFF);
Case2: Internal 8Mhz osc
C:
//#pragma config CONFIG1L = 0x29
__CONFIG(1, PLLDIV_2 & CPUDIV_OSC2_PLL3 & USBDIV_2);
//#pragma config CONFIG1H = 0x89
__CONFIG(2, FOSC_INTOSC_EC & FCMEN_OFF & IESO_ON);
//#pragma config CONFIG2L = 0x3E
__CONFIG(3, PWRT_ON & BOR_ON & BORV_3 & VREGEN_ON);
//#pragma config CONFIG2H = 0x1E
__CONFIG(4, WDT_OFF & WDTPS_32768);
//#pragma config CONFIG3H = 0x81
__CONFIG(5, CCP2MX_ON & PBADEN_OFF & LPT1OSC_OFF & MCLRE_ON);
//#pragma config CONFIG4L = 0x85
__CONFIG(6, STVREN_ON & LVP_ON & ICPRT_OFF & XINST_OFF);
//#pragma config CONFIG5L = 0x0
__CONFIG(7, CP0_ON & CP1_ON & CP2_ON & CP3_ON);
//#pragma config CONFIG5H = 0xC0
__CONFIG(8, CPB_OFF & CPD_OFF);
//#pragma config CONFIG6L = 0xF
__CONFIG(9, WRT0_OFF & WRT1_OFF & WRT2_OFF & WRT3_OFF);
//#pragma config CONFIG6H = 0xE0
__CONFIG(10, WRTC_OFF & WRTB_OFF & WRTD_OFF);
//#pragma config CONFIG7L = 0xF
__CONFIG(11, EBTR0_OFF & EBTR1_OFF & EBTR2_OFF & EBTR3_OFF);
//#pragma config CONFIG7H = 0x40
__CONFIG(12, EBTRB_OFF);
Mod edit: fixed code tags.
 
Last edited by a moderator:

odm4286

Joined Sep 20, 2009
265
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.
 

ErnieM

Joined Apr 24, 2011
8,377
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.
 

JohnInTX

Joined Jun 26, 2012
4,787
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.
 

Thread Starter

Vindhyachal Takniki

Joined Nov 3, 2014
594
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:
Config setting for internal osc which is working, pin is toggling:

//#pragma config CONFIG1L = 0x29
__CONFIG(1, PLLDIV_2 & CPUDIV_OSC2_PLL3 & USBDIV_2);
//#pragma config CONFIG1H = 0x89
__CONFIG(2, FOSC_INTOSC_EC & FCMEN_OFF & IESO_ON);
//#pragma config CONFIG2L = 0x3E
__CONFIG(3, PWRT_ON & BOR_ON & BORV_3 & VREGEN_ON);
//#pragma config CONFIG2H = 0x1E
__CONFIG(4, WDT_OFF & WDTPS_32768);
//#pragma config CONFIG3H = 0x81
__CONFIG(5, CCP2MX_ON & PBADEN_OFF & LPT1OSC_OFF & MCLRE_ON);
//#pragma config CONFIG4L = 0x85
__CONFIG(6, STVREN_ON & LVP_OFF & ICPRT_OFF & XINST_OFF);
//#pragma config CONFIG5L = 0x0
//__CONFIG(7, CP0_ON & CP1_ON & CP2_ON & CP3_ON);
//#pragma config CONFIG5H = 0xC0
__CONFIG(8, CPB_OFF & CPD_OFF);
//#pragma config CONFIG6L = 0xF
__CONFIG(9, WRT0_OFF & WRT1_OFF & WRT2_OFF & WRT3_OFF);
//#pragma config CONFIG6H = 0xE0
__CONFIG(10, WRTC_OFF & WRTB_OFF & WRTD_OFF);
//#pragma config CONFIG7L = 0xF
__CONFIG(11, EBTR0_OFF & EBTR1_OFF & EBTR2_OFF & EBTR3_OFF);
//#pragma config CONFIG7H = 0x40
__CONFIG(12, EBTRB_OFF);















config setting for external 4Mhz osc, which is not working:

__CONFIG(1, PLLDIV_1 & CPUDIV_OSC1_PLL2 & USBDIV_2);
//#pragma config CONFIG1H = 0x0
__CONFIG(2, FOSC_XT_XT & FCMEN_OFF & IESO_OFF);
//#pragma config CONFIG2L = 0x3E
__CONFIG(3, PWRT_ON & BOR_ON & BORV_3 & VREGEN_ON);
//#pragma config CONFIG2H = 0x1E
__CONFIG(4, WDT_OFF & WDTPS_32768);
//#pragma config CONFIG3H = 0x81
__CONFIG(5, CCP2MX_ON & PBADEN_OFF & LPT1OSC_OFF & MCLRE_ON);
//#pragma config CONFIG4L = 0x81
__CONFIG(6, STVREN_ON & LVP_OFF & ICPRT_OFF & XINST_OFF);
//#pragma config CONFIG5L = 0xF
//__CONFIG(7, CP0_OFF & CP1_OFF & CP2_OFF & CP3_OFF);
//#pragma config CONFIG5H = 0xC0
__CONFIG(8, CPB_OFF & CPD_OFF);
//#pragma config CONFIG6L = 0xF
__CONFIG(9, WRT0_OFF & WRT1_OFF & WRT2_OFF & WRT3_OFF);
//#pragma config CONFIG6H = 0xE0
__CONFIG(10, WRTC_OFF & WRTB_OFF & WRTD_OFF);
//#pragma config CONFIG7L = 0xF
__CONFIG(11, EBTR0_OFF & EBTR1_OFF & EBTR2_OFF & EBTR3_OFF);
//#pragma config CONFIG7H = 0x40
__CONFIG(12, EBTRB_OFF);
 

Robin Mitchell

Joined Oct 25, 2009
819
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.
 
Top