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

[SOLVED] internal oscillator with PIC18F45K80
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
scanan



Joined: 13 Aug 2004
Posts: 58
Location: Turkey

View user's profile Send private message Visit poster's website

[SOLVED] internal oscillator with PIC18F45K80
PostPosted: Thu Nov 12, 2015 12:03 pm     Reply with quote

hi,
I am frustrated with the setting of the fuse and #use delay

my settings are as followed
Code:

#include <18F45K80.h>
#fuses NOWDT,NOPROTECT,NOLVP,NODEBUG,NOMCLR,INTRC_IO,NOBROWNOUT,PUT,NOFCMEN,NOIESO
#use delay(clock=16MHz)


when I tried
#use delay(clock=16MHZ)
my delay_ms(500) is not 500ms it is 125ms
any solution?

I want to use the PLL with internal 16MHZ oscillator.
and how to set the CONFIG1H bit4 with the #fuse command can't find it
I use ccs ver4.135.

may thanks
_________________
Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com

Do whatever you do with amateur spirit -
But always feel professional.


Last edited by scanan on Thu Dec 29, 2016 5:56 am; edited 5 times in total
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 12:18 pm     Reply with quote

Before I go to the trouble of reading both data sheets.

Which part are you really using?

The 18F45K80 in the title.
OR
The 18F4580 in the code.

Mike
scanan



Joined: 13 Aug 2004
Posts: 58
Location: Turkey

View user's profile Send private message Visit poster's website

PostPosted: Thu Nov 12, 2015 12:39 pm     Reply with quote

Sorry it should be pic18f45K80
_________________
Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com

Do whatever you do with amateur spirit -
But always feel professional.
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 12:51 pm     Reply with quote

Agreed.

In fact he already has it running. He wants 16MHz*4. so 64MHz, then is selecting clock=16MHz, so 'of course' times are only 1/4 the value they should have....

The 4580, can't do 64MHz, so he must be using the K80.
wangine



Joined: 07 Jul 2009
Posts: 98
Location: Curtea de Arges, Romania

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

Re: internal oscillator with PIC18F45K80
PostPosted: Thu Nov 12, 2015 1:23 pm     Reply with quote

scanan wrote:

I want to use the PLL with internal 16MHZ oscillator.
and how to set the CONFIG1H bit4 with the #fuse command can't find it
may thanks

For your #fuse and INTRC_IO should be
Code:
#use delay(internal=16MHz)
and for PLL on
Code:
setup_oscillator(OSC_16MHZ,OSC_PLL_ON);

the test code and get 500ms delay
Code:
#include <18LF45K80.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES SOSC_DIG                 //Digital mode, I/O port functionality of RC0 and RC1
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOMCLR                   //Master Clear pin used for I/O

#use delay(internal=16MHz)

void main()
{
setup_oscillator(OSC_16MHZ,OSC_PLL_ON);

   while(TRUE)
   {
    output_toggle(pin_d0);
    delay_ms(500);
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Thu Nov 12, 2015 3:32 pm     Reply with quote

Not quite. That will give him the times/4 as he already has:
Code:

#use delay(internal=16MHz, clock=64MHz)
//critical change so timings work.....
scanan



Joined: 13 Aug 2004
Posts: 58
Location: Turkey

View user's profile Send private message Visit poster's website

PostPosted: Fri Nov 13, 2015 6:17 am     Reply with quote

Hello

Code:
#use delay(internal=16MHz, clock=64MHz)

my compiler is unable to compile with this directive
giving error
Quote:
*** Error 99 " Option invalid Internal Osc Freq Wrong

What else to do in order to activate the <config1H>bit4
my fuses after compiling
Quote:


Configuration Fuses:
Word 1: 0800 INTRC_IO NOFCMEN NOIESO
Word 2: 1E18 PUT NOBROWNOUT BORV21 NOWDT WDT32768
Word 3: 0600 PBADEN LPT1OSC NOMCLR
Word 4: 0091 STVREN NOLVP BBSIZ2K NOXINST NODEBUG
Word 5: C00F NOPROTECT NOCPB NOCPD
Word 6: E00F NOWRT NOWRTC NOWRTB NOWRTD
Word 7: 400F NOEBTR NOEBTRB

I want word1: to be 1800 but I can't find any directive for that

cheers
_________________
Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com

Do whatever you do with amateur spirit -
But always feel professional.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 13, 2015 12:29 pm     Reply with quote

It's in the 18F45K80 data sheet. In the CONFIG1H section, it has notes
at the bottom that say, regarding the PLLEN fuse:
Quote:

bit 4 PLLCFG: 4X PLL Enable bit (Note 1)
1 = Oscillator is multiplied by 4
0 = Oscillator is used directly

bit 3-0 FOSC<3:0>: Oscillator Selection bits (Note 2)
Note
1: Not valid for the INTIOx PLL mode.
2: INTIO + PLL can be enabled only by the PLLEN bit (OSCTUNE<6>)
.
Other PLL modes can be enabled by either the PLLEN bit or the
PLLCFG (CONFIG1H<4>) bit.

That means you have to use setup_oscillator(), or you could write
directly to the OSCTUNE register. You have already been told this
earlier in the thread.


Quote:
I want word1: to be 1800 but I can't find any directive for that

This means the low byte would have to be 00, but you can't do this.
Why ? Because the PIC data sheet says:
Quote:
bit 4-3 SOSCSEL<1:0>: SOSC Power Selection and Mode Configuration bits
11 = High-power SOSC circuit is selected
10 = Digital (SCLKI) mode; I/O port functionality of RC0 and RC1 is enabled
01 = Low-power SOSC circuit is selected
00 = Reserved

Having 00 for bits 3 and 4 of CONFIG1L is not allowed. It has to be 01,
10, or 11. Therefore you can't get 00 in the low byte, and you can't
get 0x1800 for CONFIG1.
scanan



Joined: 13 Aug 2004
Posts: 58
Location: Turkey

View user's profile Send private message Visit poster's website

PostPosted: Fri Nov 13, 2015 2:04 pm     Reply with quote

Many thanks to all of you without your help and enlightment I could not solve this problem easily and quickly.

My #FUSES settings for PIC18F45F80 are as follows
for 64MHZ clock internal PLL active.

Code:

#include <18F45K80.h>

#FUSES PLLEN,VREGSLEEP,INTRC_HP,SOSC_DIG,NOXINST,INTRC_IO,NOFCMEN,NOIESO //1
#FUSES PUT,NOBROWNOUT,NOWDT //2
#FUSES CANB,MSSPMSK7,NOMCLR //3
#FUSES NOSTVREN,BBSIZ2K,NODEBUG //4
#FUSES NOPROTECT,NOCPB,NOCPD //5
#FUSES NOWRT,NOWRTC,NOWRTB,NOWRTD,  //6
#FUSES NOEBTR,NOEBTRB //7
#use delay(clock=64000000)


Here the PLLEN directive has no effect
the setup_oscillator should be like
Code:

setup_oscillator(OSC_16MHZ|OSC_PLL_ON);   


at the end I get 64MHZ clock speed Smile
_________________
Dr Suleyman CANAN
R&D Electronic Engineer
https://suleymancanan.wordpress.com

Do whatever you do with amateur spirit -
But always feel professional.
silelis



Joined: 12 Jun 2007
Posts: 68
Location: Poland, podlaskie district

View user's profile Send private message

PostPosted: Sun Oct 08, 2017 12:50 pm     Reply with quote

Is it possible to use PLL_en with 20MHz quarts??

What is the differende beetween
clock, interna, crystal parameters?
silelis



Joined: 12 Jun 2007
Posts: 68
Location: Poland, podlaskie district

View user's profile Send private message

PostPosted: Sun Oct 08, 2017 12:52 pm     Reply with quote

Is it possible to use PLL_en with 20MHz quarts??


I.e If my physical (on board) quartz is 20 MHz whot I can do with my internal crystal?
Do I understand it correctly that PLL_en is "some kind of overclocking"? And if Yes what is the difference between
clock, interna, crystal parameters?
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Sun Oct 08, 2017 1:13 pm     Reply with quote

silelis wrote:
Is it possible to use PLL_en with 20MHz quarts??


I.e If my physical (on board) quartz is 20 MHz whot I can do with my internal crystal?
Do I understand it correctly that PLL_en is "some kind of overclocking"? And if Yes what is the difference between
clock, interna, crystal parameters?


No.

It's not overclocking, it is a PLL. Phase locked loop. An oscillator that is phase locked to another source. In this case, /4 phase locked to the crystal. Reason is that it is hard to make crystal oscillators for higher frequencies, and increases RF noise being radiated by the chip, so most of the faster PIC's have some form of PLL available. In this case it is a fixed one (*4), on many of the more complex PIC's you can choose the division ratio (so the multiple produced), while on others there is a higher multiple, following a divider.

From the data sheet 31-6 1A:
Quote:

min max
4 16 MHz HS + PLL Oscillator mode


4MHz is the minimum crystal supported by the PLL. 16 MHz the maximum.

No option to use the PLL with 20MHz.
silelis



Joined: 12 Jun 2007
Posts: 68
Location: Poland, podlaskie district

View user's profile Send private message

PostPosted: Sun Oct 08, 2017 11:09 pm     Reply with quote

So in my case where I an using PIC18f4520 it should be like this:

Code:

#use delay (crystal =16000000, internal = 32000000)


or like this
Code:

#use delay (clock=32000000Hz)

main()
{
setup_oscillator(OSC_16MHZ|OSC_PLL_ON);

}


May question may stupid for some of us but I have never used it but see for some of reasons I have to chcech 43MHz and other devices on board.

Exactly I am searching the best MHz to 57600 UART transmission (which ill generate less errors). Because my other device is 24MHz 57600 (and I can not change it).
Ttelmah



Joined: 11 Mar 2010
Posts: 19496

View user's profile Send private message

PostPosted: Mon Oct 09, 2017 12:44 am     Reply with quote

Neither.

The first is saying to use both the external crystal, and an internal oscillator.

The second programs all the clock rates incorrectly. Tells the code you are running at 32Mhz, but programs the internal oscillator for 64Mhz.

What speed are you actually trying to run at?. Do you have a crystal?. Do you want to use this for it's better accuracy?.

If you have a 16MHz crystal, then:
Code:

#use delay (crystal=16MHz, clock=64MHz)

To run at 64Hz.

57600, will have a tiny error. However do make sure your #use RS232 has BRG1OK set. If you want a really accurate figure, then use a crystal like 14.7456MHz, which will give you 58.9824MHz with the PLL, and 57600 as accurate as the crystal.
silelis



Joined: 12 Jun 2007
Posts: 68
Location: Poland, podlaskie district

View user's profile Send private message

PostPosted: Mon Oct 09, 2017 1:16 am     Reply with quote

Yes exactly. I have some problems with uart reception (some rubbish on the beggining of reception) and I want to speed up my PIC.

My slave (let say) mcu is 57600 and with PIC comunication first bytes are rubbish the last 4 byte are correct.
I know that PIC routine is correct and "slave" mcu is correct because I have made cross tests:
- PIC - FT232 (PC) - OK
- "slavve" mcu - FT232 (PC) - OK
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
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