how to use external crystal?


Closed Thread
Results 1 to 27 of 27

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default Re: how to use external crystal?

    in your pbp3 folders you have a directory "DEVICE_REFERENCE"
    there is a file in there for every pic chip that pbp can pgm , that file lists the correct config syntax for each chip
    or just download the meCONGIG.EXE utility from the melabs web site

    you should google "read modify write error" and search this forum for tips also


    portb.7 = 0
    PAUSEUS 100
    portb.7 = 1
    PAUSEUS 100
    portb.7 = 0
    is just asking for trouble @20mhz

    portb = 0
    PAUSEUS 100
    portb = 128
    PAUSEUS 100
    portb = 0

    is much more likely to work

  2. #2
    Join Date
    Oct 2014
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: how to use external crystal?

    Thanks for your reply.

    1. Changing to portb =128 doesn't have an impact on anything.

    2. I don't seem to have the file "Device Reference". I'm running version 5.0.0.5 compiler version 3.0.7.4. I can't find that file on the disk either.

    3. When I change to "define OSC 8" instead of "OSC 20" then the timing works correctly. This would imply the pic is running on its internal 8MHz clock and is ignoring the OSCCON's setting to use the external crystal. It's as if the configuration "fuses" are just that, fuses. Once set they can't be reset. Or maybe the pic is defective.

    4. I tried a new pic but it gave the same results.

    5. MPLAB shows the correct configuration bits. HS oscillator is indeed selected.

    6. I changed OSCCON to 01101110 to set the internal oscillator to 4 MHz. It did indeed change the clock to 4 MHz as observed on the scope. Bit 0 of OSCCON is supposed to select the external clock source but it is not.

    7. On the off chance bit 0 of OSCCON should be a 1 to select the external crystal I changed it to a 1 but the result is the same. It's as if that bit is being ignored.


    This is what I have at the beginning of the code:


    #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




    OSCCON = %01101110 'runs at 20 MHz set in configuration bits

    DEFINE OSC 20 '20 MHz CLOCK FREQUENCY
    define HSER_RCSTA 90h 'enable the serial port receiver
    define HSER_TXSTA 24h 'set up the serial port, enable transmit for fast clock. TXSTA 00100100
    define HSER_BAUD 19200 'select the baud rate, run fast
    define HSER_CLROERR 1 'automatically clear the buffer overrun error

    define ADC_BITS 10 '10 bits
    define ADC_SAMPLEUS 50 '50usec sampling time
    DEFINE ADC_CLOCK 3 'set clock source to RC


    volts var word 'power supply volts
    amps var word 'power supply amps
    tempr var word 'temperature
    ticks var word 'radiation ticks, made up of timer 1's counter bytes
    command var byte 'the command byte
    action var byte 'the action byte, what to do
    stattus var byte 'contains the power supply status information
    dungate var byte 'status flag to indicate the count has been recorded & counter cleared


    GATE var portb.4 'label for the gate input
    TRIG var portc.0 'label for the ticks input
    TEMPRP VAR portc.1 'temperature pulsewidth input
    ONOFF var portc.3 'dc/dc on/off bit. On = 1
    beat var portb.7 'heartbeat monitor


    ADCON0 = %11000000 'set ADC clock to RC
    ADCON1 = %10000000 'right justify the result in ARESH:ADRESL registers. Vref=Vdd
    ANSEL = %00000011 'set AN0 and AN1 as analog
    ANSELH = %00000000 'set AN8 and higher to digital
    TRISA = %11111111 'set up port A as all inputs
    TRISB = %01111111 'set up port B as all inputs except for RB7 which is a heartbeat monitor output
    TRISC = %10110111 'set up port C where 1 = input

  3. #3
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: how to use external crystal?

    The "Device Reference" is not a file, it is a subdirectory under your PBP3 directory.

    If you installed PBP3 under your root directory then this would be "C:\PBP3\DEVICE_REFERENCE".
    If it is installed in the default location then it should be here: "C:\Program Files\PBP3\DEVICE_REFERENCE".
    The "file" would be the PIC device file located in the "DEVICE_REFERENCE" subdirectory with a ".INFO" extension.
    For the 16F886 this would be "PIC16F886.INFO"

    Also, just curious when you use MPLAB and the PICKSTART PRO programmer, after programming the PIC have you tried reading back from the PIC and checking if the config bits are set?
    Regards,
    TABSoft

  4. #4
    Join Date
    Oct 2014
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Re: how to use external crystal?

    I don't have any "device.reference" subdirectory associated with pbp3. Maybe I need to uninstall and reinstall the software.

    When I read the device after programming it doesn't list the config memory location 2007. All the registers read 0 so not sure if osccon is being set correctly.


    Also, I get a ASM warning: found directive in column 1. (__config)
    When I indent 1 space it goes away. Not sure if that matters.


    I'm at a loss on what to try next. It seems like it is ignoring config and osccon and just operating at default conditions. I can select the internal oscillator frequency with osccon but I can 't get it to run in external crystal mode. I am in trouble if I can't get this to work.




    This is the beginning of the .asm listing if that gives any information: (also, how do I make a scrolling code window within this reply?)


    ; PICBASIC PRO(TM) Compiler 3.0.7.4, (c) 1998, 2013 microEngineering Labs, Inc. All Rights Reserved.
    MPASMWIN_USED EQU 1

    #define PBP_PATH C:\PBP3\




    NOLIST
    ifdef PM_USED
    LIST
    include 'M16F88x.INC' ; PM header
    XALL
    NOLIST
    else
    LIST
    LIST p = 16F886, r = dec, w = -302, c = 255
    INCLUDE "P16F886.INC" ; MPASM Header
    NOLIST
    endif
    LIST


    PBP_HARDWAREDEF macro
    endm


    __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



    ; Define statements.
    ; C:\PBP3\DEVICES\PIC16F886.PBPINC 00172 DEFINE CODE_SIZE 8
    #define CODE_SIZE 8
    ; C:\USERS\TBARANIA\DOCUMENTS\MY DOCUMENTS\WEATHER STATION TOWER\7725_RADIATION SENSOR_GEIGER\GEIGER.PBP 00028 define OSC 20 '20 MHz CLOCK FREQUENCY
    #define OSC 20

  5. #5
    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?

    On page 100 of the manual it shows listing the config fuses in a different format than you've been using. Could be worth trying.

    In the above you've got #define OSC 20 and you need to get rid of the pound sign. I'm assuming that would be the same for the code-size statement also.

    You could also do most of the above with the CONFIG1=xxxxxxxx and CONFIG2=xxxxxxxx. Something else to try maybe.

    Just a few thoughts that may be horribly bad.

  6. #6
    Join Date
    Oct 2011
    Location
    Pennsylvania
    Posts
    13


    Did you find this post helpful? Yes | No

    Default Re: how to use external crystal?

    What happens if you turn _IESO_ON to _IESO_OFF ? In CONFIG of course. Is there a way to detect if the crystal oscillates?

  7. #7
    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 found this and thought it might help http://ww1.microchip.com/downloads/e...efinitions.pdf. It might be of interest.

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