changing internal clock speed

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
geetansh
Posts: 29
Joined: Tue Jun 21, 2011 4:23 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

changing internal clock speed

Post by geetansh »

hello
i have a little problem, i m using PIC18F4685 n i m using its internal oscillator.
everything is working fine but the internal oscillator is running at 1Mhz(default) but i want 8 or 4Mhz so please tell me how i can change internal oscillators frequency.
thank you.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: changing internal clock speed

Post by medelec35 »

Higeetansh,

At the very beginning of the flowchart (Main Macro) Place a C code box with

Code: Select all

osccon=0x70;
That should run internal osc at 8MHz
If use

Code: Select all

osccon=0x60;
instead,
then internal osc should run at 4MHz

If you look at the data sheet, then you can determine what values should be.
This is for a different target device, but take a look here:
http://www.matrixmultimedia.com/mmforum ... 29&#p28829

Martin
Martin

geetansh
Posts: 29
Joined: Tue Jun 21, 2011 4:23 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: changing internal clock speed

Post by geetansh »

thanks martin!

geetansh
Posts: 29
Joined: Tue Jun 21, 2011 4:23 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: changing internal clock speed

Post by geetansh »

hey 8Mhz is working fine but i think now i need freq around 20Mhz. (without using external oscillator)
i saw the link given n using PLL 16MHz and 32MHz freq can be achieved but i m going wrong somewhere
these are my steps (i am using PIC18F4685 without any external oscillator)
1. i selected this in the expert config. screen oscillator - HS-PLL enabled=4xFosc1
2. c code inserted was osccon=0xF0;

but when i checked it on hardware it was still running at 8Mhz.
so can you please tell me where i m wrong and the correct steps to get 16Mhz or 32Mhz freq without using any external oscillator?

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: changing internal clock speed

Post by medelec35 »

Hi geetansh,
Since PLL multiplies internal osc by 4, what you have stated is correct.
Only speeds you can achieve with PLL enabled is 4 x 4 = 16MHz
& 8 X 4 =32MHz

Here are the steps I would take for setting internal osc to 16MHz

1)Target clock speed to 16MHz, (I would 1st select 10 or 12MHz and just change second digit to a 6

2) Since 16MHz is 4 X 4 you will need to set internal oscillator to 4MHz.so use a C Code box with
osccon=0x60;
at the start of Main macro.

3) In expert Configuration, Set Oscillator to HS-PLL enabled freq=4xFosc1,
Change Watchdog Timer, Low Voltage Program
& Extended CPU Enable from Enabled to disabled.

Give that a go, and if still not working then If you post your flowchart (assuming it's not commercially sensitive) , someone will take a look at it for you.

Martin
Martin

cobra1
Posts: 175
Joined: Thu Feb 04, 2010 7:44 am
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: changing internal clock speed

Post by cobra1 »

Hi, the HS-PLL wont work with the internal clock, well at least i couldnt get it to work.

It needs to have an external clock to work with the HS-PLL,
Put an 8mhz crystal in the hardware and set HS-PLL and you will get 32mhz clock speed

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: changing internal clock speed

Post by medelec35 »

Hi cobra1,
Sorry to hear you could not get PLL to work with internal osc.
These chips are designed to work at 16 and 32 MHz in conjunction with internal oscillator as well as external osc.
here is the block diagram:
Int Osc PLL.png
(87.96 KiB) Downloaded 7030 times
As you can see the connection from internal osc and PLL block
cobra1 wrote:Hi, the HS-PLL wont work with the internal clock, well at least i couldnt get it to work.
You are correct! Looking at the data sheet I have made a mistake saying about HS-PLL enabled freq=4xFosc1
Sorry about that.

To enable PLL to work with internal osc try this.
Add to C code block you have got at the beginning:

Code: Select all

osctune.PLLEN=1;
So you should have:

Code: Select all

osccon=0x60;
osctune.PLLEN=1;
Then In expert Configuration, Set Oscillator to 1 of the INT configurations
Thanks cobra1 for mentions you could not get it to work, thats what made me look at the datasheet in more detail.

Martin
Martin

cobra1
Posts: 175
Joined: Thu Feb 04, 2010 7:44 am
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: changing internal clock speed

Post by cobra1 »

No problem, i myself have learnt something new :)

geetansh
Posts: 29
Joined: Tue Jun 21, 2011 4:23 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: changing internal clock speed

Post by geetansh »

hello guys i tried it on hardware(without osctune) n it didnt worked then i looked at datasheet n found out osctune<6> needs to be set.
i was just posting my doubt about it but u guys have already solved it.
thanks to u both. :)

geetansh
Posts: 29
Joined: Tue Jun 21, 2011 4:23 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: changing internal clock speed

Post by geetansh »

what's the use of "Extended cpu enable" ????
so that i knw the difference on hardware response when it is enabled or disabled.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: changing internal clock speed

Post by medelec35 »

Hi geetansh,
Glad PLL is now working with internal osc.

One issue I know of with Extended cpu is it appears to cause problems with string arrays.
So if enabled will stop LCD from working correctly.
Martin

geetansh
Posts: 29
Joined: Tue Jun 21, 2011 4:23 pm
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: changing internal clock speed

Post by geetansh »

any link or doc to know more about it??

cobra1
Posts: 175
Joined: Thu Feb 04, 2010 7:44 am
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: changing internal clock speed

Post by cobra1 »

I had mega problems with the extended CPU. Took me over a week to find it was actually that causing the problem. I don't know what it does exactly. But I just disable it. I disable everything that I don't fully understand.

Post Reply