PDA

View Full Version : 18f2550 oscillator problems



rjones2102
- 24th September 2007, 16:03
Hi all,

I am running an 18f2550 using internal oscillator. I have a timing problem that causes the program to run what I believe is 4 times slower than it should.

I have the following fuses set in 18f255.inc in the PBP directory.

__CONFIG _CONFIG1L, _PLLDIV_1_1L
__CONFIG _CONFIG1H, _FOSC_INTOSCIO_EC_1H
__CONFIG _CONFIG2H, _WDT_ON_2H & _WDTPS_512_2H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L

I have the following code running on chip.

OSCCON=%01100000
DEFINE OSC 4
TRISA=%0000000
ADCON1 = 7 ' A/D off, all digital
high PORTA.5
pause 1000
low PORTA.5
pause 1000
high PORTA.5

I am sure the LED on PORTA.5 is staying on for 4 seconds and then goes off for 4 seconds before finally coming back on. What am I doing wrong?

rjones2102
- 24th September 2007, 16:07
Sorry, I should also have said I am using MPASM

Ronald123
- 24th September 2007, 18:44
Hi,

Try to set de _PLLDIV_1_1L to _PLLDIV_5_1L. This is also the setting when I'm using USB on the 18F2550 with a 20MHz oscillator.

Regards,
Ronald.

mister_e
- 24th September 2007, 19:00
i'll bet on


__CONFIG _CONFIG1L, _PLLDIV_1_1L & _CPUDIV_OSC1_PLL2_1L

mackrackit
- 24th September 2007, 19:18
INTOSCIO ??? How about INTCKO instead.

Try -- OSCCON=%01111100

mister_e
- 24th September 2007, 22:44
:eek: INTCKO is not a valid fuse in my current MPASM version (5.11) for the 18F2550


;----- CONFIG1H Options --------------------------------------------------
_FOSC_XT_XT_1H EQU H'F0' ; XT oscillator, XT used by USB
_FOSC_XTPLL_XT_1H EQU H'F2' ; XT oscillator, PLL enabled, XT used by USB
_FOSC_ECIO_EC_1H EQU H'F4' ; External clock, port function on RA6, EC used by USB
_FOSC_EC_EC_1H EQU H'F5' ; External clock, CLKOUT on RA6, EC used by USB
_FOSC_ECPLLIO_EC_1H EQU H'F6' ; External clock, PLL enabled, port function on RA6, EC used by USB
_FOSC_ECPLL_EC_1H EQU H'F7' ; External clock, PLL enabled, CLKOUT on RA6, EC used by USB
_FOSC_INTOSCIO_EC_1H EQU H'F8' ; Internal oscillator, port function on RA6, EC used by USB
_FOSC_INTOSC_EC_1H EQU H'F9' ; Internal oscillator, CLKOUT on RA6, EC used by USB
_FOSC_INTOSC_XT_1H EQU H'FA' ; Internal oscillator, XT used by USB
_FOSC_INTOSC_HS_1H EQU H'FB' ; Internal oscillator, HS used by USB
_FOSC_HS_1H EQU H'FC' ; HS oscillator, HS used by USB
_FOSC_HSPLL_HS_1H EQU H'FE' ; HS oscillator, PLL enabled, HS used by USB


and the OSCCON was right in the first post.

Sorry mackrackit :(

mackrackit
- 25th September 2007, 00:28
:eek: INTCKO is not a valid fuse in my current MPASM version (5.11) for the 18F2550


;----- CONFIG1H Options --------------------------------------------------
_FOSC_XT_XT_1H EQU H'F0' ; XT oscillator, XT used by USB
_FOSC_XTPLL_XT_1H EQU H'F2' ; XT oscillator, PLL enabled, XT used by USB
_FOSC_ECIO_EC_1H EQU H'F4' ; External clock, port function on RA6, EC used by USB
_FOSC_EC_EC_1H EQU H'F5' ; External clock, CLKOUT on RA6, EC used by USB
_FOSC_ECPLLIO_EC_1H EQU H'F6' ; External clock, PLL enabled, port function on RA6, EC used by USB
_FOSC_ECPLL_EC_1H EQU H'F7' ; External clock, PLL enabled, CLKOUT on RA6, EC used by USB
_FOSC_INTOSCIO_EC_1H EQU H'F8' ; Internal oscillator, port function on RA6, EC used by USB
_FOSC_INTOSC_EC_1H EQU H'F9' ; Internal oscillator, CLKOUT on RA6, EC used by USB
_FOSC_INTOSC_XT_1H EQU H'FA' ; Internal oscillator, XT used by USB
_FOSC_INTOSC_HS_1H EQU H'FB' ; Internal oscillator, HS used by USB
_FOSC_HS_1H EQU H'FC' ; HS oscillator, HS used by USB
_FOSC_HSPLL_HS_1H EQU H'FE' ; HS oscillator, PLL enabled, HS used by USB


and the OSCCON was right in the first post.

Sorry mackrackit :(

I goofed on on OSCCOM --%01101100 is what I meant, bit 2+3 turned on.

INTCKO:eek: Ever have ONE OF THOSE DAYS when.... Thanks for letting me know that I am having one.

mister_e
- 25th September 2007, 03:11
and then ... bit 2+3 are read-Only... so writing 1 or 0 on these won't change anything... sorry again :(


Ever have ONE OF THOSE DAYS when.... Thanks for letting me know that I am having one.

Oh... trust me... i really understand... i recently have more than day(s) like that... count them in weeks and months....

mackrackit
- 25th September 2007, 06:14
and then ... bit 2+3 are read-Only... so writing 1 or 0 on these won't change anything... sorry again :(


Well I have got bigger problems than I thought. I am trying to learn the 18F4320 and I realize you can read bits 2+3 , but the only way I can get the chip to run correctly is to set them high.

Must have been a fluke, now I am going to try them low. I have only done a couple of projects with this chip.

Just tried it on a data logger I am working on, now bits 2+3 do not make a difference.

Learn something every day:D Thank you Mr.E

mister_e
- 25th September 2007, 22:17
:D nice! You're welcome.

Don't worry, we all learn new thing every day with those nifty black pinned boxes.

Thanks to internet, forums and various Gurus all 'round the world. Really nice toolssssssssss!

rjones2102
- 27th September 2007, 12:59
Hey guys,

Thanks so much for your input. Much appreciated. _CPUDIV_OSC1_PLL2_1L fixed it. I now have the same problem on a 16f88 that I was trying to use with internal osc. It ran about 10 times slower than it should. I can't find any fuses relating to PLL. I was out of internet range (I work on a boat) so I put a resonator in the circuit and fixed it that way. Strange to have the same problem with 2 different chips when there is absolutely no relationship between the problems!! Well, there must be a fuse somewhere I can't recognise!

Thanks again

Rich

mister_e
- 27th September 2007, 13:10
well it's more than set a fuse, you also need to set the internal OSC register. Open the datasheet under OSCCON Section. If my memory serves me well, the default value is set to 32KHz

And then if my memory still serves me well
OSCCON=%01100000 ' will set the internal osc to 4MHz
OSCCON=%01110000 ' will set the internal osc to 8MHz

rjones2102
- 28th September 2007, 01:23
Thanks Mr_e!

I actually tried 8mhz and 4mhz internal using the following settings:

DEFINE OSC 8
OSCCON=%01110000

DEFINE OSC 4
OSCCON=%01100000

My fuse setting was INTRC. I can't find anything else of relevance to osc speed in fuses. It's not a major problem as ultimately I will use a 20mhz crystal but it would enhance my understanding for future projects to be able to use the internal osc.

Cheers

Rich

mackrackit
- 28th September 2007, 03:57
Just a thought, have you read this? Post #6
http://www.picbasic.co.uk/forum/showthread.php?p=13087#post13087#post6