View previous topic :: View next topic |
Author |
Message |
Vovachess
Joined: 15 Mar 2004 Posts: 33 Location: Swiss
|
Internal Oscillator calibration |
Posted: Thu Aug 25, 2005 4:06 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Aug 25, 2005 5:03 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Vovachess
Joined: 15 Mar 2004 Posts: 33 Location: Swiss
|
|
Posted: Thu Aug 25, 2005 5:25 am |
|
|
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???? |
|
![](templates/subSilver/images/spacer.gif) |
Vovachess
Joined: 15 Mar 2004 Posts: 33 Location: Swiss
|
|
Posted: Thu Aug 25, 2005 5:38 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Aug 25, 2005 6:27 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Vovachess
Joined: 15 Mar 2004 Posts: 33 Location: Swiss
|
|
Posted: Thu Aug 25, 2005 6:36 am |
|
|
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!!!!!! |
|
![](templates/subSilver/images/spacer.gif) |
Vovachess
Joined: 15 Mar 2004 Posts: 33 Location: Swiss
|
|
Posted: Thu Aug 25, 2005 6:53 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Thu Aug 25, 2005 7:20 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Vovachess
Joined: 15 Mar 2004 Posts: 33 Location: Swiss
|
|
Posted: Thu Aug 25, 2005 7:25 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|