PDA

View Full Version : 16F887 20Mhz External Clock Problems



modifyit
- 2nd September 2008, 03:23
For some reason I can't get an external oscillator to work on a 16F887 using the following 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


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.

skimask
- 2nd September 2008, 03:36
Try turning on the Power Up Timer enable...
Caps on the crystal?
Caps across Vdd and Vss pins?

modifyit
- 2nd September 2008, 03:48
Thanks,

I've got bypass caps on the Vss and Vdd
I'm using a resonator so I don't think caps are needed
I've tried the Power on Timer and it did not help

any other thoughts? I feel like I am missing something simple

skimask
- 2nd September 2008, 04:01
Does the resonator have 2 legs or 3?
2 legs (haven't seen many, but haven't looked either) needs caps and grounds.
3 legs needs a ground...

BrianT
- 2nd September 2008, 04:21
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

Archangel
- 2nd September 2008, 04:39
Hello,
With all due respect to Brian T. I have no problems whatsoever with the 3 leg resonators, and use 20 mhz almost exclusively. Where I have had problems is from old breadboards. The higher the Frequency, the more affected the circuit is by corrosion, moisture, long lead length induced problems, and just plain funk. If you have to use longish wires to the resonator, then twist them, it seems to help. Make sure your power supply is up to the job and do not forget to tie up the MCLR and tie down any loose inputs. Do not run wires in parallel with the ones going to the resonator, as the added capacitance may load down the OSC.

skimask
- 2nd September 2008, 05:01
Echo'ing Joe's reply...
Slower resonators (i.e. <8Mhz)...no problems on the messy/quicky boards...
Faster resonators (i.e. above 10Mhz or so)... Gotta be a clean set up, good solder joints, short runs, clean power, and so on...

BrianT
- 2nd September 2008, 05:14
I almost always prototype my designs piece by piece on solderless breadboards. That is probably why I am getting dodgy results with fast resonators.

If the solderless version does not work I am most reluctant to build a pcb on the wish that it might with a better layout. I also use a couple of general purpose boards like those from OLIMEX and my own designs but these all have crystals.

thanks
BrianT

Acetronics2
- 3rd September 2008, 13:11
Hi,

Some idea here ???




4.6 Clock Switching
The system clock source can be switched between
external and internal clock sources via software using
the System Clock Select (SCS) bit of the OSCCON
register.
4.6.1 SYSTEM CLOCK SELECT (SCS) BIT
The System Clock Select (SCS) bit of the OSCCON
register selects the system clock source that is used for
the CPU and peripherals.
• When the SCS bit of the OSCCON register = 0,
the system clock source is determined by
configuration of the FOSC<2:0> bits in the
Configuration Word Register 1 (CONFIG1).
• When the SCS bit of the OSCCON register = 1,
the system clock source is chosen by the internal
oscillator frequency selected by the IRCF<2:0>
bits of the OSCCON register. After a Reset, the
SCS bit of the OSCCON register is always
cleared



Alain