CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

PLL on internal clock

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rikotech8



Joined: 10 Dec 2011
Posts: 376
Location: Sofiq,Bulgariq

View user's profile Send private message

PLL on internal clock
PostPosted: Sat Sep 29, 2012 1:49 am     Reply with quote

Hi!
How can I measure a clock (osc/4) frequency of my MCU? I need to do it, because I test 18F2520 (MCU)whether it reach maximum clock freq 32MHZ by PLL function and internal oscilator. Here is the code I use:
Code:

#include <18F2520.h>
#FUSES INTRC_IO,PUT,NOWDT,NOMCLR
#use delay(internal = 8M)

void main()
{
setup_oscillator(OSC_32MHZ|OSC_INTRC|OSC_PLL_ON);
while(true)
   {
   output_toggle(pin_b0);
   }
}

May be the output shall toggling with clock freq divided by two?
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

Re: PLL on internal clock
PostPosted: Sat Sep 29, 2012 2:15 am     Reply with quote

rikotech8 wrote:
Hi!
How can I measure a clock (osc/4) frequency of my MCU? I need to do it, because I test 18F2520 (MCU)whether it reach maximum clock freq 32MHZ by PLL function and internal oscilator. Here is the code I use:
Code:

#include <18F2520.h>
#FUSES INTRC_IO,PUT,NOWDT,NOMCLR
#use delay(internal = 8M)

void main()
{
setup_oscillator(OSC_32MHZ|OSC_INTRC|OSC_PLL_ON);
while(true)
   {
   output_toggle(pin_b0);
   }
}

May be the output shall toggling with clock freq divided by two?


No.

Start at the beginning. The processor executes one instruction for each four cycles of the CPU clock. So at 32MHz, the processor performs at 8MIPS.

Then the output_toggle instruction, involves two processor instructions, while the jump back though one instruction, takes two cycle times (look up jump instructions in the data sheet). So four instruction times. So the pin should take 500nSec between edges (4*125nSec), giving 1MHz out.

As a comment, the use delay statement, should match your clock. So needs to say 32MHz, not 8MHz. This won't 'matter' for the code as shown, but will cause problems with timings, RS232, etc. etc. in the future.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group