CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

INTOSC drift at cold temps...Recalibrate using OSCTUNE???

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fdirosa



Joined: 08 Sep 2006
Posts: 2

View user's profile Send private message

INTOSC drift at cold temps...Recalibrate using OSCTUNE???
PostPosted: Thu Apr 05, 2007 2:23 pm     Reply with quote

I am using a PIC16F767 (EXT) which using the internal oscillator as it's main clock source (I know, you are asking why? Not my choice, I inherited this design, probably because of cost). I am also using the AUSART plus another S/W UART to communicate between the PIC and PC. All is well at room temp all the way down to 0 deg C. Somewhere below that the serial com starts getting dirty. I believe it is because the baud rate changes due to the internal oscillator drifting really bad at cold temps. I was wondering if anyone has written a calibration routine that uses TIMER1 and the INTRC oscillator as a reference frequency using the CCS compiler. There seems to be less of a drift spec'd for the INTRC osc than the ones spec'd for the INTOSC. Microchip has a routine that does this in a ASM file but I don't think I can use it with the CCS compiler. Anyone care to port it for me? I tried and will keep trying but I am unfamiliar with the ASM portion of ccs and it's limitation, such as declaring the variables in asm (maybe I can't in ccs, I don't know.).

http://ww1.microchip.com/downloads/en/AppNotes/00244a.pdf

I am using PCM version 4.010

Any help in this would be greatly appreciated. Thanks.
kevcon



Joined: 21 Feb 2007
Posts: 142
Location: Michigan, USA

View user's profile Send private message

PostPosted: Thu Apr 05, 2007 2:50 pm     Reply with quote

This method requires an external 32Khz oscillator.


Quote:

The ability to calibrate the internal oscillator means that
a known time-base must be established as a reference
point. This time-base will be derived from a 32.768 kHz
clock crystal connected to Timer1 (see Figure 1). Other
fixed time-bases that can be used are AC line
frequency (50 or 60 Hz).
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Fri Apr 06, 2007 3:13 pm     Reply with quote

I think you're on the right track. The datasheet says the INTOSC will vary +/-10% over temperature extremes (from -40ºC to +85ºC). This will most definetly screw-up your comms.

The good thing is that OSCTUNE allows +/-12.5% of tunability from center frequency. What does this mean? It means you have the ability to tune-out the frequency drift over temperature.


How would this be done? I will give you my simplistic approach on how to do this.

The datasheet states that the tuning constant is linear over its entire range ("tuning sensitivity is constant throughout the tuning range"). This means that you have 8-bits which span a 25% tuning range. This equals (almost) 0.1%/bit (8kHz/bit for 8MHz clock). The temperature drift can be assumed to be constant over temperature (i.e. x%/ºC). All you need now is the value of x (this you can do by measuring the CLOCKOUT Frequency at two temperature points), and the value of temperature (the easiest way to do this is to have the PIC read a temp sensor). At this point you can calculate as follows (note that the actual code will depend on the sensor and format).
Code:
OSCTUNE = (temp-22ºC)*(x%/0.1%)
Probably you want everything in signed integers.
Nuvistor
Guest







PostPosted: Fri Apr 06, 2007 3:49 pm     Reply with quote

Did the bean counters do this ?
I like when people remove the bypass capacitors from IC's
because they cost to much and compliance it doesn't work anymore..
Save a few cents and lose $100. Wink
fdirosa



Joined: 08 Sep 2006
Posts: 2

View user's profile Send private message

PostPosted: Mon Apr 09, 2007 7:16 am     Reply with quote

languer,

Great idea! The design already uses a temperature sensor so that will be easy to do. I know at room temp 25 C the OSCTUNE should be 0 so I can solve the equation with that in mind and try it from there. I was wondering why the 22 C and not 25 C since that is the typical temp that the PIC is calibrated at in the factory. That is, they calibrate OSCTUNE=0 at 25 Celsius.
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Mon Apr 09, 2007 6:51 pm     Reply with quote

22ºC was just the midpoint between -40ºC and +85ºC. Since OSCTUNE=0x00 is the midpoint of the the tune curve I tried to get fancy. But you're correct the oscillator is calibrated at 25ºC (thus OSCTUNE=0x00 corresponds to 25ºC).

On a side note, if you did not have an external temperature you could have used a voltage reference (the PIC's internal one is probably good) as they tend to change over temperature. Unfortunately that means you must add an external (more stable, or much less) reference to compare against. This is not trivial, but it has been done in the past (after all, many temperature sensors are based on voltage references).
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group