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

Internal Oscillator calibration

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



Joined: 15 Mar 2004
Posts: 33
Location: Swiss

View user's profile Send private message Visit poster's website ICQ Number

Internal Oscillator calibration
PostPosted: Thu Aug 25, 2005 4:06 am     Reply with quote

Hello All.
Internal Oscillator calibration

I wonder if you explain what to do with Internal Oscillator calibration byte.
I have application where I use Internal Oscillator and application is very time critical.

I use in my software for PIC12F269 code like:
#use delay(clock=4000000)//-------------------------oscilator 4MHZ

und calculate all timing with this 4MHZ

As I programmed 100 pleases mC I saw that it hat errors in timing. Each mC has clock error.

How correctly to work with this problem und to calibrate to 4 MHZ ? What to do at all? Ideas???

Thanks forward
Ttelmah
Guest







PostPosted: Thu Aug 25, 2005 5:03 am     Reply with quote

First answer, is that if the code is 'very time critical', you cannot use the internal oscillator. Even with the calibration set to the 'best' value on a particular chip, if you are running at 5v, expect errors of about 2%. If your supply voltage varies, the margin opens out even further.
The calibration value is automatically loaded for you from the top of memory by the compiler, if the INTRC mode is selected. Provided your programmer does not destroy/overwrite the contents of the top memory location, you will already be close to as good as you can get with this oscillator. You should verify that your programmer does save this instruction, when a chip erase is performed.

Best Wishes
Vovachess



Joined: 15 Mar 2004
Posts: 33
Location: Swiss

View user's profile Send private message Visit poster's website ICQ Number

PostPosted: Thu Aug 25, 2005 5:25 am     Reply with quote

Thanks for explanation.
The code is not very time critical.
I have question:
The calibration value is automatically loaded for you from the top of memory by the compiler…
Controller PIC12F269 has register OSCCAL at 0x03FF address. In this register is factory calibration byte saved. It is different from controller to controller. How can I automatically adjust this value? How can compiler automatically load this value????
Vovachess



Joined: 15 Mar 2004
Posts: 33
Location: Swiss

View user's profile Send private message Visit poster's website ICQ Number

PostPosted: Thu Aug 25, 2005 5:38 am     Reply with quote

Aha. I think at the beginning of program I must read the value from 0x03FF address and then load it to ASCCAL register!….. by programming I must see, that value at address 0x03FF will not be erased.
Is it correct?
Ttelmah
Guest







PostPosted: Thu Aug 25, 2005 6:27 am     Reply with quote

You have got it.
You don't though 'read' the value at 0x3FF, but you call the program at this address. Most of the smaller PICs, don't have the ability to read their own program memory, but implement an instruction 'RETLW', which returns a value. So you call 0x3FF, and arrive back, with the W register containing the value that needs to go into the OSCCAL register.
If you look at the listing file generated (in this case for a 12F675, but the behaviour is identical between the chips), the compiler generates:
Code:

0004:  CALL   3FF
0005:  BSF    03.5
0006:  MOVWF  10
0007:  MOVLW  00
0008:  MOVWF  0A
0009:  GOTO   00A
....................  #include "C:\Program Files\PICC\amtest\40K.h"
....................  #include <12F675.h>
....................  //////// Standard Header file for the PIC12F675 device ////////////////
.................... #device PIC12F675
.................... #list
....................
.................... #use delay(clock=4000000)
.................... #fuses INTRC_IO,PUT,WDT


The call returns the calibration value, and the compiler then does a bank switch (to address the registers from 0x80..0xFF), and saves the result into address 0x10, which is register 0x90. It then jumps to the main code. The bulk erase instruction, does erase this word, but most programmers have an option to save the value here, and re-write it after an erase.

Best Wishes
Vovachess



Joined: 15 Mar 2004
Posts: 33
Location: Swiss

View user's profile Send private message Visit poster's website ICQ Number

PostPosted: Thu Aug 25, 2005 6:36 am     Reply with quote

Wau.... Super code....
I see my listing.... The compiler does not generate this code.
How to enable this feature that compiler will do this code?
Thanks a lot!!!!!!
Vovachess



Joined: 15 Mar 2004
Posts: 33
Location: Swiss

View user's profile Send private message Visit poster's website ICQ Number

PostPosted: Thu Aug 25, 2005 6:53 am     Reply with quote

My compliler doesnot automatically load from the top of memory this byte----
According to the listing that I get!!!!
How to do it automatically?
Realy Thanks for help
Ttelmah
Guest







PostPosted: Thu Aug 25, 2005 7:20 am     Reply with quote

Are you sure?. You need to turn off the 'nolist' option in the include file, to see this (otherwise it is hidden).
Have another try at looking at the list file, with the list option selected, and it may be there. Also check the fuses. This code is not used/present for any oscillator option other than 'INTRC'. If the code is still not there, how old is the compiler?. This has been working OK, for over a year that I know of, but was faulty in some of the early compilers.

Best Wishes
Vovachess



Joined: 15 Mar 2004
Posts: 33
Location: Swiss

View user's profile Send private message Visit poster's website ICQ Number

PostPosted: Thu Aug 25, 2005 7:25 am     Reply with quote

Thanks for advice.
The funny thing. I use MPLAB. I configure bits in MPLAB, So i Use no
#fuses derective. If I use it, this code will be compiled.
Thanks
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