Define oscillator speed


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2011
    Posts
    17

    Default Define oscillator speed

    Hello,

    I have small project using PIC18F26K22 with 8MHz crystal external oscillator. USART output from PIC is connected over TTL to USB and I use TERMITE serial software to read data from PIC.

    I wanna send numbers from 1-255 over USART with a pause of 1 sec.

    From pbp manual it state that for every other external oscillator I need to use DEFINE OSC, for my example DEFINE OSC 8.

    Code:
     DEFINE OSC 8
    
    define HSER_BAUD 9600
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    define HSER2_BAUD 9600
    DEFINE HSER2_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER2_TXSTA 20h ' Enable transmit, BRGH = 0
    DEFINE HSER2_CLROERR 1 ' Clear overflow automatically
    
    ANSELC = 0
    
    
    i var word
    i = 0
    tajmer var byte
    
    start:
        i = i+ 1
        Hserout2 [dec i,13,10]
        pause 1000
    
    goto start
    Since pause is in millisecond this should give me 1 sec delay. But this delay last to to long over my serial terminal.

    I have tried many things and find it only working if I add this line:

    Code:
    #config
     CONFIG FOSC = HSHP
    #endconfig
    When using this confing pause 1000 is really 1 sec. I think with this command I have disabled internal oscillator.

    When I look deeper in datasheet it is said that HSHP is best for high power oscillator >16MHz and for oscillators used from 4MHz - 16MHz should be used HSMP.

    When I used

    Code:
    #config
     CONFIG FOSC = HSMP
    #endconfig
    again my pause 1000 is not 1 sec.

    Any help, advice, correction ?

    Thx

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


    Did you find this post helpful? Yes | No

    Default Re: Define oscillator speed

    default config
    Code:
    #CONFIG
      CONFIG  FOSC = INTIO67
      CONFIG  PLLCFG = OFF
      CONFIG  PRICLKEN = OFF
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = OFF
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5
      CONFIG  HFOFST = ON
      CONFIG  T3CMX = PORTC0
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG


    Default output frequency of HFINTOSC on Reset.
    HFINTOSC/16 – (1 MHz)(3)


    DEFINE OSC 8


    does absolutely nothing but advise the compiler what freq to base timing calculations on

    to use ext xtal


    Code:
    #CONFIG
      CONFIG  FOSC = HSHP
      CONFIG  PLLCFG = OFF
      CONFIG  PRICLKEN = OFF
      CONFIG  FCMEN = OFF
      CONFIG  IESO = OFF
      CONFIG  PWRTEN = OFF
      CONFIG  BOREN = SBORDIS
      CONFIG  BORV = 190
      CONFIG  WDTEN = ON
      CONFIG  WDTPS = 32768
      CONFIG  CCP2MX = PORTC1
      CONFIG  PBADEN = OFF
      CONFIG  CCP3MX = PORTB5
      CONFIG  HFOFST = ON
      CONFIG  T3CMX = PORTC0
      CONFIG  P2BMX = PORTB5
      CONFIG  MCLRE = EXTMCLR
      CONFIG  STVREN = ON
      CONFIG  LVP = OFF
      CONFIG  XINST = OFF
      CONFIG  DEBUG = OFF
      CONFIG  CP0 = OFF
      CONFIG  CP1 = OFF
      CONFIG  CP2 = OFF
      CONFIG  CP3 = OFF
      CONFIG  CPB = OFF
      CONFIG  CPD = OFF
      CONFIG  WRT0 = OFF
      CONFIG  WRT1 = OFF
      CONFIG  WRT2 = OFF
      CONFIG  WRT3 = OFF
      CONFIG  WRTC = OFF
      CONFIG  WRTB = OFF
      CONFIG  WRTD = OFF
      CONFIG  EBTR0 = OFF
      CONFIG  EBTR1 = OFF
      CONFIG  EBTR2 = OFF
      CONFIG  EBTR3 = OFF
      CONFIG  EBTRB = OFF
    #ENDCONFIG
    Warning I'm not a teacher

Similar Threads

  1. Replies: 2
    Last Post: - 25th July 2012, 03:19
  2. High Speed Oscillator question
    By Tina10 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th July 2012, 11:29
  3. Replies: 0
    Last Post: - 7th August 2008, 10:02
  4. Using PIC16F88 oscillator as oscillator for other ICs
    By Torael_7 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 30th March 2008, 13:58
  5. Define for extern oscillator
    By Mugelpower in forum PBP Wish List
    Replies: 3
    Last Post: - 22nd February 2008, 16:35

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