View previous topic :: View next topic |
Author |
Message |
doctorprox
Joined: 09 Nov 2010 Posts: 7 Location: UK
|
Internal Oscillator not working at 64mhz |
Posted: Mon Nov 25, 2013 10:18 am |
|
|
Hi there,
I have been playing with this for the last 6 hours now trying to get it to work and it's driving me over the edge.
I want to run a PIC18F13k22 at its 64mhz internal oscillator (16mhz 4xPLL).
I've tried using setup_oscillator() with various attempts and each failed.
I treid using just fuses and #use delay (internal=16000000) or (clock=64000000) which all failed.
I even tried setting OSCCON and OSCTUNE manually using this:
Code: |
#byte OSCCON = 0xFD3
#byte OSCTUNE = 0xF9B
OSCCON = 0b11110010;
OSCTUNE =0b11000000;
|
Code: | #FUSES INTRC_IO
#FUSES PLLEN
#use delay(clock=64000000) |
Code: | #FUSES INTRC_IO
#FUSES PLLEN
#use delay(internal=16000000) |
I appear to keep getting the default 4mhz according to my calcs from timer0. I think the best I have managed is 8mhz.
Please help, any advice would be much appreciated.
Jason |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Nov 25, 2013 10:36 am |
|
|
Code: |
#FUSES INTRC_IO
#use delay(internal=64MHz)
//Then add at the start of main
setup_oscillator(OSC_INTRC|OSC_64MHz);
|
Some compiler versions get it all 'right', but some leave you running in the 'failsafe' with just the fuses. The setup_oscillator, then switches to the correct oscillator. The clock statement must use 64Mhz, or timings will all be wrong once the oscillator is running at 64MHz.
Best Wishes |
|
|
doctorprox
Joined: 09 Nov 2010 Posts: 7 Location: UK
|
|
Posted: Mon Nov 25, 2013 11:39 am |
|
|
Thank you for the suggestion, I tried adding the code but unfortunately it appears to run at 8mhz. I'm wondering if there is a compiler problem with the k22 pic? Surely though if osccon is right it has to work? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Nov 25, 2013 11:49 am |
|
|
I've had the chip working with the settings given, at 64MHz.
What compiler version?....
Best Wishes |
|
|
doctorprox
Joined: 09 Nov 2010 Posts: 7 Location: UK
|
|
Posted: Mon Nov 25, 2013 12:18 pm |
|
|
Version 5.007.
I had a play with those settings, by removing the setup_oscillator from main() and just having this:
Code: |
#FUSES INTRC_IO
#FUSES PLLEN
#use delay(internal=64MHz) |
It runs about 4 times faster than I have ever been able to get it going. I don't believe it is 64Mhz because my timers are way out and if I run the code in ISIS with a simulated crystal of 64mhz it is about 4 times quicker still (my timed pulses are 4 times shorter).
I 'think' that with setup_oscillator(OSC_INTRC|OSC_64MHz); in the main() as well as the fuses it runs at 4mhz, without it it runs at 16mhz.
I'll do some calculations tomorrow to confirm this, the way I have been doing it is pulse width / number of timer0 counts multiplied by 4 to give speed.[/code] |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19506
|
|
Posted: Mon Nov 25, 2013 12:23 pm |
|
|
I consider 5.007, to still be a 'beta' for the V5 compilers, so not too surprised if it has problems. As I said the setup oscillator is only needed on compilers that don't do it correctly from the fuses/clock option given.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Nov 25, 2013 9:35 pm |
|
|
I tested this program with vs. 5.007 and it runs OK. This test is with an
18F14K22 on a Microchip Low Pin Count board at +5v. The LED on pin C0
blinks once per second. I don't have an 18F13K22, but I then compiled
the program for that PIC and the .LST file code looks the same. So your
PIC should work with this program. I used a Microchip ICD2. The
program was compiled and run in "Release" mode.
Code: |
#include <18F14K22.h>
#fuses INTRC_IO, BORV27, NOMCLR
#use delay(clock=64M)
//===================================
void main()
{
while(1)
{
output_high(PIN_C0);
delay_ms(500);
output_low(PIN_C0);
delay_ms(500);
}
} |
Code: |
CCS PCH C Compiler, Version 5.007, xxxx 25-Nov-13 19:31
Filename: C:\Program Files\PICC\Projects\18F14K22\18F14K22.lst
ROM used: 114 bytes (1%)
Largest free fragment is 16270
RAM used: 5 (1%) at main() level
6 (1%) worst case
Stack used: 0 locations
Stack size: 31
|
Quote: | if I run the code in ISIS with a simulated crystal of 64mhz |
Run the program in hardware, like I did. |
|
|
doctorprox
Joined: 09 Nov 2010 Posts: 7 Location: UK
|
|
Posted: Tue Nov 26, 2013 5:42 am |
|
|
Thank you for the help, that does appear to work correctly. It seems that the compiler gets confused with the setup_oscillator function. |
|
|
|