Setting up the oscillator


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2006
    Location
    Glasgow, Scotland
    Posts
    26

    Default Setting up the oscillator

    Hi there everyone, I have a problem setting up the external oscillator on the following pics
    16f876a and the 18f2220

    I have programmed both with the same simple counter led display program.
    i wanted it to run faster to give me some processing time so i thought all i would need was a faster crystal which didn't work on the 16f876a so I thought I would try a 18f2220 with the original 4mh crystal or higher frequency. when i tried the program in the faster chip it ran dead slow 1 count per sec instead of the 100 per sec with the 16f876a with 4mhz crystal.

    Am I using the internal osc?
    what registers do i need to change?

    here is the code used for both pic's

    PICBASIC PRO program to demonstrate 7-segment LED display. Schematic
    ' can be found at http://melabs.com/resources/articles/ledart.htm (fig 6).

    DEFINE OSC 4
    Segments Var PORTB
    Digits Var PORTC

    i Var Byte
    n Var Byte
    Value Var Word


    TRISB = $80 ' Set segment pins to output
    TRISC = $f0 ' Set digit pins to output

    mainloop:
    For Value = 0 To 9999
    GoSub display ' Display the value
    Next Value

    GoTo mainloop ' Do it forever


    ' Subroutine to send the number (0 - 9999) in Value to LEDs
    display:
    For i = 0 To 3 ' Loop through 4 digits
    n = Value Dig i ' Get digit to display
    GoSub display1 ' Display the digit
    Pause 1 ' Leave it on 1 millisecond
    Next i ' Do next digit
    Return


    ' Surboutine to display one digit on LED
    ' i = digit number
    ' n = number to display
    display1:
    Digits = $ff ' All digits off to prevent ghosting

    ' Convert binary number in n to segments for LED
    Lookup n, [$40, $79, $24, $30, $19, $12, $02, $78, $00, $18], Segments

    ' Set digit pin i to 0 (on) and the rest of the pins to 1 (off)
    Digits = ~Dcd i

    Return

    thanks in advance John

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


    Did you find this post helpful? Yes | No

    Default

    If you want to use a faster crystal speed, let's say 20 MHz, you also need to alter the configuration fuses before programming your PIC. The most useful way, at least to me, is to set them in your code.

    For the 16F876a, make sure the part number finish with -20, unless it's possible that it doesn't work... even if many here, including me already tried it with nice results.

    To use any crystal value >4MHz, you need to set the OSC mode to HS. I suggest you to read the following thread... at VERY LEAST the first 5 posts.
    http://www.picbasic.co.uk/forum/showthread.php?t=543

    Now, for a 20MHz crystal and for a 16F876a, using MPASM, your code header should looks like
    Code:
    @        __config _HS_OSC & _WDT_OFF & _BODEN_ON & _PWRTE_ON & _LVP_OFF & _CP_OFF & _DEBUG_OFF
    
            DEFINE OSC 20
    HTH
    Steve

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

Similar Threads

  1. PBP and 18F2550
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 15th January 2012, 06:34
  2. PICKit2 - warning about configuration words
    By flotulopex in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 4th August 2009, 14:01
  3. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  4. Advice please - Warning message
    By malc-c in forum mel PIC BASIC Pro
    Replies: 50
    Last Post: - 23rd January 2007, 13:20
  5. PIC12F675, accuracy of baud rate with Internal Oscillator
    By Chris Mayhew in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st August 2005, 22:41

Members who have read this thread : 1

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