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

setup_oscillator()

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



Joined: 16 Dec 2004
Posts: 3
Location: Minneapolis, MN

View user's profile Send private message

setup_oscillator()
PostPosted: Wed Jun 29, 2005 11:01 am     Reply with quote

I'm using the latest compiler (3.226), but the help file doesn't include setup_oscillator. I'm looking at the 18F8490.h device file at the oscillator section and am wondering which bits some of these constants set/clear.
Code:

////////////////////////////////////////////////////////////////// INTERNAL RC
// Constants used in setup_oscillator() are:
// First param:
#define OSC_31KHZ   0
#define OSC_125KHZ  0x10
#define OSC_250KHZ  0x20
#define OSC_500KHZ  0x30
#define OSC_1MHZ    0x40
#define OSC_2MHZ    0x50
#define OSC_4MHZ    0x60
#define OSC_8MHZ    0x70
// The following may be OR'ed in with the above using |
#define OSC_TIMER1  1
#define OSC_INTRC   2
#define OSC_NORMAL  0
// The following may be OR'ed in with the above using |
#define OSC_IDLE_MODE  0x80
#define OSC_31250   0x80
#define OSC_PLL_ON  0x40
#define OSC_PLL_OFF 0
// A second optional parameter may be used with this part to fine
// tune the speed (signed int,0-31)
// Result may be (ignore all other bits)
#define OSC_STATE_STABLE 4
#define OSC_STATE_EXT_RUNNING 8


Specifically, the OSC_IDLE_MODE option and the OSC_31250 option.

I am using this line:
setup_oscillator(OSC_1MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
This was produced by the wizard. I would assume that OSC_31250 selects between the prescaled internal 8MHz clock and the RC used by the WDT and has no effect when running at 1MHz. But this line of code writes 0xC2 to the OSCCON register which means that idle mode is entered with the SLEEP instruction.

The LST file includes:
Code:

....................    setup_oscillator(OSC_1MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF); 
00E0:  MOVLW  C2
00E2:  MOVWF  FD3


Am I reading this all correctly? I'll admit this is my first use of an 18F-series part, so I'm still coming up to speed.

What I'm after is to use the internal RC oscillator at 1MHz (for now), no PLL, and no idle mode. I currently have #FUSES INTRC_IO set as well.

Thanks
Bradley
theMagni



Joined: 21 May 2004
Posts: 48
Location: Victoria, BC

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

PostPosted: Wed Jun 29, 2005 12:47 pm     Reply with quote

To be honest, I dislike the setup_oscillator() function. I just have OSC_CON defined and have the settings I want #defined. That way, I know exactly what it's doing. This is on a 16F88 / 18F2420. (It's great how that works out.)

#define FOUR_MHz 0b01100010
#define THIRTYTWO_kHz 0b00000010
...

OSC_CON = FOUR_MHz;

OSC_CON = THIRTYTWO_kHz;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 29, 2005 1:58 pm     Reply with quote

Quote:
I'm using the latest compiler (3.226), but the help file doesn't include setup_oscillator().

CCS has two help files in the c:\Program Files\Picc folder:

The real one is CCSC.CHM and you can identify it in Windows Explorer
by its file type, which is "Compiled HTML Help File".

They've also got an older one, CCSC.HLP in that folder, which doesn't
have setup_oscillator() in it.

Quote:
I'm looking at the 18F8490.h device file at the oscillator section
and am wondering which bits some of these constants set/clear.

The constant definitions are screwed up. I think they really should
look like this:
Code:
// Constants used in setup_oscillator() are:
// First param:
#define OSC_31KHZ   0
#define OSC_125KHZ  0x10
#define OSC_250KHZ  0x20
#define OSC_500KHZ  0x30
#define OSC_1MHZ    0x40
#define OSC_2MHZ    0x50
#define OSC_4MHZ    0x60
#define OSC_8MHZ    0x70
// The following may be OR'ed in with the above using |
#define OSC_TIMER1  1
#define OSC_INTRC   2
#define OSC_NORMAL  0
#define OSC_IDLE_MODE  0x80

//----------------------------------
// A second optional parameter may be used with this part
// to fine tune the speed (signed int,0-31)

// The following may be OR'ed in with the fine-tune bits
// of the 2nd parameter by using |
#define OSC_31250   0x80
#define OSC_PLL_ON  0x40
#define OSC_PLL_OFF 0

//------------------------------------------
// Result may be (ignore all other bits)
#define OSC_STATE_STABLE 4
#define OSC_STATE_EXT_RUNNING 8

Also, CCS implies that setup_oscillator() will return a value.
I tried to have the function return a value with a 16F88 (which
does have the "frequency stable" bit) and the compiler gave
me an error. So the "Result" part of the definitions above
are not really useful.
BradleyEE



Joined: 16 Dec 2004
Posts: 3
Location: Minneapolis, MN

View user's profile Send private message

PostPosted: Wed Jun 29, 2005 5:04 pm     Reply with quote

PCM programmer wrote:

Code:
// Constants used in setup_oscillator() are:
// First param:
#define OSC_31KHZ   0
#define OSC_125KHZ  0x10
#define OSC_250KHZ  0x20
#define OSC_500KHZ  0x30
#define OSC_1MHZ    0x40
#define OSC_2MHZ    0x50
#define OSC_4MHZ    0x60
#define OSC_8MHZ    0x70
// The following may be OR'ed in with the above using |
#define OSC_TIMER1  1
#define OSC_INTRC   2
#define OSC_NORMAL  0
#define OSC_IDLE_MODE  0x80

//----------------------------------
// A second optional parameter may be used with this part
// to fine tune the speed (signed int,0-31)

// The following may be OR'ed in with the fine-tune bits
// of the 2nd parameter by using |
#define OSC_31250   0x80
#define OSC_PLL_ON  0x40
#define OSC_PLL_OFF 0

//------------------------------------------
// Result may be (ignore all other bits)
#define OSC_STATE_STABLE 4
#define OSC_STATE_EXT_RUNNING 8

Also, CCS implies that setup_oscillator() will return a value.
I tried to have the function return a value with a 16F88 (which
does have the "frequency stable" bit) and the compiler gave
me an error. So the "Result" part of the definitions above
are not really useful.


Good call. The OSC_31250 is the same as the OSC_IDLE_MODE, which is why that was being set. I suppose I should send a bug report via email about this. Got rid of the OSC_31250 and the OSC_PLL_OFF (it's zero anyway) and now the assembly for that line is coming out to what I would expect.

Thanks
Bradley
BradleyEE



Joined: 16 Dec 2004
Posts: 3
Location: Minneapolis, MN

View user's profile Send private message

PostPosted: Wed Jun 29, 2005 5:07 pm     Reply with quote

theMagni wrote:
To be honest, I dislike the setup_oscillator() function. I just have OSC_CON defined and have the settings I want #defined. That way, I know exactly what it's doing. This is on a 16F88 / 18F2420. (It's great how that works out.)

#define FOUR_MHz 0b01100010
#define THIRTYTWO_kHz 0b00000010
...

OSC_CON = FOUR_MHz;

OSC_CON = THIRTYTWO_kHz;


Yes, I'm leaning towards doing the same thing. I have some some reservations because it seems that some directives and functions will occasionally interact.

The next question I'm going to have is going to be about setup_lcd(), but perhaps I'll just roll my own configuration routines so that I know that (and how) they work.

Thanks
Bradley
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 29, 2005 5:13 pm     Reply with quote

The problem is not really that the constants are the same,
its rather that CCS didn't make it clear that some of the
constants are to be used with the 1st parameter and
others are only to be used with the 2nd parameter of
the setup_oscillator() function.
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