|
|
View previous topic :: View next topic |
Author |
Message |
rikotech8
Joined: 10 Dec 2011 Posts: 376 Location: Sofiq,Bulgariq
|
PLL on internal clock |
Posted: Sat Sep 29, 2012 1:49 am |
|
|
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
|
Re: PLL on internal clock |
Posted: Sat Sep 29, 2012 2:15 am |
|
|
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 |
|
|
|
|
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
|