Log in

View Full Version : High Speed Oscillator question



Tina10
- 2nd July 2012, 10:58
I never went beyond 4MHz before but want to find out about using the 20MHz Oscillator. I have few questions as they way I did it did not produced accurate results while simulating on proteus. I did the following:

DEFINE OSC 20 ' Added this define

Under Config statement I used

_HS_OSC

I tried the following code:

Main:
Toggle LED
Pause 1000
Goto Main

My LED did not blinked @ 1 sec interval but was a bit slower.
--------------------------------------------------------------

I also tried the similar settings with 8 MHz oscillator (I used _XT_OSC in Config this time & DEFINE OSC 8) and found out that my LED again was slightly slower than 1 Sec. So my question is-:

A) Is there something I am missing to get timings right
B) Just want to confirm that once DEFINE is added correctly, all pause statements and serial commands using baud rates are written as normal as the PIC automatically adjusts the timing.

Thanks :)

HenrikOlsson
- 2nd July 2012, 12:13
The DEFINE is correct but it doesn't mean that the PIC will RUN at 20MHz. What it does is tell the compiler at what speed you INTEND to run the PIC so that it (the compiler) can calculate the proper delays for things like PAUSE, SEROUT, DEBUG etc.

It's up to you to make sure that the PIC actually gets a 20MHz clock to run from. In other words fit a 20MHz crystal etc. Now, since you're using a simulator there's probably a way to specify the clock frequency.

Archangel
- 9th July 2012, 10:29
I never went beyond 4MHz before but want to find out about using the 20MHz Oscillator. I have few questions as they way I did it did not produced accurate results while simulating on proteus. I did the following:

DEFINE OSC 20 ' Added this define

Under Config statement I used

_HS_OSC

I tried the following code:

Main:
Toggle LED
Pause 1000
Goto Main

My LED did not blinked @ 1 sec interval but was a bit slower.
--------------------------------------------------------------

I also tried the similar settings with 8 MHz oscillator (I used _XT_OSC in Config this time & DEFINE OSC 8) and found out that my LED again was slightly slower than 1 Sec. So my question is-:

A) Is there something I am missing to get timings right
B) Just want to confirm that once DEFINE is added correctly, all pause statements and serial commands using baud rates are written as normal as the PIC automatically adjusts the timing.

Thanks :)Everything Heinrick posted is right, your code should be on for 1 second and off for 1 second (2 second cycle).The chip you use may have OSCON or other way to adjust the osc. PS always use HS_OSC if using 3 term resonators at any speed . . .