48MHz Clock Frequency from 4MHz crystal

Programmer, In-Circuit Debugger, PIC Start-Up Kit, Memory Interface...

48MHz Clock Frequency from 4MHz crystal

Postby aru » Mon Oct 22, 2018 3:52 pm

I am using SK40C.
I need to have a Microcontroller clock frequency of 48MHz when using 4 MHz crystal.
Device used is 18F4550. IDE used is MPLABX V5.05. Compiler used is XC8 V2.00.

Based on the datasheet, I added the following configuration settings in the code to achieve 48MHz cpu clock;
#pragma config PLLDIV = 1
#pragma config CPUDIV = OSC1_PLL2
#pragma config FOSC = XTPLL_XT

I made a simple code below to check if the clock frequency is correct.

#pragma config PLLDIV = 1
#pragma config CPUDIV = OSC1_PLL2
#pragma config FOSC = XTPLL_XT

#include <xc.h>
#define _XTAL_FREQ 4000000
#define MyPIN LATDbits.LATD0

void main(void)
{
TRISD = 0;
while(1)
{
MyPIN = 1;
NOP();
MyPIN = 0;
NOP();
}
}
NOP() should give 1 cycle delay.
Simulation shows correctly as 41ns of HIGH and 83 seconds if LOW. This is correct for 48MHz instruction frequency.
But after programming the device using the above configuration settings, the Oscilloscope at RD0 shows HIGH and LOW with timing way low than these values

Can someone take a look and advise if the config settings are correct for 48MHz cpu clock.
Thanks for the help
aru
Novice
 
Posts: 17
Joined: Fri Jan 05, 2018 2:53 pm

Re: 48MHz Clock Frequency from 4MHz crystal

Postby aru » Tue Oct 23, 2018 9:29 am

Found the reason for the error.
I overlooked the fact that the instruction frequency is 1/4 of the CPU clock frequency.
For 48MHz CPU clock the instruction frequency is 12MHz.
The cycle time is 83nS.
The oscilloscope waveform is correct.
Thanks.
Please close this case.
aru
Novice
 
Posts: 17
Joined: Fri Jan 05, 2018 2:53 pm

Re: 48MHz Clock Frequency from 4MHz crystal

Postby ober » Sat Oct 27, 2018 5:05 am

Good catch!
Ober Choo
Cytron Technologies Sdn Bhd
www.cytron.com.my
User avatar
ober
Moderator
 
Posts: 1378
Joined: Wed Apr 15, 2009 1:03 pm


Return to PIC Development Tool

Who is online

Users browsing this forum: No registered users and 1 guest