how to use external crystal?


Closed Thread
Results 1 to 27 of 27

Hybrid View

  1. #1
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: how to use external crystal?

    I'm sure there are many variations and I appreciate you adding one. My point was that the config statement

    #config
    __config1 _FOSC_HS & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF & _WRT_OFF
    #endconfig
    doesn't look like the one in the manual. There are space at the beginning of the line __config and after each & that are not in the config statement above. I realize the config statement is ASM and therefore only the fuse is case sensitive but I thought it at least worth the effort.

    The manual also shows #CONFIG/#ENDCONFIG in caps. Just sayin'.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

    Default Re: how to use external crystal?

    for pbp3
    #CONFIG
    __config _CONFIG1, _HS_OSC & _WDT_ON & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF & _DEBUG_OFF
    __config _CONFIG2, _BOR40V & _WRT_OFF
    #ENDCONFIG


    for pbp 2.6
    ASM
    __config _CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF & _DEBUG_OFF
    __config _CONFIG2, _BOR40V & _WRT_OFF
    ENDASM

    I tried #CONFIG/#ENDCONFIG and #config/#endconfig and both work therefore its not case sensitive


    this is just wrong for a PIC16F886
    #config
    __config1 _FOSC_HS & _WDTE_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOREN_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF & _WRT_OFF
    #endconfig
    ps
    I'm surprised it can compile
    Last edited by richard; - 9th March 2015 at 00:28. Reason: ps OPPS MAKE IT HS_OSC

  3. #3
    Join Date
    Oct 2014
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: how to use external crystal?

    Thanks for this. I'm using pbp3 so I copied and pasted and it compiled. The program still doesn't seem to time correctly tho, which I describe below.
    -- How did you know this was the correct configuration? I've read many threads, tried many different suggestions including some that use @ DEVICE. I've looked in the manual and went by its examples. The manual comes close but it has a couple spaces before the CONFIG, which it shows in caps and yours is lowercase. This is what I get when I type it in:

    #CONFIG
    __config _CONFIG1, _HS_OSC & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _CP_OFF & _CPD_OFF & _BOR_ON & _IESO_ON & _FCMEN_ON & _LVP_OFF & _DEBUG_OFF
    __config _CONFIG2, _BOR40V & _WRT_OFF
    #endconfig

    Note that CONFIG is uppercase and endconfig is lowercase, tho when I cut and pasted the code they were both uppercase. Go figure.

    How did you know your code would work? Trial and error? Is there a book you can recommend? I spent hours and hours getting nowhere.

    ----------------------------------

    To test the timing I toggle a bit and look at it with a scope. This is the code:
    portb.7 = 0
    PAUSEUS 100
    portb.7 = 1
    PAUSEUS 100
    portb.7 = 0
    pauseus 100
    portb.7 = 1
    PAUSEUS 100
    portb.7 = 0
    pauseus 100
    portb.7 = 1
    pauseus 100
    portb.7 = 0

    I have OSCCON set to select the external crystal and define the oscillator as 20:
    OSCCON = %01111110 'runs at 20 MHz set in configuration bits

    define OSC 20

    (again the word define is lowercase in pbp but copies and pastes as uppercase, tho I show it ias it appears on pbp)

    I expect
    portb.7 to toggle at 100usec high, 100usec low. Instead it is 250usec hi/lo. It's as if the pic is running at 8MHz but doing the timing calculations at 20MHz.

    What am I missing?

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

    Default Re: how to use external crystal?

    (again the word define is lowercase in pbp but copies and pastes as uppercase, tho I show it ias it appears on pbp)
    don't trust copy and paste for case sensitive defines

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


    Did you find this post helpful? Yes | No

    Default Re: how to use external crystal?

    Quote Originally Posted by tbarania View Post

    (again the word define is lowercase in pbp but copies and pastes as uppercase, tho I show it ias it appears on pbp)


    What am I missing?
    Micro Code Studio is changing what you see, whereas what you copy paste is what you have. To fix this, open MCS and click the tab marked view, then click Editor Options,in Options click the tab Highlighter Options, at the bottom you will see Reserved Word Formatting, click the checkbox marked "DEFAULT" and click OK to close the box.
    Last edited by Archangel; - 9th March 2015 at 15:07.
    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.

Similar Threads

  1. 1 x external crystal oscillator for multiple PICs
    By harryweb in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th November 2013, 14:05
  2. Help using this crystal?
    By Kamikaze47 in forum General
    Replies: 5
    Last Post: - 14th November 2009, 14:48
  3. 16f877A and tmr1 external crystal question
    By comwarrior in forum General
    Replies: 3
    Last Post: - 13th July 2009, 00:40
  4. Pic or Crystal
    By jetpr in forum General
    Replies: 2
    Last Post: - 16th September 2008, 01:56
  5. Crystal
    By leonel in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 12th April 2005, 16:05

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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