PDA

View Full Version : Internal Osccillator help



Sabahan
- 22nd May 2016, 11:04
I try to use the Pic18F family of MCU,I notice that it have internal oscillator and need no external crystal oscillator,but how to set it to work?I have try it and nothing happen,the code works fine with Pic16f877a,I need the long word to process some timing input

Heckler
- 22nd May 2016, 15:06
Hi Sabahan,

I would start by going to the "device_reference" folder for PBP (what version of PBP are you using?)
C:\PBP3\DEVICE_REFERENCE

then open up the .info file for your device
inside there you should find information for what to put in your configuration statements

partial example of a .info file ...

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; File: PIC18F45K22.INFO
; Date: 07/24/11
; Generated by melabs File Manager
;
; PICBASIC PRO(tm) Compiler version: 3.0.0.x
;
; Copyright 2011 microEngineering Labs, Inc. All Rights Reserved
; The content herein is intended to facilitate embedded development using
; PICBASIC PRO Compiler. Reproduction or utilization for other purposes
; is prohibited without written permission from microEngineering Labs, Inc..
;
; microEngineering Labs, Inc.
; 2845 Ore Mill Road STE 4
; Colorado Springs, CO 80904
; 719-520-5323
; fax: 719-520-1867
; http://melabs.com
; [email protected]
;
; Modifications to this file in the \DEVICE_REFERENCE folder will be overwritten when
; you install future upgrades.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;MPASM CONFIG Directive Options
;
; This section is included for reference only. The following options may
; be used with the MPASM CONFIG directive to specify configuration settings
; in the source program using the #CONFIG/#ENDCONFIG block.
; Example:
;
; #CONFIG
; CONFIG OSC = HS
; CONFIG WDTE = ON
; #ENDCONFIG
;
;
; Oscillator Selection bits
; CONFIG FOSC = RC ;111X External RC oscillator, CLKOUT function on RA6
; CONFIG FOSC = ECLPIO6 ;EC oscillator (low power, <500 kHz)
; CONFIG FOSC = ECLP ;EC oscillator, CLKOUT function on OSC2 (low power, <500 kHz)
; CONFIG FOSC = ECMPIO6 ;EC oscillator (medium power, 500 kHz-16 MHz)
; CONFIG FOSC = ECMP ;EC oscillator, CLKOUT function on OSC2 (medium power, 500 kHz-16 MHz)
; CONFIG FOSC = INTIO7 ;Internal oscillator block, CLKOUT function on OSC2
; CONFIG FOSC = INTIO67 ;Internal oscillator block
; CONFIG FOSC = RCIO6 ;External RC oscillator
; CONFIG FOSC = RC ;External RC oscillator, CLKOUT function on OSC2
; CONFIG FOSC = ECHPIO6 ;EC oscillator (high power, >16 MHz)
; CONFIG FOSC = ECHP ;EC oscillator, CLKOUT function on OSC2 (high power, >16 MHz)
; CONFIG FOSC = HSMP ;HS oscillator (medium power 4-16 MHz)
; CONFIG FOSC = HSHP ;HS oscillator (high power > 16 MHz)
; CONFIG FOSC = XT ;XT oscillator
; CONFIG FOSC = LP ;LP oscillator
;
; 4X PLL Enable
; CONFIG PLLCFG = OFF ;Oscillator used directly
; CONFIG PLLCFG = ON ;Oscillator multiplied by 4
;
; Primary clock enable bit
; CONFIG PRICLKEN = OFF ;Primary clock can be disabled by software
; CONFIG PRICLKEN = ON ;Primary clock is always enabled
;
; Fail-Safe Clock Monitor Enable bit
; CONFIG FCMEN = OFF ;Fail-Safe Clock Monitor disabled
; CONFIG FCMEN = ON ;Fail-Safe Clock Monitor enabled
;
; Internal/External Oscillator Switchover bit
; CONFIG IESO = OFF ;Oscillator Switchover mode disabled
; CONFIG IESO = ON ;Oscillator Switchover mode enabled
;
; Power-up Timer Enable bit
; CONFIG PWRTEN = OFF ;Power up timer disabled
; CONFIG PWRTEN = ON ;Power up timer enabled
;
; Brown-out Reset Enable bits
; CONFIG BOREN = SBORDIS ;Brown-out Reset enabled in hardware only (SBOREN is disabled)
; CONFIG BOREN = NOSLP ;Brown-out Reset enabled in hardware only and disabled in Sleep mode (SBOREN is disabled)
; CONFIG BOREN = ON ;Brown-out Reset enabled and controlled by software (SBOREN is enabled)
; CONFIG BOREN = OFF ;Brown-out Reset disabled in hardware and software
;
; Brown Out Reset Voltage bits
; CONFIG BORV = 190 ;VBOR set to 1.90 V nominal
; CONFIG BORV = 220 ;VBOR set to 2.20 V nominal
; CONFIG BORV = 250 ;VBOR set to 2.50 V nominal
; CONFIG BORV = 285 ;VBOR set to 2.85 V nominal
;
; Watchdog Timer Enable bits
; CONFIG WDTEN = ON ;WDT is always enabled. SWDTEN bit has no effect
; CONFIG WDTEN = SWON ;WDT is controlled by SWDTEN bit of the WDTCON register
; CONFIG WDTEN = NOSLP ;WDT is disabled in sleep, otherwise enabled. SWDTEN bit has no effect
; CONFIG WDTEN = OFF ;Watch dog timer is always disabled. SWDTEN has no effect.
;


then at the top of your code do something like this...

#CONFIG
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_OFF & _MCLRE_OFF & _CP_ON & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_25 & _LVP_OFF
#endconfig

good luck
dwight

Heckler
- 22nd May 2016, 15:08
you can also do something like this to allow your code to compile for different processors...


#IF __PROCESSOR__ = "16F1828" or __PROCESSOR__ = "16F1829"
#CONFIG
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_ON & _PWRTE_OFF & _MCLRE_OFF & _CP_ON & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_OFF & _BORV_25 & _LVP_OFF
#endconfig
#else

#IF __PROCESSOR__ = "16F690"
#CONFIG
__CONFIG _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_OFF & _MCLRE_OFF & _CP_ON & _CPD_OFF & _BOD_OFF & _IESO_OFF & _FCMEN_OFF
#endconfig
#ELSE
#ERROR "Program does not support " + __PROCESSOR__
#ENDIF
#endif
#msg "compiling for target " + __PROCESSOR__