View previous topic :: View next topic |
Author |
Message |
nazoa
Joined: 09 Feb 2007 Posts: 56
|
Setting clock on 18F67J60 |
Posted: Thu Jan 17, 2008 8:32 am |
|
|
Hello,
Can anyone suggest how the following clock conditions on the 18F67J60 chip can be set?
PLL Prescaler = /3
PLL5 = enabled
PLL Postscaler = disabled
My board has a 25MHz crystal and I am trying to set the internal clock frequency to 41.6667MHz.
I have tried the following:
#byte osctune=0xFD3
osctune = 0x40;
But it has not helped. The internal clock remains at 25MHz.
Thanks! |
|
|
CCS_HELPER Guest
|
|
Posted: Thu Jan 17, 2008 9:42 am |
|
|
I'm working from memory, but this should point you in the right direction:
1) Make sure you have the HSPLL or H4_SW fuse set (can't remember which it is)
2) Search the 18F67J60 header file for "setup_oscillator". There should be an option such as PLL_5_DIV_3 or something like that. Call the function setup_oscillator(PLL_5_DIV_3); (or whatever constant you find in the header file) from main().
Do both of these and you should be good to go! |
|
|
nazoa
Joined: 09 Feb 2007 Posts: 56
|
|
Posted: Thu Jan 17, 2008 11:05 am |
|
|
Thanks for the suggestions but I have tried them all. HSPLL does not exist and H4_SW does help. PLL5_5_DIV_3 or PLL5 or anything else is not on the header file and what I have tried generates a compilation error.
Any other suggestions? |
|
|
nazoa
Joined: 09 Feb 2007 Posts: 56
|
|
Posted: Thu Jan 17, 2008 11:48 am |
|
|
I have tried adding setup_oscillator(OSC_PLL_5_DIV_3); in the main code and the compiler listing shows the following:
0AAFE: MOVLW 40
0AB00: MOVWF F9B
0AB02: CLRF FD3
0AB04: MOVF FD3,W
I am not sure but I think this writing 0x40 to address F9B which is the OSCTUNE register which is what is needed. But it still does not help.
I tried writing directly to the OSCTUNE register but that does not help either!
|
|
|
CCS_HELPER Guest
|
|
Posted: Thu Jan 17, 2008 12:35 pm |
|
|
what compiler version are you using? I haven't checked the ASM listing you posted to see if it's correct, but earlier version 4 compilers generated incorrect code for the setup_oscillator() function on this chip. |
|
|
nazoa
Joined: 09 Feb 2007 Posts: 56
|
|
Posted: Thu Jan 17, 2008 4:25 pm |
|
|
OK, I am using 4.065 and have run out of ideas..
Probably not relevant, but I am using the CCS ethernet kit board with the web server example.
Thanks.
|
|
|
RossJ
Joined: 25 Aug 2004 Posts: 66
|
|
Posted: Thu Jan 17, 2008 5:47 pm |
|
|
There are essentially 3 things you need to set to control the oscillator: OSCCON, OSCTUNE and the FOSC2:0 fuses. If you want to eliminate the compiler as a possible source of your problem, start by writing the registers directly (as you have done above).
With the code you indicated above:
0AAFE: MOVLW 40
0AB00: MOVWF F9B
0AB02: CLRF FD3
0AB04: MOVF FD3,W
Your OSCTUNE settings will produce the desired frequency so long as the fuses are set to one of the two PLL modes, otherwise the PLL, prescaler and postscaler are all disabled (i.e. what you are getting).
Your OSCCON settings are such that the fuses MUST be set correctly.
The fuses FOSC2:0 are set with the compiler symbols PRIMARY and H4_SW. Make sure you don't have any other oscillator related fuses set (i.e. HS,EC_IO,E4_SW_IO,INTRC). If you have any doubts as to what the different fuse names are (H4_SW is a very odd name given that this is not a x4 PLL), the device editor has all the definitions. Also, take a look at the bottom of the .LST file where you can see the actual hex values of the fuses. Make sure the oscillator values are as you expect. |
|
|
nazoa
Joined: 09 Feb 2007 Posts: 56
|
|
Posted: Fri Jan 18, 2008 3:13 am |
|
|
Thank you RossJ this has fixed the problem. It was the oddly named H4_SW that I had not tried.
Thanks again.
|
|
|
|