PDA

View Full Version : Define oscillator speed



CipiCips
- 8th August 2016, 13:31
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.


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:


#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


#config
CONFIG FOSC = HSMP
#endconfig

again my pause 1000 is not 1 sec.

Any help, advice, correction ?

Thx

richard
- 8th August 2016, 13:51
default config

#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



#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