PDA

View Full Version : Internal Oscillator and pull-up statements for 16f887



Dennis
- 22nd November 2009, 18:28
Hi all

I am copying and modifying my code to work on a 16F887 PIC (and some others later on.

Would somebody please explain how to or what to alter the following settings to.
With you help I can start doing a comparison and see how it's done so I can safely do it myself in future

[code]
'Ocsillator selections here
OSCCON = $70 'Int CLK 8MHz
OSCTUNE.6 = 1 'PLL 4x
ADCON1= %00001111 '$0F = disable A/D converter
cmcon = 7
INTCON2.7 = 0 'switch pull-ups ON
'END of oscillator selections
'timer/oscillator defines
DEFINE OSC 32 '4x 8MHz
'END of timer/oscillator defines
[code]

Any tips as always would be much appreciated

Kind regards

Dennis

Gusse
- 22nd November 2009, 19:09
Hi all

I am copying and modifying my code to work on a 16F887 PIC (and some others later on.

Would somebody please explain how to or what to alter the following settings to.
With you help I can start doing a comparison and see how it's done so I can safely do it myself in future

[code]
'Ocsillator selections here
OSCCON = $70 'Int CLK 8MHz
OSCTUNE.6 = 1 'PLL 4x
ADCON1= %00001111 '$0F = disable A/D converter
cmcon = 7
INTCON2.7 = 0 'switch pull-ups ON
'END of oscillator selections
'timer/oscillator defines
DEFINE OSC 32 '4x 8MHz
'END of timer/oscillator defines
[code]

Any tips as always would be much appreciated

Kind regards

Dennis

First, download manual (http://ww1.microchip.com/downloads/en/DeviceDoc/41291F.pdf)!

This PIC support max. 8MHz internal oscillator, so you can forget 4x PLL.

OSCCON, check "4.2 Oscillator Control"
Digital IO, check ANSEL "3.2.1 ANSEL REGISTER"
Pull-ups, check OPTION_REG "2.2.2.2 OPTION Register"
Comparators, check "8.0 COMPARATOR MODULE"
DEFINE OSC 8

This is best way to learn :)

BR,
-Gusse-

Dennis
- 22nd November 2009, 19:46
Gusse

Thanks a million :-)
Already have the manual .. just wasn't sure and don't want to mess up and later have to trouble-shoot for ages.

Definitely what I am looking for though ...thank you!

Just a quick question regarding the 8MHZ oscialltor...(this is probably a silly questionbut...)
If I am going to be transmitting suing something like serout or debug from one PIC to another , first by wire(directly connected) and then by using wireless modules, would both PICS have to have the same internal oscillator setting ?
I have been sifting through many a thread on here and notice most people make the mistake of adding wireless TX and RX before they have tested using PIC to PIC communications.
I have been reading different code snippets and threads and noticed the various different oscillator settings as per each persons code and PIC.
then we come to the baud rate and so forth.
From what I have PICked up timing starts becomeing an issue at higher baud rates and whether you are going to using things alike HSER as opposed to debug or serin/out and serin/out 2.

Any thoughts ?

Kind regards

Dennis

Dennis
- 22nd November 2009, 22:37
Hi Gusse

Is this looking better ?

Not sure of the Comparator setting ??



@__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF

'Ocsillator selections here
'OSCCON = %01100001 for 4mhz, or OSCCON = %01110001for 8mhz
OSCCON = %01110001 'Int CLK 8MHz
ANSEL= %11111111 '$0F = disable A/D converter
cm1con = 1
option_reg = 7 'switch pull-ups ON
'END of oscillator selections
'timer/oscillator defines
define osc 8 '8MHz
'END of timer/oscillator defines

Gusse
- 23rd November 2009, 15:25
Hi Dennis,

I would try with following settings.

<code><font color="#008000">@__config _INTRC_OSC_NOCLKOUT &amp; _WDT_OFF &amp; _MCLRE_ON &amp; _LVP_OFF &amp; _CP_OFF

</font>OSCCON = %01110001 <font color="#000080"><i>'Int CLK 8MHz
</i></font>ANSEL = %00000000 <font color="#000080"><i>'All digital
</i></font>OPTION_REG.7 = 0 <font color="#000080"><i>'Weak pull-ups enabled

</i></font><b>DEFINE </b>OSC 8 <font color="#000080"><i>'8MHz</i></font></code>

Comparators are disabled at POR, no need to disable twice.

BR,
-Gusse-

Dennis
- 23rd November 2009, 18:59
HI Gusse

MCS won't allow a compile ....
It seems to have a problem with this line


@__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF

In particular with the first path or the line it seems ...
Here's the error
Warning [205]...Found directive in column 1.(__config)
Error [126] c:......argument out of range (not a valid config register)
:-(
Should I rather set those in the include file ?
And what about the comparator ? Haven't quite master the way to disable it , the manual mentions CMxCON...

Kind regards

Dennis

Dennis
- 23rd November 2009, 19:15
Check the include file 16f887.inc
and it has this line in any way ...


@__config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF


So I left the line out of the code since there's no need to replicate the config lines.... or am I wrong ?

Now what about the option to disable the onboard comparators ?

Kind regards

Dennis

Gusse
- 23rd November 2009, 21:41
I have never included fuses to PicBasic code, always modified INC-files.
Delete line from code and check that you have following line in 16F887.INC


__config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF

Comparators are off after Power On Reset (POR), so if you haven't enabled those, then they are disabled.

BR,
-Gusse-

Dennis
- 23rd November 2009, 21:47
Thank you for the guidance and help !!

I have all set in the include file now! :-)

All is working just fine :-)

Kind regards

Dennis

Gusse
- 23rd November 2009, 21:55
Nice to follow your project :)
Good Luck!

BR,
-Gusse-

Dennis
- 23rd November 2009, 22:40
Cool thanks Gusse :-)

You can find more info here.

I need to first solve the TX/RX issue , then sort out the keystroke captures and then make it wireless :-)

Eventually I would like to try and make it an RF,IR remote. And maybe a little more added to it as time goes by ;-)


Well let's see how far I get with it ;-)

Kind regards

Dennis

Archangel
- 26th November 2009, 21:25
I have never included fuses to PicBasic code, always modified INC-files.
Delete line from code and check that you have following line in 16F887.INC


__config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF

Comparators are off after Power On Reset (POR), so if you haven't enabled those, then they are disabled.

BR,
-Gusse-
I never Fail to include them. To include the configs in your code, open the .inc file and install a semicolon just before the default config so,


__config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
becomes


;__config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_ON & _LVP_OFF & _CP_OFF
save it and start including them in your code without error. This way you can quickly adjust them, if you want to change something.

Dennis
- 26th November 2009, 22:06
Hi Joe

Thanks a million for the reply and advice :-) ,much appreciated !

Kind regards
Dennis