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 CCS Technical Support

setup_oscillator pic18f26k20 pll

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



Joined: 16 Aug 2010
Posts: 95

View user's profile Send private message

setup_oscillator pic18f26k20 pll
PostPosted: Tue Mar 01, 2011 6:49 pm     Reply with quote

Hi, I am using a PIC18F26K20 running at 16Mhz from the internal oscillator. Code is working fine. My issue is that bit 6 of the osctune register is not set to 1 to enable the 4x pll, so I am unable to run the part at its full clock speed of 64Mhz. CCS VER 4.116 Compiler.

For clarity I use the following code to configure the part
Code:

#use delay (INTERNAL=64MHZ)
setup_oscillator(OSC_64MHZ);

The #define for setup_oscillator from the .h file is
Code:
#define OSC_64MHZ   0x4070

Looking at the Osccon register it reads 7C, so the internal osc is running at 16 MHz.

The osctune register reads 40, bit 6 of this register is 0. I believe it should be 1 ?

Thanks Scott
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 02, 2011 5:41 pm     Reply with quote

Post a little LED blinking program with all the required lines for compilation.
Then I can just drop it into MPLAB and look at it.

It must have the #include for the PIC, #fuses, #use delay(), and main().
Test the program and verify that it fails before you post it.

Also tell us if this is a Proteus project or are you testing it in real
hardware ? Are you testing this in Debug mode or in Release mode ?
scottc



Joined: 16 Aug 2010
Posts: 95

View user's profile Send private message

PostPosted: Wed Mar 02, 2011 8:00 pm     Reply with quote

Hi PCM,

I will code up something for you to look at. I dont use Proteus but real
hardware with either the PCW debugger or MPLAB. I pulled my code into
mplab and looked at the sfr's that control the Osccon and Ostune registers
and they display the same as in the CCS debugger, though mplab seems to have a problem updating those SFR's Smile

I also looked fairly closely at the microchip spec sheet. I believe the
code should work, but the osctune register looks to be where the issue is.

Back in a bit with some code.

Thanks Scott
scottc



Joined: 16 Aug 2010
Posts: 95

View user's profile Send private message

PostPosted: Wed Mar 02, 2011 8:35 pm     Reply with quote

Hi Pcm some code, to try.. works ok this end with hardware but 4x
pll is not enabled. Using CCS VER 4.116

Thanks for your help

Scott
Code:

#include <main.h>
#use delay (INTERNAL=64MHZ)             //For Use with Internal Oscillator

#USE FAST_IO(A)
#USE FAST_IO(B)               
#USE FAST_IO(C)               

#BYTE port_a = 0xF80          //Port Address for 18F26K20 Part
#BYTE port_b = 0xF81
#BYTE port_c = 0xF82

#Define Led    Pin_C2         //Led

Void blinkaled (void)
   {
   Output_High(led);
   delay_ms(500);
   Output_Low(led);
   delay_ms(500);
   }

void main(void)
{

set_tris_c(0b11000000);       //Port C I/O Config
setup_oscillator(OSC_64MHZ ); //Internal Oscillator set for 16Mhz with 4x pll

//Note OSCTUNE REG = 40, bit 6 = 0 believe it should be 1 for 4x pll
//OSCCON REG = 7C ..Looks OK !

while(true)
   {
   blinkaled();
   }
}

Code:

//# MAIN.H File

#include <18F26K20.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPBADEN                 //PORTB pins are configured as digital I/O on RESET
#FUSES NOLPT1OSC                //Timer1 configured for higher power operation
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
scottc



Joined: 16 Aug 2010
Posts: 95

View user's profile Send private message

PostPosted: Wed Mar 02, 2011 8:37 pm     Reply with quote

I tested in PCW both with ICD=True and release mode, results are the
same... 4x pll not working. On this particular part the pll should enable
for only 8Mhz and 16Mhz, resulting in a internal clock of 32Mhz, 64Mhz

--edited to update info ----

PCM one other thing I noticed is even though I use a internal delay of 64Mhz The blink rate of the led seems to be ok, i.e of 1 second. This
is kind of curious because the internal clock is running at 16Mhz per the
config bits in the osccon register. I would think since the delay is set to
64Mhz the timing of the blinking led would be way off but not 100% sure
?

Thanks Scott
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 02, 2011 11:37 pm     Reply with quote

Quote:
The osctune register reads 40, bit 6 of this register is 0. I believe it should be 1 ?

I don't understand your statement above. You say OSCTUNE reads 0x40
but then you say bit 6 is 0. Those are contradictory statements.
0x40 = 0b01000000 = 0100 0000 = bit 6 is set to 1


I compiled your program with vs. 4.116 and I got this output in the
.LST file. It shows that OSCTUNE is set to 0x40, which means the
PLLEN bit is set = 1. I don't see what the problem is.
Code:

.................... setup_oscillator(OSC_64MHZ ); //Internal Oscillator set for 16Mhz with 4x pll 
0007C:  MOVLW  70
0007E:  MOVWF  FD3  // OSCCON
00080:  MOVLW  40
00082:  MOVWF  F9B  // OSCTUNE
00084:  MOVF   FD3,W
scottc



Joined: 16 Aug 2010
Posts: 95

View user's profile Send private message

PostPosted: Thu Mar 03, 2011 12:16 pm     Reply with quote

PCM, You are 100% right, I think I must of had a rough day or something
cant see the forest for the trees Smile

So the PLL apears to be Ok.

Thanks for the sanity check

Scott
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