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

setting up oscillator

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



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

setting up oscillator
PostPosted: Sun Jan 25, 2015 3:35 am     Reply with quote

Hi everybody
i'm experimenting with this compiler.
I'm having some troubles setting oscillator.
I use 18f2550 and want to use internal 8MHz.
I tried many configurations that i found in the forum but none works good.

for example
Code:

#fuses NOPROTECT,intrc_io,NOWDT
#use delay(clock=8000000)

makes everything go slowww
Code:

#fuses NOPROTECT,intrc_io,NOWDT
#use delay(internal=8000000)

does the same
the only thing that works on time is
Code:

#fuses NOPROTECT,hs,NOWDT
#use delay(clock=1000000)

after mixing some readings , i tried to use #byte osccon 255, hoping that it would work but there is probably a syntax error.

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Jan 25, 2015 4:33 am     Reply with quote

What are you actually wanting to do with the chip?.

Understand that this chip _requires_ the external oscillator if USB is to be used.

What compiler version?.

In a thread here a few months ago, after another poster had problems, PCM_programmer found that the actual oscillator layout, does not quite match what the data sheet shows (fun....). There is actually a path from the internal oscillator MUX, to the CPUDIV fuses. These default to '11' (/4), so the poster was getting 1/4 the speed he expected.

Use:
Code:

#fuses NOPROTECT,INTRC_IO,NOWDT,CPUDIV1
#use delay(clock=8MHz, internal=8MHz)
nuclear__



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

PostPosted: Sun Jan 25, 2015 5:06 am     Reply with quote

I'm using 5.005, i tried your code too but no luck.
I'm just playing with it, i dont want to use usb or anything complex. Only rs232 ,play with lcd and blink leds!
I try to migrate from a basic compiler i have, so i go step by step.

Thats really wired . I cannt find anything more than what i try, in documentations spread around.

I think whatever i declare device works at 1 mhz .
How can i set osccon value manualy?

Thank you
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Sun Jan 25, 2015 8:27 am     Reply with quote

Seriously, 5.005, is a _beta_ version. The first working V5 compilers were at least a couple of versions later. The earliest I have kept as 'possibly working' is 5.010, so I can't do a comparison compile to find what is likely to be wrong....
guy



Joined: 21 Oct 2005
Posts: 297

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

PostPosted: Sun Jan 25, 2015 2:36 pm     Reply with quote

For internal oscillator maybe try setup_oscillator(OSC_8MHZ) inside your code for example?

I remember struggling with a PIC18F4550 to make it work with USB at the right speed with a 12MHz crystal. Eventually what worked was:
Code:

#fuses HSPLL,PLL3,CPUDIV3,NOFCMEN,NOIESO,PUT,BROWNOUT_SW,VREGEN
#fuses NOWDT,WDT32768,CCP2C1,NOPBADEN,NOLPT1OSC,STVREN,NOLVP,NOXINST
#use delay(clock=24000000) // 12Mhz xtal

Hope this helps...
nuclear__



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

PostPosted: Mon Jan 26, 2015 4:27 am     Reply with quote

Hi
It's not version problem.. A collegue that has 5.03x tested it and it did the same.
Thanks guy i will try that.
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Mon Jan 26, 2015 5:05 am     Reply with quote

Guy's code is for an external crystal at 12MHz. Won't work without the crystal.
You are using the explicit setup I posted. This has worked for me in the past.
However as Guy says, add this:
Code:

#include <18F2550.h>
#fuses NOPROTECT,INTRC_IO,NOWDT,CPUDIV1,NOPBADEN
#use delay(clock=8MHz, internal=8MHz)

void main(void)
{
    //variable declarations
    setup_oscillator(OSC_8MHZ|OSC_INTRC);
    //rest of code
    while(TRUE)
    {
       output_toggle(PIN_B0);
       delay_ms(100);
    }
}


On the 5.03x, I've seen quite a lot of problems starting to appear with the latest compilers. Currently using 5.028, as the most reliable recent release. I'd be happier if you said you had tried it on something around this area, than a .03x version....

Have just tried this on a chip, and it merrily gives 5Hz as expected.
nuclear__



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

PostPosted: Mon Jan 26, 2015 3:16 pm     Reply with quote

Ttelmah wrote:
Guy's code is for an external crystal at 12MHz. Won't work without the crystal.
You are using the explicit setup I posted. This has worked for me in the past.
However as Guy says, add this:
Code:

#include <18F2550.h>
#fuses NOPROTECT,INTRC_IO,NOWDT,CPUDIV1,NOPBADEN
#use delay(clock=8MHz, internal=8MHz)

void main(void)
{
    //variable declarations
    setup_oscillator(OSC_8MHZ|OSC_INTRC);
    //rest of code
    while(TRUE)
    {
       output_toggle(PIN_B0);
       delay_ms(100);
    }
}


On the 5.03x, I've seen quite a lot of problems starting to appear with the latest compilers. Currently using 5.028, as the most reliable recent release. I'd be happier if you said you had tried it on something around this area, than a .03x version....

Have just tried this on a chip, and it merrily gives 5Hz as expected.


Well that was enough by itself
#fuses NOPROTECT,INTRC_IO,NOWDT,CPUDIV1,NOPBADEN
#use delay(clock=8MHz, internal=8MHz)

Probably CPUDIV1 is the key.

I will go on with some experiments and reading.

Thank you all, especialy Ttelmah !
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Jan 27, 2015 8:42 am     Reply with quote

Which is what I said right at the start, and you said didn't work.
nuclear__



Joined: 24 Jan 2015
Posts: 63

View user's profile Send private message

PostPosted: Tue Jan 27, 2015 8:49 am     Reply with quote

Ttelmah wrote:
Which is what I said right at the start, and you said didn't work.

I miss this word. Confused
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Jan 27, 2015 9:44 am     Reply with quote

I think the phrase aaargh! applies!.... Smile
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