|
|
View previous topic :: View next topic |
Author |
Message |
evelikov92
Joined: 10 Mar 2015 Posts: 23
|
How to enable 4X PLL in PIC18F6722 |
Posted: Sun Apr 05, 2015 4:09 am |
|
|
Hi everybody!
I begin with pic microcontroller, and I have problem with active 4X PLL in PIC18F6722.
Here is my simple code.
Code: |
#include "main.h"
#use delay(clock=32000000) // 32MHz
#fuses NOWDT,NOPROTECT,H4
void main()
{
setup_oscillator(OSC_8MHZ|OSC_NORMAL|OSC_31250|OSC_PLL_ON);
output_high(PIN_D1);
while(1)
{
output_toggle(PIN_C2);
delay_ms(5000);
}
}
|
I suppost is correct code but is not working correct. I write delay_ms(5000), but is working as delay_ms(20000).
My version of CCS C Compiler is 4.057.
Sory for my bad english. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sun Apr 05, 2015 6:56 am |
|
|
check your #fuses
you are missing at a MINIMUM the H4 argument
and probably more .... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19499
|
|
Posted: Sun Apr 05, 2015 9:04 am |
|
|
Key thing is always _read the data sheet first_.
One big problem with the PIC's is that there are hundreds of models, with slight differences to the options, and people try to use the options for one, with the wrong chip.
Start by working out what has to be set to make the chip do what you want, and then work out the CCS options to do this. The reference for the equivalence between the Microchip fuses, and the CCS names, is the file 'fuses.txt', and the reference for the options for the setup commands is the processor '.h' file.
So 6722 datasheet.
Section 2.5.2
"The PLL is also available to the internal oscillator block
when the internal oscillator block is configured as the
primary clock source. In this configuration, the PLL is
enabled in software and generates a clock output of up
to 32 MHz. The operation of INTOSC with the PLL is
described in Section 2.6.4 “PLL in INTOSC Modes”."
So note the critical thing here. The PLL for this _must_ be _enabled in software_, and the internal oscillator must be the primary clock source.
Neither is true in the settings being used.
First the internal oscillator must be set as the primary source INTRC or INTRC_IO.
Then the PLL must _not_ be enabled in the fuses. H4 is trying to enable the PLL in the fuses and this will stop it from being software enabled...
So Asmboy is wrong on this one (in this case - on most chips it would be needed....).
Then look at your clock setup line:
You are trying to enable two oscillators at once. The 32KHz, and the 8MHz. No. You can only have one oscillator running.
Code: |
#include "main.h"
#use delay(clock=32000000) // 32MHz
#fuses NOWDT,NOPROTECT,INTRC_IO
void main()
{
setup_oscillator(OSC_32MHZ); //This automatically selects the PLL
output_high(PIN_D1);
while(1)
{
output_toggle(PIN_C2);
delay_ms(5000);
}
}
|
The point is that your chip is not being setup to use the internal oscillator by default. It is defaulting to trying to use a crystal, and then dropping back to the internal oscillator, when this doesn't work (since you don't have fail safe clock monitoring disabled). This happens to give you 8MHz, but then the PLL can't be used on this oscillator.... |
|
|
evelikov92
Joined: 10 Mar 2015 Posts: 23
|
|
Posted: Sun Apr 05, 2015 11:54 am |
|
|
Thanks a lot Ttelmah. It's works. |
|
|
|
|
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
|