Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

18f4550 @ 3.3v using internal oscillator

Status
Not open for further replies.

mdanh2002

Member
Hi,

I am trying to run a PIC18F4550 at 3.3V using its internal oscillator. My code is as follows:

#pragma config WDT = OFF
#pragma config MCLRE = OFF
#pragma config FOSC = INTOSC_HS //Internal oscillator, port function on RA6, HS crystal used by USB
#pragma config BOR = OFF
#pragma config LVP = OFF //to be able to use RB5
#pragma config PBADEN = OFF
#pragma config ICPRT = OFF
#pragma config PLLDIV = 1

....

OSCCON = 0b01110000; //8Mhz internal oscillator

The PIC runs properly but much slower (around 8 times) when compared with a 16f with a 8Mhz external crystal. For example, the following FOR loop:

for (i=0; i<500; i++);

delays around 1 millisecond on a 16f with 8MHz crystal. But on this PIC, it delays for 8 milliseconds.

I have tried to enable the PLL (x4) using OSCTUNE but that does not seem to have any effects. Is there a divider somewhere that divide the internal oscillator frequency before using it? Or it it because I run at 3.3v and everything is slower. The datasheet says that this PIC can run from 2V to 5V.

Thanks for any advice.
 
Last edited:
Hi,

The lower the voltage the lower the clock speed, so always checks the chips 'electrical charactristics' in the data sheet -there are graphics showing the frequency v volts - 8 meg at 3v3 should be ok though.

Try changing your FOSC to FOSC=INTOSCIO_EC
- see the 4550.inc file for options /details. ( in Mplab ASM folder) or the C equivalent
 
According to the datasheet the PLL only works with external crystals The highest internal frequency is 8Mhz, If you specify FOSC = INTOSC_HS this requires an external crystal ASWELL to dive the USB clock. Are you using the USB?


Cheers Ian
 
Last edited:
Hi. I plan to add USB functionality shortly but for now, USB is not used yet. Must I still have the external crystal for USB even if it's not used?

As to whether the PLL is available for the internal oscillator, I researched and got contradicting results. On page 2 of the official datasheet from Microchip, it says

4x Phase Lock Loop (PLL) – available for crystal and internal oscillators

On page 28, there is a full section of how to configure PLL in INTOSC modes. If I understand correctly, setting bit 6 of OSCTUNE (PLLEN) to 1 is all I need to to to enable the PLL (x4). However, many other online sources say that PLL is only supported for external oscillators. Strange. Regardless, even without PLL, the PIC should be running at 8Mhz. But my example using the FOR loop and compare with a PIC 16F @ 8Mhz shows that it is running only around 1 MHz, way to slow.

I think I have tried to change it to INTOSCIO_EC (external clock for USB) with the same effects.
 
I just found out that if I connected a 4MHz crystal and used the following configuration

#pragma config WDT = OFF
#pragma config MCLRE = OFF
#pragma config FOSC = XTPLL_XT
#pragma config BOR = OFF
#pragma config LVP = OFF
#pragma config PBADEN = OFF
#pragma config ICPRT = OFF
#pragma config PLLDIV = 1
#pragma config CPUDIV = OSC1_PLL2
#pragma config USBDIV = 2

then the PIC runs at 8Mhz. Strange, with the above configuration, shouldn't it be using the PCC and run at 48Mhz instead? My PIC has an I/P at the end of its part name (PIC18F4550 I/P), if that matters.
 
Last edited:
...
The PIC runs properly but much slower (around 8 times) when compared with a 16f with a 8Mhz external crystal. For example, the following FOR loop:

for (i=0; i<500; i++);

delays around 1 millisecond on a 16f with 8MHz crystal. But on this PIC, it delays for 8 milliseconds.
...

This is a very poor way to measure the PIC osc speed, especially since you are comparing 16F to 18F with the same code!

You need a system to output the osc speed regardless of how the code compiles.

Here is a system I have often used;
Code:
// first set TMR0 to 8bit mode and 1:1 prescaler
T0CON = 0b11001000;		 // ON, 8bit mode, 1:1 prescaler

// loop and generate output freq exactly every 512 PIC instructions (xtal freq / 2048)
while(1)
{
  while(INTCON.T0IF == 0);       // wait for TMR0 to roll
  INTCON.T0IF = 0;               // then clear roll flag
  if(LATB.F0 == 1) LATB.F0 = 0;  // toggle RB0 output pin
  else             LATB.F0 = 1;
}

All this does is toggle an output pin synchronised to every 256 instructions, so the output frequency is;
freq_out = (freq_xtal / 4 / 256 / 2)
so; freq_out = (freq_xtal / 2048)

Then you can use a frequency meter to very accuractely measure the xtal freq without loading the xtal in any way.
 
Last edited:
Flexible Oscillator Structure:
• Four Crystal modes, including High Precision
PLL for USB
• Two External Clock modes, up to 48 MHz
• Internal Oscillator Block:
- 8 user-selectable frequencies, from 31 kHz
to 8 MHz
- User-tunable to compensate for frequency drift
• Secondary Oscillator using Timer1 @ 32 kHz
• Dual Oscillator options allow microcontroller and
USB module to run at different clock speeds
• Fail-Safe Clock Monitor:
- Allows for safe shutdown if any clock stops

This is from the official datasheet.
Yes you can run directly from the internal OSC only.
I know that some pic's can PLL the internal clock but if you look at page 24, because of the USB the circuitry, it's different.

Cheers Ian
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top