16F887 20Mhz External Clock Problems


Closed Thread
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2005
    Posts
    96

    Thumbs down 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.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Try turning on the Power Up Timer enable...
    Caps on the crystal?
    Caps across Vdd and Vss pins?

  3. #3
    Join Date
    Apr 2005
    Posts
    96


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    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...

  5. #5


    Did you find this post helpful? Yes | No

    Default 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
    Last edited by BrianT; - 2nd September 2008 at 05:14. Reason: typo

  6. #6
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    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.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    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...

  8. #8


    Did you find this post helpful? Yes | No

    Default Thanks Joe & Skimask

    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

  9. #9
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    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
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Data Out From External Clock
    By Quin in forum Serial
    Replies: 2
    Last Post: - 25th October 2008, 09:11
  2. external clock / internal clock
    By grounded in forum General
    Replies: 4
    Last Post: - 31st May 2008, 17:44
  3. Problems with driving external EEPROM M24256
    By Kristjan in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 10th February 2008, 11:34
  4. External clock
    By Firegod in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th March 2007, 00:53
  5. How to set external clock source in PBP
    By TurboLS in forum mel PIC BASIC Pro
    Replies: 28
    Last Post: - 19th February 2005, 15:56

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts