PIC 18F4550 48MHz Assistance

Status
Not open for further replies.

Micro9900

New Member
Hey guys, I'm trying to get an LED to turn on (and then blink) at 48MHz. I have it working fine at 8MHz, but when I use the settings I have listed below for 48MHz, it seems I cannot get the microcontroller to function properly. I am using a 20MHz resonator, but I also have a 20MHz crystal (it specifies 20pF, but I am using 22PF caps, if this is a problem please let me know), which doesn't work either. So, I'm not sure if it's a software or hardware issue.

Here is the layout (shown in the diagram, but note I am also trying a resonator, so I don't have caps hooked up and I have the middle pin grounded)

Here is the resonator I am using currently (20MHz): Link (I have the middle pin connected to ground and the other pins are going to OSC1 - Pin 13 and OSC2 - Pin 14 receptively).

Here is the crystal I have selected: Link

Here is my code (I'm using MPLAB with C18 LITE):

Code:
//turns watch dog timer off, turn low voltage programming off
#pragma config WDT=OFF, LVP=OFF, MCLRE = OFF

//oscillator configurations see pg. 25 /430 of pic18f4550 data sheet
      //#pragma config FOSC = INTOSCIO_EC // Internal oscillator, port function on RA6, EC used by USB (use if not op. at 48Mhz)
        #pragma config PBADEN = OFF 	  // Set RB4-RB0 to act as digital inputs/output
        #pragma config DEBUG=OFF		  // Background debugging disabled, RB6 and RB7 act as digital I/O

	#pragma config FOSC = HSPLL_HS	// Using 20 MHz crystal with PLL
	#pragma config PLLDIV = 5 		// Divide by 5 to provide the 96 MHz PLL with 4 MHz input
	#pragma config CPUDIV = OSC1_PLL2 // Divide 96 MHz PLL output by 2 to get 48 MHz system clock
	#pragma config USBDIV = 2 		// USB clock comes from 96 MHz PLL output / 2

	#pragma config FCMEN = OFF // Disable Fail-Safe Clock Monitor
	#pragma config IESO = OFF  // Disable Oscillator Switchover mode
	#pragma config PWRT = OFF  // Disable Power-up timer
	#pragma config BOR = OFF   // Disable Brown-out reset
	#pragma config VREGEN = ON // Use internal USB 3.3V voltage regulator
	#pragma config ICPRT = OFF // Disable dedicated programming port (44-pin devices)
	#pragma config CP0 = OFF   // Disable code protection


#include <p18f4550.h> // Uses Microchip's predefined library for 18F4550
#include <delays.h>	  // Uses Microchip's predefined library for delay methods

//Power LED (PortA)
#define LEDPin LATAbits.LATA0 //Define LEDPin as PORT A Pin 2

void main()
{

	while(!OSCCONbits.IOFS);      //wait for osc stable
	ADCON1 = 0x0F;                //set AN0-AN12 (RA0,RB0, etc) as digital I/O

	// --Set uC's internal to oscillator to 8MHz - default is 1 MHz
	//OSCCONbits.IRCF2 = 1;
	//OSCCONbits.IRCF1 = 1;	
	//OSCCONbits.IRCF0 = 1;	

	TRISA = 0x42; // 0100 0000 (RA1 is an input)
	TRISC = 0x00;

        LEDPin = 0; //Set LEDPin to off

	while(1)
	{
		//Delay test from 8Mhz to 48MHz (set to 8Hz 1 sec delay, should be faster at 48Mhz)
		//Delay10KTCYx(200);	
		//LEDPin = ~LEDPin;

		LEDPin = 1;	
	}
}

As you can see from the above code, I am just trying to turn the LED on while the microcontroller is configured to operate at 48MHz. In addition, I do not have 100nF decoupling caps on both sides of the uC (I only have one laying around unfortunately, but I am unsure if this is the problem as well). If anyone could help me determine the issue or point me in the right direction it would be much appreciated. Thank you.
 
Last edited:
Well, I got it work (hopefully it continues to work). I basically got rid of the line:

Code:
while(!OSCCONbits.IOFS);      //wait for osc stable

I guess this would make sense since I am not using those bits. I also added 220nF decoupling caps (which I plan to replace with 100nF, but I guess this will have to suffice for now) between VDD and VSS. So, it looks like it is stable, here is a pic for reference:

**broken link removed**
 
Decoupling capacitors are more important that you might think.

I had an issue a few years with a product which would work perfectly at 4-8Mhz but as soon as your kicked in the PLL to run at 16-40Mhz it was unpredictable - it worked for 95% of the time but would suffer from random resets.

It was 100% down to a batch of bad decoupling capacitors (100nF) - it took me a couple of weeks of debugging to realise it was hardware not software - it was only when I brought the circuit back to basics on a breadboard and found it worked fine that I looked at the hardware side.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…