PDA

View Full Version : 18F1320 question



Charlie
- 10th March 2014, 05:00
I'm using an 18F1320 with it's internal oscillator. I've got a basic blink program running, but the clock seems to be running very slowly and nothing I change in the OSCCON register changes the clock. Is there something in the config registers or somewhere else I'm missing that overrides the values in OSCCON? 2 Hours of reading and experimenting is getting hard on my hair - thanks for any clues!

Aussie Barry
- 10th March 2014, 07:37
What do you have your OSCCON set at?
The main output is an 8MHZ clock which can be varied from 125kHz to 4MHz via the postscaler.
Have you defined the clock speed in your program to match that set by OSCCON?
Example: if you have the INTOSC set at 8MHZ then you should include the define

DEFINE OSC 8

at the beginning of your program.

To help more we would need to see your actual code to help debug the problem.

Cheers
Barry
VK2XBP

Charlie
- 10th March 2014, 10:48
Thanks, Barry. If you read what I originally posted you will see that you can set OSCCON to any postscaler value and the behaviour does not change.
And yes, I read the documentation - I know how it is supposed to work.

The actual code is not going to help this time, but sure:

OSCCON = $11110011
DEFINE OSC 8
CLEAR
ADCON1 = 0
Startup:
TRISA = 0
PORTA.1 = 1
pause 10
PORTA.1 = 0
pause 10
goto startup
end

The LED on PORTA.1 is blinking just slightly faster than once per second, when it should be so fast you don't even see it blinking.

So to repeat the original question: Is there something in the config registers or somewhere else I'm missing that overrides the values in OSCCON?

Dave
- 10th March 2014, 11:21
I have one question. Why are you setting the TRIS register each time thru the loop?

Aussie Barry
- 10th March 2014, 11:40
Try changing your OSCCON statement to:

OSCCON = %11110011

Cheers
Barry
VK2XBP

Charlie
- 10th March 2014, 12:23
I'm totally embarrassed. Snookered by a typo. Thanks, Barry.

Aussie Barry
- 10th March 2014, 23:03
I guess the "actual code" was able to help after all...

Cheers
Barry
VK2XBP

Charlie
- 11th March 2014, 00:18
Official chastising accepted - please pass the crow. :biggrin:

Aussie Barry
- 11th March 2014, 10:57
Hahaha - Sorry, couldn't help myself...
All good :D

Cheers
Barry
VK2XBP