Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Oscillator settings for 18F4550

Status
Not open for further replies.

hkBattousai

Advanced Member level 4
Joined
Jun 16, 2007
Messages
118
Helped
5
Reputation
10
Reaction score
1
Trophy points
1,298
Location
Turkey
Activity points
2,182
18f4550 internal oscillator

I'm quite new to PIC programming. This morning I designed my first PIC based circuit using an online tutorial which simply flashes a led.

The circuit used the internal oscillator of the PIC. But I want to use an external crystal oscillator.

I'm using MPLAB IDE 8.10, assembly language, and the the configuration part of my code is as below :
Code:
CONFIG WDT = OFF			; Disable watchdog timer
CONFIG MCLRE = ON			; MCLEAR Pin on
CONFIG DEBUG = ON			; Enable Debug Mode
CONFIG LVP = OFF			; Low-Voltage programming disabled (necessary for debugging)
CONFIG FOSC = INTOSCIO_EC	; Internal oscillator, port function on RA6

I think there has to be a modification in the last line, but I couldn't find out what to do after a long Google search.
Can somebody help me on this?



And I have one more thing to ask,
Assembly language is quite mind boggling when dealing with complicated projets. Sometimes I see people writing C code for PIC projects on the net. What IDE they use? Does MPLAB support PIC C? Please guide me.

Any help will be appreciated.
 

18f4550 configuration bits

There are several settings for external oscillators depending on type used.
see data sheet sheet for explanation.

See p18f4550.inc file for config settings . Search for "Oscillator Selection bits" and you will see the config statements for oscillators.

For C programing go to Microchip site and search for C18 and you will find their compilier for this chip. Download the free student version. Install and it will integrate into MPLAb for you.
Most sample code you will find for this chip is in C.

There are also other free compliers that integrate into mplab.

George
 

    hkBattousai

    Points: 2
    Helpful Answer Positive Rating
xt oscillator

Thank you very much George.

I realized that I included the wrong header; P18F45J50.INC instead of P18F4550.INC. I don't know the difference, but I know that the previous one was not the rightful header file.

The header file has the following CONFIG directives in it relevant with the oscillation circuit :
Code:
;   Oscillator Selection bits:
;     FOSC = XT_XT         XT oscillator, XT used by USB
;     FOSC = XTPLL_XT      XT oscillator, PLL enabled, XT used by USB
;     FOSC = ECIO_EC       External clock, port function on RA6, EC used by USB
;     FOSC = EC_EC         External clock, CLKOUT on RA6, EC used by USB
;     FOSC = ECPLLIO_EC    External clock,PLL enabled, port function on RA6,EC used by USB
;     FOSC = ECPLL_EC      External clock, PLL enabled, CLKOUT on RA6, EC used by USB
;     FOSC = INTOSCIO_EC   Internal oscillator, port function on RA6, EC used by USB
;     FOSC = INTOSC_EC     Internal oscillator, CLKOUT on RA6, EC used by USB
;     FOSC = INTOSC_XT     Internal oscillator, XT used by USB
;     FOSC = INTOSC_HS     Internal oscillator, HS used by USB
;     FOSC = HS            HS oscillator, HS used by USB
;     FOSC = HSPLL_HS      HS oscillator, PLL enabled, HS used by USB

I have changed the FOSC setting to XT_XT, and reprogrammed my PIC. But it didn't work :(. I don't understand what I am doing wrong :?:.


By the way, I found the C compiler and downloading currently. Thank you for the advice.
 

18f4550 config

It may be a really stupid question, but did you connect a crystal to your PIC?
Another point is that XT configuration is for oscillators less than 10MHz. If you use a quartz of 10MHz or more, you should use HS configuration.
 
oscillator settings

bld said:
It may be a really stupid question, but did you connect a crystal to your PIC?
Another point is that XT configuration is for oscillators less than 10MHz. If you use a quartz of 10MHz or more, you should use HS configuration.
Yes, of course I did. I tried two different 20MHz crystals, and tried both 15pF and 20pF capacitor pairs with them.
 

18f4550 configuration

Try using HS Oscillator, PLL enabled, HS used bu USB.
I use this all the time with 20MHz crystals.

The config locations for my settings are as follows
0E24
1E39
0100
0081
C00F
E00F
400F
 

    hkBattousai

    Points: 2
    Helpful Answer Positive Rating
configuration bits 18f4550

u must untick here
 

    hkBattousai

    Points: 2
    Helpful Answer Positive Rating
hs oscillator

bld said:
Another point is that XT configuration is for oscillators less than 10MHz. If you use a quartz of 10MHz or more, you should use HS configuration.
I'm going to try this as soon as I arrive home. Thank you for your help.


Colbhaidh said:
Try using HS Oscillator, PLL enabled, HS used bu USB.
I use this all the time with 20MHz crystals.

The config locations for my settings are as follows
0E24
1E39
0100
0081
C00F
E00F
400F
How can I load these configuration bits in my PIC?
Through the programmer kit or in my source code?


vikrambgholap said:
u must untick here
Thank you for the image, but I think there's a problem. It is not displayed.
 

18f4550 fosc

How can I load these configuration bits in my PIC?
Through the programmer kit or in my source code?

I may recommend you to load the configuration words in the code, using CONFIG directive. I always set the configuration words in the code.
 

p18f4550 programmer

bld said:
I may recommend you to load the configuration words in the code, using CONFIG directive. I always set the configuration words in the code.
But how?

Is that something like this? :
Code:
CONFIG 0E24
CONFIG 1E39
CONFIG 0100
CONFIG 0081
CONFIG C00F
CONFIG E00F
CONFIG 400F

Can you tell me how to load this bits both in assembly and C please?
 

18f4550 oscillator

Try the following.....

config FOSC = HSPLL_H ; HS with PLL enabled used by CPU and USB
config PLLDIV = 5 ; PLL prescaler 20/5=4 MHz (96MHz PLL needs
;4 MHz from prescaler)
config CPUDIV = OSC1_PLL2 ; PLL divided by 2 (96/2=48MHz) to feed CPU;
config USBDIV = 2 ; if full speed (FSEN=1) USB is fed by PLL
; divided by 2 (96/2=48MHz)
config IESO = OFF
config PWRT = OFF
config BOR = OFF
config BORV = 2.0
config VREGEN = ON
config WDT = OFF
config WDTPS = 32768
config MCLRE = ON
config LPT1OSC = OFF
config PBADEN = OFF
config CCP2MX = ON
config STVREN = ON
config LVP = OFF
config ICPRT = OFF
config XINST = OFF
config DEBUG = OFF
config CP0 = OFF
config CP1 = OFF
config CP2 = OFF
config CPB = OFF
config CPD = OFF
config WRT0 = OFF
config WRT1 = OFF
config WRT2 = OFF
config WRT3 = OFF
config WRTB = OFF
config WRTC = OFF
config WRTD = OFF
config EBTR0 = OFF
config EBTR1 = OFF
config EBTR2 = OFF
config EBTRB = OFF
 

    hkBattousai

    Points: 2
    Helpful Answer Positive Rating
how to set external oscillator in p18f4550

Fo example, like this:

Code:
	__CONFIG _CONFIG1L, _PLLDIV_5_1L & _CPUDIV_OSC3_PLL4_1L & _USBDIV_2_1L
	__CONFIG _CONFIG1H, _FOSC_HSPLL_HS_1H & _FCMEM_OFF_1H & _IESO_OFF_1H 
	__CONFIG _CONFIG2L, _PWRT_ON_2L & _BOR_OFF_2L ; _VREGEN_OFF_2L
	__CONFIG _CONFIG2H, _WDT_OFF_2H & _WDTPS_1_2H 
	__CONFIG _CONFIG3H, _MCLRE_ON_3H & _PBADEN_OFF_3H & _CCP2MX_OFF_3H
	__CONFIG _CONFIG4L, _DEBUG_OFF_4L & _LVP_OFF_4L & _STVREN_OFF_4L & _XINST_OFF_4L
	__CONFIG _CONFIG5L, _CP0_OFF_5L & _CP1_OFF_5L & _CP2_OFF_5L
	__CONFIG _CONFIG5H, _CPB_OFF_5H & _CPD_OFF_5H
	__CONFIG _CONFIG6L, _WRT0_OFF_6L & _WRT1_OFF_6L & _WRT2_OFF_6L & _WRT3_OFF_6L
	__CONFIG _CONFIG6H, _WRTB_OFF_6H & _WRTC_OFF_6H & _WRTD_OFF_6H
	__CONFIG _CONFIG7L, _EBTR0_OFF_7L & _EBTR1_OFF_7L & _EBTR2_OFF_7L & _EBTR3_OFF_7L
	__CONFIG _CONFIG7H, _EBTRB_OFF_7H

Take care! I didn't check if the code above it's exactly the configuration you need, I have just given you an example.
 

    hkBattousai

    Points: 2
    Helpful Answer Positive Rating
config fosc = intoscio_ec

Yes, but I think you are using an older version of MPASM. I believe the __CONFIG statement has been retired. On the other hand- maybe I am using the older version, I'll check....
 

intoscio_ec

Yes...__CONFIG has been replaced by CONFIG (without 2 leading underscores.) But I could compile the code using __CONFIG with the latest MPLAB.
 

internal oscillator 18f4550

After a long delay I'm back with my project...

Colbhaidh said:
Try the following.....

config FOSC = HSPLL_H ; HS with PLL enabled used by CPU and USB
config PLLDIV = 5 ; PLL prescaler 20/5=4 MHz (96MHz PLL needs
;4 MHz from prescaler)
config CPUDIV = OSC1_PLL2 ; PLL divided by 2 (96/2=48MHz) to feed CPU;
config USBDIV = 2 ; if full speed (FSEN=1) USB is fed by PLL
; divided by 2 (96/2=48MHz)
config IESO = OFF
config PWRT = OFF
config BOR = OFF
config BORV = 2.0
config VREGEN = ON
config WDT = OFF
config WDTPS = 32768
config MCLRE = ON
config LPT1OSC = OFF
config PBADEN = OFF
config CCP2MX = ON
config STVREN = ON
config LVP = OFF
config ICPRT = OFF
config XINST = OFF
config DEBUG = OFF
config CP0 = OFF
config CP1 = OFF
config CP2 = OFF
config CPB = OFF
config CPD = OFF
config WRT0 = OFF
config WRT1 = OFF
config WRT2 = OFF
config WRT3 = OFF
config WRTB = OFF
config WRTC = OFF
config WRTD = OFF
config EBTR0 = OFF
config EBTR1 = OFF
config EBTR2 = OFF
config EBTRB = OFF

Colbhaidh, I did the configuration settings just as you suggested. MPLAB gives error on the directives
config FOSC = HSPLL_H
and
config BORV = 2.0

The first one has a letter error. I corrected it to
config FOSC = HSPLL_HS
and commented out the the line below :
config BORV = 2.0
I hope I didn't ruin anything by these two changes.

Result is amazing, it works.


My errounous configuration settings (the ones which didn't work with crystal oscillator) were :
Code:
CONFIG WDT=OFF			; disable watchdog timer
CONFIG MCLRE = ON			; MCLEAR Pin on
CONFIG DEBUG = ON			; Enable Debug Mode
CONFIG LVP = OFF			;Low-Voltage programming disabled (necessary for debugging)
CONFIG FOSC = HSPLL_HS	; HS oscillator, PLL enabled, HS used by USB

Why didn't my code work but Colbhaidh's work?
Did I miss some crucial CONFIG directives?
Any help will be appreciated.
 

fosc configuration setting

Why didn't my code work but Colbhaidh's work?
Did I miss some crucial CONFIG directives?
Any help will be appreciated.

I can see 2 differences that may be important:

1) You didn't set DEBUG bit to OFF. I think it's not OFF by default ( I may be wrong, you can check).
2) You selected FOSC = HSPLL_HS but you didn't configure PLLDIV, CPUDIV and USBDIV.

I think one or all of these "forgotten" configuration could make your code to stuck.

Added after 7 minutes:

and commented out the the line below :
config BORV = 2.0

I may suggest you:

config BORV = _BORV_0_2L

Other valid values are:
_BORV_1_2L
_BORV_2_2L
_BORV_3_2L

Another advice. In the folder where you installed mplab, search for P18F4550.INC file. You can find a lot of usefull information in that file. That file is the source for my answers to your questions :)
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top