Author Topic: PIC16F and OSCTUN  (Read 4415 times)

0 Members and 1 Guest are viewing this topic.

Offline S53SGTopic starter

  • Newbie
  • Posts: 5
  • Country: si
PIC16F and OSCTUN
« on: September 29, 2016, 11:48:12 am »
Hello everyone on EEVBlog,

I am trying to get out of PIC16F1704 clock generator on 460kHz - so, I set the INTOSC on 2MHz, and fuse to CLKOUT EN (output is Fsys/4).
In PIC there is OSCTUN register which can tune the internal clock oscillator - in Microchip document AN244 is written;
Quote
OSCTUNE is responsible for tuning the frequency
within a range of +/-12 percent on the selected
frequency
So, depend on this, there shouldn't be a problem to set on wished frequency CLKOUT, but I tried with code below, which supposed to set the OSC to minimum (theoretically 440kHz?); but it isn't - the CLKOUT lowest value is 488kHz!
What I am doing wrong here?
Thanks a lot!

Code: [Select]
    OSCCONbits.IRCF = 0b1100; //2 MHz INT CLOCK
    OSCCONbits.SCS = 0b10;
    while (OSCSTATbits.HFIOFR == 0); //wait for stable
    OSCTUNEbits.TUN = 0b100000;
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4099
  • Country: us
Re: PIC16F and OSCTUN
« Reply #1 on: September 29, 2016, 12:57:01 pm »
If you get 500KHz at 0x00 and about 512kHz at 0x1f, I think you got your answer. You're doing it right and the datasheet is either lying or it's not specifying that there is huge tolerance range on this "+-12%" deal. :)

Most of the people screwing with OSCTUNE would be using it to fine tune the device for error of factory calibration.... so if it moves plus or minus 2%, that's more than enough.  :-//

*Edit:
Wait a sec.
Set clock to 500kHz and enable 4xPLL.

Now you can quadruple the amount that OSCTUNE can adjust, right? ...That will still leave you short a bit.

* edit edit:
duh, nermind.

Besides all this, I am curious what page you are reading this +-12% figure.
« Last Edit: September 29, 2016, 01:23:30 pm by KL27x »
 

Offline Wilksey

  • Super Contributor
  • ***
  • Posts: 1329
Re: PIC16F and OSCTUN
« Reply #2 on: September 29, 2016, 12:59:49 pm »
If you set the center frequency (OSCTUNE = 0) does the frequency come out at 500kHz bang on?

The datasheet states that the internal 500kHz can drift by 2%, still, it should be lower than it is.
 

Offline KL27x

  • Super Contributor
  • ***
  • Posts: 4099
  • Country: us
Re: PIC16F and OSCTUN
« Reply #3 on: September 29, 2016, 01:16:12 pm »
I find a curious mistake in my 1936 datasheet....

OSCTUNE is same as your device, with 6 bit value for OSCTUNE. High 2 bits are unused.
clearly states under the OSCTUNE section
b'100000' is the min   (0x20)
b'011111' is the max  (0x1F)

BUT, in the prior text description it says that
Min value is at 0x10
Max value is at 0x0F

.... Which is describing OSCTUNE as if it is only 5 bits.....  :-//

Worth a shot trying to use 0x10? just Maybe? :)
« Last Edit: September 29, 2016, 01:20:49 pm by KL27x »
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1638
  • Country: nl
Re: PIC16F and OSCTUN
« Reply #4 on: September 29, 2016, 01:39:18 pm »
Just want to point out that the AN244 is an application note for completely different, much outdated, chips. I wouldn't be surprised that with better oscillator modules the need for a +/-12% adjustment range has diminished and new chips only need like +/-2.5% (which fits nicely over the +/-2% factory tolerance)..

I read the PIC16F1704 datasheet, and it points out everywhere OSCTUNE is 6-bits wide, 0x20 is the lowest frequency and 0x1F is the highest frequency.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12856
Re: PIC16F and OSCTUN
« Reply #5 on: September 29, 2016, 02:45:40 pm »
Use a CCP module with PR2 of 16 to generate a PWM with Fosc=32MHz, then pull FOSC 2.3% slower using OSCTUNE to get it down from 470KHz to 460Khz.
 

Offline S53SGTopic starter

  • Newbie
  • Posts: 5
  • Country: si
Re: PIC16F and OSCTUN
« Reply #6 on: September 29, 2016, 06:04:09 pm »
Thanks for replies!
To be more detailed; I need cheap clock source for HART modem on 460.8kHz - but there is no requirement to be very accuracy on full temperature range, because I need HART only for for load some setting via HART after assembly and casted PCB.
Okay, I see that the idea with OSCTUNE is not feasible, so another possible option is by Ian.M, with CCP module (in combination with OSCTUN anyway, to get as close as possible wished frequency). Thank you for this suggestion.
The only problem here can be the power consumption in this way, but over the thumb I think it should be under the limitation.
Anyway, backup solution is the 1.8432MHz crystal, but this is not desired because of its size.
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: PIC16F and OSCTUN
« Reply #7 on: September 29, 2016, 07:28:36 pm »
a range of +/-12 percent on the selected
where exactly did you read that? older parts would write percentage and theoretical frequency along the value, in the datasheet.
newer parts don't

(also tune range is a 6 bit 2-complement number)
« Last Edit: September 29, 2016, 07:30:18 pm by JPortici »
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: PIC16F and OSCTUN
« Reply #8 on: September 30, 2016, 01:31:27 am »
Quote
within a range of +/-12 percent

That would be a little too coarse.
================================
https://dannyelectronics.wordpress.com/
 

Offline S53SGTopic starter

  • Newbie
  • Posts: 5
  • Country: si
Re: PIC16F and OSCTUN
« Reply #9 on: September 30, 2016, 05:32:17 am »
JPortici; here: http://ww1.microchip.com/downloads/en/AppNotes/00244a.pdf
In datasheet is nothing described more detailed about this...  :o
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: PIC16F and OSCTUN
« Reply #10 on: September 30, 2016, 05:42:49 am »
always refer to the datasheet.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf