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 support@ccsinfo.com

pic18f46k22 configure oscillator

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



Joined: 31 Jan 2013
Posts: 59

View user's profile Send private message

pic18f46k22 configure oscillator
PostPosted: Sun Aug 30, 2020 4:12 am     Reply with quote

hi
I want to configure pic18f46k22 in internal oscillator 64 MHz. But rs232 not working !
When change to 16 MHz rs232 working properly.
Code:

#include <18F46K22.h>
#FUSES NOWDT,NOBROWNOUT,NOPUT,PLLEN,NOMCLR 
#use delay(internal=64mhz)

#use rs232(baud=9600,parity=N,xmit=PIN_d6,rcv=PIN_d7,bits=8,stream=BLT)

void main()
{
        while(true)
        {
        printf("hello\r\n");
        delay_ms(100);
        }
}
temtronic



Joined: 01 Jul 2010
Posts: 7686
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Aug 30, 2020 5:12 am     Reply with quote

I did a very quick test to confirm...

these settings work fine for me.

//46k22 fuses

#fuses H4 //uses PLL*4 speed
#fuses INTRC_IO //use internal osc (yes !!)

//
#use delay(clock=64000000,internal)

if they don't work, perhaps it's a compiler 'bug' but 16MHz works, 64 doesn't is 'magically' 4x.... looks like the fuse setting is incorrect.

Jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21232

View user's profile Send private message

PostPosted: Sun Aug 30, 2020 6:30 am     Reply with quote

Try this modified version of your program.
Code:
#include <18F46K22.h>
#FUSES INTRC_IO, NOWDT,NOBROWNOUT,NOPUT,NOMCLR 
#use delay(clock=64M)

#use rs232(baud=9600,parity=N,xmit=PIN_d6,rcv=PIN_d7,bits=8,stream=BLT)

//=============================
void main()
{
setup_oscillator(OSC_64MHZ, OSC_PLL_ON);

delay_ms(100);

while(TRUE)
  {
   printf("hello\r\n");
   delay_ms(100);
  }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 16429

View user's profile Send private message

PostPosted: Sun Aug 30, 2020 6:56 am     Reply with quote

Critical question, nobody has asked. _What compiler version_.
hamid9543



Joined: 31 Jan 2013
Posts: 59

View user's profile Send private message

PostPosted: Sun Aug 30, 2020 7:32 am     Reply with quote

Ttelmah wrote:
Critical question, nobody has asked. _What compiler version_.


5.094
Ttelmah



Joined: 11 Mar 2010
Posts: 16429

View user's profile Send private message

PostPosted: Sun Aug 30, 2020 9:44 am     Reply with quote

OK.
In which case the H4 fuse referred to by Jay, doesn't exist.

Your problem is being caused by you trying to enable the PLL, with the
PLLEN fuse. This is not allowed (data sheet PLL in HFINTOSC modes):
Quote:

The 4x frequency multiplier can be used with the
internal oscillator block to produce faster device clock
speeds than are normally possible with the internal
oscillator. When enabled, the PLL multiplies the
HFINTOSC by 4 to produce clock rates up to 64 MHz.

Unlike external clock modes, the PLL can only be
controlled through software. The PLLEN control bit of
the OSCTUNE register is used to enable or disable the
PLL operation when the HFINTOSC is used.


Note what the second paragraph says. You _cannot_ enable the PLL
in the fuses, and use it with the internal oscillator. It has to be enabled
in software.
By turning it on in the fuses, you are preventing it from working.

Simply remove your PLLEN fuse, and it should work....
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