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 support@ccsinfo.com

How to enable 4X PLL in PIC18F6722

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



Joined: 10 Mar 2015
Posts: 23

View user's profile Send private message

How to enable 4X PLL in PIC18F6722
PostPosted: Sun Apr 05, 2015 4:09 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Sun Apr 05, 2015 6:56 am     Reply with quote

check your #fuses
you are missing at a MINIMUM the H4 argument
and probably more ....
Ttelmah



Joined: 11 Mar 2010
Posts: 19254

View user's profile Send private message

PostPosted: Sun Apr 05, 2015 9:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Apr 05, 2015 11:54 am     Reply with quote

Thanks a lot Ttelmah. It's works.
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