How to check oscillator frequency


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Jun 2007
    Posts
    56

    Default How to check oscillator frequency

    Hi all,

    I'd like to know how to check that the osccilator is working as requested. I mean how do I know exactly that the external crystal is working at 8 Mhz

    I made some experiment with 18F4431, the program run well with internal oscilator setup 4Mhz, but it does not function when I switch to external crystal
    I am using easypic 4 board.

    Thanks,

    Johan

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Johan View Post
    Hi all,
    I'd like to know how to check that the osccilator is working as requested. I mean how do I know exactly that the external crystal is working at 8 Mhz
    I made some experiment with 18F4431, the program run well with internal oscilator setup 4Mhz, but it does not function when I switch to external crystal
    I am using easypic 4 board.
    Thanks,
    Johan
    Are you sure the config bits are set correctly in your program?

  3. #3
    Join Date
    Jun 2007
    Posts
    56


    Did you find this post helpful? Yes | No

    Default

    What config bits needed to set up ?
    This is my test program , please correct if it is not correct:

    \code
    TRISA = %11111111 ' Set PORTA to all input
    TRISB = %00000000 ' Set PORTB to all output
    TRISC = %00000000 ' Set PORTC to all input
    TRISD = %00000000 ' Set PORTD to all output
    TRISE = %00000000 ' Set PORTE to all output
    ANSEL0= %00000000 ' Analog channel AN0-AN7 off
    ANSEL1= %00000000 ' Analog channel AN8 off

    clear

    main:
    high portb.1
    pause 1000
    low portb.1
    pause 1000
    goto main

    \code

    the oscillator setting during programming with picflash is:
    oscillator : int ra6 & ra7 as i/o
    other setting left unchanged

    thanks

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    yeah... it run but the default OSC speed is set to 32KHz

    just add those
    Code:
    OSCCON= %01100000       ' configure internal OSC  @ 4MHZ
    While OSCCON.2=0 : wend ' wait until OSC is stable
    at the top of your code.

    For the configuration bits, it's usual and recommended to set them in your code, have a look at the following...

    http://www.picbasic.co.uk/forum/showthread.php?t=543

    and here's a short example for a 18F2431, as inspiration source
    Code:
            '
            '       Pic Configuration
            '       =================
            ASM         
            __CONFIG _CONFIG1H, _OSC_IRCIO_1H  & _FCMEN_OFF_1H & _IESO_OFF_1H
            __CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_ON_2L & _BORV_45_2L
            __CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WINEN_OFF_2H 
            __CONFIG _CONFIG3L, _T1OSCMX_OFF_3L & _HPOL_LOW_3L & _LPOL_HIGH_3L & _PWMPIN_OFF_3L
            __CONFIG _CONFIG3H, _MCLRE_ON_3H
            __CONFIG _CONFIG4L, _LVP_OFF_4L & _DEBUG_OFF_4L
            ENDASM
            DEFINE OSC 4
    Now if you want to switch to the external OSC, use...
    Code:
            ASM         
            __CONFIG _CONFIG1H, _OSC_HS_1H  & _FCMEN_OFF_1H & _IESO_OFF_1H
            __CONFIG _CONFIG2L, _PWRTEN_ON_2L & _BOREN_ON_2L & _BORV_45_2L
            __CONFIG _CONFIG2H, _WDTEN_OFF_2H & _WINEN_OFF_2H 
            __CONFIG _CONFIG3L, _T1OSCMX_OFF_3L & _HPOL_LOW_3L & _LPOL_HIGH_3L & _PWMPIN_OFF_3L
            __CONFIG _CONFIG3H, _MCLRE_ON_3H
            __CONFIG _CONFIG4L, _LVP_OFF_4L & _DEBUG_OFF_4L
            ENDASM
            DEFINE OSC 8
    and remove the OSCCON & WHILE : WEND lines
    Last edited by mister_e; - 11th July 2007 at 05:46.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  5. #5
    Join Date
    Jun 2007
    Posts
    56


    Did you find this post helpful? Yes | No

    Default

    Thank you Mr.E,

    On my programmer's setup page ( easypic ) there are configuration bits to setup ( see attachment ) . If I put the configuration at PBP, will this be a problem ?
    Attached Images Attached Images  

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Nope, there's no problem at all. In fact, if you set the bits in your code, you'll no longer need to set them in Picflash as they're now included in the .HEX file.

    Try the above, a click on 'Reload HEX'. You'll see that the Oscillator bit have change to HS or INT RC... depending which code above you have used.

    I also have that board. Can't live without now
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    Join Date
    Jun 2007
    Posts
    56


    Did you find this post helpful? Yes | No

    Default

    Mr.E,

    I tried to put those asm lines, and got error messages :
    Error 118 bla,bla,bla : Overwriting previous address content

    But my problem is solved just by adding : define OSC 8

Similar Threads

  1. TMR1 external LP xtal setup check
    By comwarrior in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th October 2009, 18:11
  2. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  3. PIC16F877A - Timer0 won't interrupt
    By WishMaster^ in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 25th April 2007, 08:25
  4. Code check -- button not working
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 2nd March 2006, 22:43
  5. Even Parity Check, How?
    By Mark Scotford in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th January 2005, 09:21

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