16F887 20Mhz External Clock Problems
For some reason I can't get an external oscillator to work on a 16F887 using the following code:
[code/]DEFINE OSC 20
'SETUP PIC FUSES
@ __config _CONFIG1, _DEBUG_OFF & _LVP_OFF & _FCMEN_OFF & _IESO_OFF & _BOR_ON & _CPD_ON & _CP_ON &_MCLRE_ON & _PWRTE_OFF & _WDT_ON & _HS_OSC
ADCON0.0=0
'PORT A
ANSEL= %00000000
ANSELH=%00000000
PORTA= %00000000
TRISA= %00000000
'PORT B
PORTB= %00000000
TRISB= %00000000
WPUB= %00000000
IOCB= %00000000
'PORT C
PORTC= %00000000
TRISC= %00000000
'Port D
PORTD= %00000000
TRISD= %00000000
'PORT E
PORTE= %00000000
TRISE= %00000000
CM1CON0.7=0 'turn off comparator1
CM2CON0.7=0 'turn off comparator2
main:
porta.1=1
pause 200
porta.1=0
pause 200
goto main
[/code]
If I turn the "Fail-Safe Clock Monitor" on the chip it will default to the internal 4-mhz oscillator and my led will blink.
Any help getting the 20Mhz to work is appreciated.
Resonators at 20 MHz - bad kama IMHO
I have had very intermittent results with 20 Mhz 3 leg resonators. 4 MHz resonators work every time on every chip I have tried but 20 MHz units have been most disappointing. A few work, most don't. I have tried HS and XT settings but the answer is always the same - intermittent working and bulk frustration.
Go for the appropriate cut crystal, preferably with the recommended capacitors and I reckon your clock problems will vanish. I have just soldered the crystal into the outer pin positions of the resonator PCB footprint and left the capacitors off and over the last 5 years or more have never had a unit run significantly off frequency.
HTH
BrianT