PIC16F and OSCTUN - Page 1
Forum section: electronics / general

author: S53SG
author_rank: Newbie
timestamp: September 29, 2016, 11:48:12 am
content: 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;QuoteSo, 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:OSCCONbits.IRCF = 0b1100; //2 MHz INT CLOCKOSCCONbits.SCS = 0b10;while (OSCSTATbits.HFIOFR == 0); //wait for stableOSCTUNEbits.TUN = 0b100000;

author: KL27x
author_rank: Super Contributor
timestamp: September 29, 2016, 12:57:01 pm
content: 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.

author: Wilksey
author_rank: Super Contributor
timestamp: September 29, 2016, 12:59:49 pm
content: 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.

author: KL27x
author_rank: Super Contributor
timestamp: September 29, 2016, 01:16:12 pm
content: 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 sectionb'100000' is the min (0x20)b'011111' is the max (0x1F)BUT, in the prior text description it says thatMin value is at 0x10Max value is at 0x0F.... Which is describing OSCTUNEas if it is only 5 bits.....Worth a shot trying to use 0x10? just Maybe?

author: hans
author_rank: Super Contributor
timestamp: September 29, 2016, 01:39:18 pm
content: 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.

author: Ian.M
author_rank: Super Contributor
timestamp: September 29, 2016, 02:45:40 pm
content: 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.

author: S53SG
author_rank: Newbie
timestamp: September 29, 2016, 06:04:09 pm
content: 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.

author: JPortici
author_rank: Super Contributor
timestamp: September 29, 2016, 07:28:36 pm
content: Quote from: S53SG on September 29, 2016, 11:48:12 amwhere 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)

author: dannyf
author_rank: Super Contributor
timestamp: September 30, 2016, 01:31:27 am
content: QuoteThat would be a little too coarse.

author: S53SG
author_rank: Newbie
timestamp: September 30, 2016, 05:32:17 am
content: JPortici; here:http://ww1.microchip.com/downloads/en/AppNotes/00244a.pdfIn datasheet is nothing described more detailed about this...

author: JPortici
author_rank: Super Contributor
timestamp: September 30, 2016, 05:42:49 am
content: always refer to the datasheet.