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

Correcting the timing with a new type of PIC: 18FXXJ90

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



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

Correcting the timing with a new type of PIC: 18FXXJ90
PostPosted: Thu Sep 10, 2009 8:38 am     Reply with quote

[compiler version: 4.093]
[programmer: PICKit2]
[uController: 18F66J90]

Hi there,

As usual I'm putting myself in to the fire before all to get some more from my designs. But also as usual, this causes a lot of headaches.

I recently decided to use 18F66J90 for our new product because of it's features. (LCD, RTC, mTouch, 2 UARTs, considerably low power comparing with other J series, etc).

Right now I have 120 pieces of 18F66J90's but I can make them run only at 4 MHz. Normally #use delay(clock=16000000) should work fine, but not with this one. I'm pretty sure this is a bug of CCS.

So I tried couple of workarounds.

Manually set the oscillator, manually set the PLL. But none of them works perfectly. Here is the code:

As I was writing this post, my aim was to ask help but exactly at this point I tried the last option and voila, found it. It was the SCS bits of OSCTUNE SF Register. So here I'm writing the solution if anyone needs it.
Code:

/// Add this line to your fuse settings
#fuses INTRCPLL_IO
/// if you want to use RA6 pin as 4MHz clock source use this one instead
#fuses INTRCPLL

/// Add this line right after your fuse settings (assuming that you want to work with 16 MHz)
#use delay(clock=16000000)


/// Add these lines somewhere in the beginning of your executable code like right after the void main()

#byte OSCCON = 0xFD3
#bit PLLEN = 0xF9B.6

OSCCON = 0b01100000;    /// 4MHz
PLLEN = 1;              /// x 4 = 16 MHz



Regards,
_________________
/// KMT
/// www.muratursavas.com
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 10, 2009 1:04 pm     Reply with quote

Quote:

#byte OSCCON = 0xFD3
#bit PLLEN = 0xF9B.6

OSCCON = 0b01100000; /// 4MHz
PLLEN = 1; /// x 4 = 16 MHz

This program does the same thing as your code:
(Tested with vs. 4.093 and 4.099)
Code:
#include <18F66J90.h>
#fuses INTRCPLL_IO, NOWDT
#use delay(clock=16M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//=====================================
void main()
{

setup_oscillator(OSC_4MHZ | OSC_PLL_ON);

while(1);
}


Here's the .LST file:
Code:

.... setup_oscillator(OSC_4MHZ | OSC_PLL_ON);
0030:  MOVLW  40
0032:  MOVWF  F9B  // Set PLLEN bit
0034:  MOVLW  60
0036:  MOVWF  FD3
0038:  MOVF   FD3,W


In symbolic format:
Code:

.... setup_oscillator(OSC_4MHZ | OSC_PLL_ON);
0030:  MOVLW  40
0032:  MOVWF  OSCTUNE  // Set PLLEN bit
0034:  MOVLW  60
0036:  MOVWF  OSCCON
0038:  MOVF   OSCCON,W
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

View user's profile Send private message Send e-mail

PostPosted: Fri Sep 11, 2009 3:10 am     Reply with quote

Thank you PCM Programmer,

I never tried setup_oscillator in this situation because my experience with setup oscillator never solved anything.

That means, I have to be open minded Smile
_________________
/// KMT
/// www.muratursavas.com
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