PDA

View Full Version : 16F631 and crystal problems



Luckyborg
- 31st May 2011, 23:54
I have been having problems with getting a 16F631 to operate correctly. I have tried both an internal and external oscillators. Under both circumstances the code seems to run 2 times faster or more. I have a very basic blinking LED program, 2 seconds on 2 off. I'm using PBP compiler 2.60.



@ __config _HS_OSC & _WDT_ON & _MCLRE_OFF & _CP_OFF & _IESO_OFF
'@ __config _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF & _IESO_OFF

Clear
define osc 10
'define osc 8

OSCCON = %01101110 'external 10 mhz
'OSCCON = %01111111 'internal 8 mhz

ANSEL = 0 'set port to digital
OPTION_REG.7 = 0 'enable pull ups on A and B

TRISA = %011000 '
TRISB = %11001111 '
TRISC = %11111111 '

PORTA = 0

Pause 500
fake_main:

PORTA.0 = 0
pause 2000
PORTA.0 = 1
pause 2000

goto fake_main

endThis problem is frustrating me and is probably either very obvious or very difficult.

Thanks for the help

mackrackit
- 1st June 2011, 01:38
First, it is a good idea to turn off/disable the comparators:
from the data sheet


8.2.1
COMPARATOR ENABLE
Setting the CxON bit of the CMxCON0 register enables
the comparator for operation. Clearing the CxON bit
disables the comparator resulting in minimum current
consumption.

Then, if you are using a 10MHz external, do not use the OSCCON register.
If using the internal then set OSCCON to 01110000 for 8MHz.

Archangel
- 1st June 2011, 07:08
Hello Luckyborg,
The aspstrophe ' symbol works in pbp to assign text as a comment, it supposedly does not work in assembly, and should be replaced with an semicolon ;
'@ __config _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF & _IESO_OFF
;@ __config _INTOSCIO & _WDT_ON & _MCLRE_OFF & _CP_OFF & _IESO_OFF
I would think MPASM would choke, who knows.
EDIT: also DEFINES are "supposed" to be in all UPPERCASE LETTERS

mister_e
- 1st June 2011, 07:55
The aspstrophe ' symbol works in pbp to assign text as a comment, it supposedly does not work in assembly, and should be replaced with an semicolon ;

True when it's AFTER the @ symbol or Within and ASM/ENDASM block, it doesn't apply it the current case.

But yes, OSC reswerved word HAVE TO BE IN UPPERCASE

Archangel
- 1st June 2011, 08:11
True when it's AFTER the @ symbol or Within and ASM/ENDASM block, it doesn't apply it the current case.

But yes, OSC reswerved word HAVE TO BE IN UPPERCASE
Hi Steve,
Ok so that's the Magic, before the @ it works, after it doesn't, got it . . . for now :D Getting pretty foggy behind these eyes . . .

Luckyborg
- 1st June 2011, 16:23
Thanks everyone. The problem was osc instead of OSC. The comparators are disabled on this chip by default, at least according to my 2006 preliminary datasheet I have, though I'll download the current version just to make sure nothing has changed. Can someone explain what

DEFINE osc 10 would do, or is it just ignored? I've never intentionally used a DEFINE with anything other than a reserved word. Does it behave similar to

osc CON 10Thanks again for the help. I'm very glad it was under the something obvious category.

mackrackit
- 1st June 2011, 17:23
Yup, they are off by default, that is why I said, "a good idea". One line of code to be sure.

DEFINE OSC XX 'Tells PBP the speed the chip is running at so it can calculate timing functions such as PAUSE.