PDA

View Full Version : Settings for internal oscillator



mradde
- 9th February 2009, 12:07
How do i setup the internal oscillator?
I know i can use command "DEFINE OSC 4 (for 4mhz)".
And also in the *.inc file at PBP folder. Somthing like this:

__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L
__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H

SmugWimp
- 9th February 2009, 13:20
This would be found on the datasheet for the chip that you are working with. It will vary from chip to chip. All pic datasheets can be downloaded in PDF form from microchip (http://www.microchip.com).

Look in the index for the section called "Special Features". It will list all of those configurations (fuses) for your chip, and how they are used.

Then at the top of your PIC Basic code, use a line similar to this:

"@ device hs_OSC, wdt_on, pwrt_on, protect_off" (You "can" make the modifications in the '16Fxxx.inc' include file, but that will be a change for all projects, instead of just this one)

For setting the speed, use a define statement in your code...

DEFINE OSC 4

Again, check datasheets for correct syntax and that it works for your chip.

Cheers!

SmugWimp

Archangel
- 9th February 2009, 17:18
You will find files in the MPASM Suite subdirectory of the Microchip directory on your C: something like P16f648A.inc . Open the one for the chip you are using (do not change anything here ) and you will find all the configuration fuse settings for that chip ( that MPASM USES ) PM will use the same fuses but may spell the names a little differently, and will likely use different syntax.

RussMartin
- 9th February 2009, 17:42
It is my understanding that DEFINE OSC actually does nothing to configure the PIC's oscillator; it is used by PBP to correct time-dependent commands (PAUSE would be an example). It's also my understanding that PBP assumes 4 MHz as a default value, so a DEFINE is necessary only if a different oscillator speed is used.

To configure the internal oscillator, see the section of the data sheet entitled "Oscillator Module" or "Oscillator Configuration" or the equivalent. Recently, I've done stuff with the 12F683, the 16F628A/648A, the 16F877A, and the 16F88. Of these, three have internal oscillators and two have a register, OSCCON, to load to configure the oscillator.

For example, to use the 12F683 with its internal oscillator running at 4 MHz, I have to load that register with the statement: OSCCON=%01100000 (or $60--I've never tried decimal 96).

peterdeco1
- 9th February 2009, 19:31
Actually, on the 12F683 I use the following code and it defaults to 4MHZ

DEFINE OSCCON_1K 1
@ DEVICE MCLR_ON, INTRC_OSC_NOCLKOUT, WDT_ON, BOD_OFF, PWRT_ON, PROTECT_ON

On the 16F819 & 16F88 I use this, otherwise it defaults to the slowest speed (I think 32KHZ)
OSCCON = $60 'set int osc to 4mhz

RussMartin
- 9th February 2009, 21:53
DEFINE OSCCON_1K 1



This is a new one for me. Can you tell me more about it?--syntax and such--or direct me to more information?

And, yeah, I discovered the default-to-32 kHz thing the hard way.

Thanks!

mister_e
- 9th February 2009, 22:44
It's a new one for everyone I guess ;)

You'll have more chance to find DEFINE OSCCAL_1K, and it's explained a litlle bit in the manual.

RussMartin
- 9th February 2009, 22:59
It's a new one for everyone I guess ;)

You'll have more chance to find DEFINE OSCCAL_1K, and it's explained a litlle bit in the manual.

Yes, now that you mention it. I find it in my new manual on pp. 12 and 202.

(My old manual is the one with all the handwritten notes in it!)

But I find the explanation on p. 12 mysterious.

peterdeco1
- 10th February 2009, 18:42
Originally Posted by mister_e
It's a new one for everyone I guess

You'll have more chance to find DEFINE OSCCAL_1K, and it's explained a litlle bit in the manual.

When I use DEFINE OSCCAL_1K, generates errors. "Error C:\PBP\PBPPIC14.LIB 7448:[225] Undefined Symbol 'OSCCAL'

The only way I don't get an error is:
DEFINE OSCCON_1K 1 ' Set OSCCON for 1K device

mister_e
- 10th February 2009, 19:00
peterdeco1,
if you have this error message it indeed mean that your particular PIC doesn't have the OSCCAL register.

12F683 have an OSCCON register indeed, and it's directly accessible through your code. Some also have OSCTUNE register, this one is to tweak the internal oscillator in case you need to do so. But still, this one is also directly accessible in code and no need for DEFINEs.

DEFINE can be everything, if it's not built-in in the compiler instruction set or the spelling (Case) is wrong, it will just do nothing, hence why we already discussed about their spelling.

DEFINE MarryHadAlittleBoy_HisNameIsJerry 1

will not return any error, and obviously it will not do anything unless you use it in ASM. This is handy when you want to customized your INCLUDE/Library or feature of your program. Check my Keypad routine for example.

peterdeco1
- 10th February 2009, 19:11
Yes Steve. I did see the Osctune in the datasheet, but haven't played with it yet. I'm using the HPWM in the 12F683 and it's dead-on accurate the way it is. I'm a great believer in "If it works, don't fix it." Besides, Osctune may make me pull more hair out! Thanks.