PDA

View Full Version : OSCTUNE and 12F683



RussMartin
- 15th December 2008, 05:20
I'd like to run a 12F683 as close to 131.2 kHz as possible.

I presume I can select 125 kHz using OSCON.

But I'm not able to figure out how to use OSCTUNE (page 24 of the data sheet)--or can I even do that to get the desired result?

skimask
- 15th December 2008, 05:46
I'd like to run a 12F683 as close to 131.2 kHz as possible.
I presume I can select 125 kHz using OSCON.
But I'm not able to figure out how to use OSCTUNE (page 24 of the data sheet)--or can I even do that to get the desired result?

Should be able to do that. It doesn't say in that particular datasheet, but I seem to remember reading somewhere that OSCTUNE does about +/-12% worth of tweaking to the internal oscillator. You've got +15 and -15 steps to work with, each 'step' worth about .8% if that +/-12% total is correct.
So, presuming that the internal oscillator will actually run at exactly 125khz, you need 131.2khz, a 5% increase. 5 / .8 = 6.25, so OSCTUNE = 6 should give you +6.25% from the nominal 125Khz, which comes out to about 132.5khz.
Set your config's for INTOSC or INTOSCIO...
Set OSCCON = $11, internal oscillator selected, 125khz selected
Set OSCTUNE = 6 and assuming the config words took correctly, you should be running at 132.5khz.
And you'll probably have to change OSCTUNE by 1 or 2 in either direction to get nice and close to 131.2Khz.
If you set INTOSC instead of INTOSCIO, you should get Fosc/4 on the OSC2 pin, which in your case, you should get 32.8khz. Hope you've got a tight freq counter or a good o'scope!

RussMartin
- 15th December 2008, 06:29
If you set INTOSC instead of INTOSCIO, you should get Fosc/4 on the OSC2 pin, which in your case, you should get 32.8khz. Hope you've got a tight freq counter or a good o'scope!

Thanks for the suggestions. I don't know why I can't find what I need in the 12F683 data sheet but (as I'm sure you've noticed), Microchip's data sheets aren't always as user-friendly as they perhaps could be.

And I've got both a good (but old) frequency counter (Hewlett-Packard 5300B that last calibrated at 200 ppb) and of course I've got a scope . . . three, right now. (Although my venerable Philips PM3266 is a dinosaur.)

Interestingly, I intend to use that 32.8 kHz coming out. Although I can probably make do with anything between 32 and 34 kHz, so the tuning may not be as fussy as I am.

Again, thanks.

skimask
- 15th December 2008, 11:51
Interestingly, I intend to use that 32.8 kHz coming out. Although I can probably make do with anything between 32 and 34 kHz, so the tuning may not be as fussy as I am.
It might be more accurate to run the PIC as fast as you can (8Mhz on the internal) and write a blinky LED to give you ~32khz on a single pin.


main: led (whatever pin) = 1
pauseus 29
led = 0
pauseus 28
goto main

1 cycle for each LED=x statement, 2 cycles for goto, 57 cycles for each pause = 61 cycles total.
8Mhz / 4 = 2 MIPS / 61 cycles = 32,768 Hz.
Then, between changing the pauseus values, and tweaking OSCTUNE, you should get dead-on exactly what you really want.