View previous topic :: View next topic |
Author |
Message |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
Internal Oscillator Calibration |
Posted: Thu Aug 31, 2017 6:48 am |
|
|
Sorry bombarding with so many questions.
I am having a problem when running my program with the PIC12F629, the oscillator frequency is to high with internal oscillator. I tested with a stopper (not a scientific way, I know) for 10 seconds a few times and I got 7.8 seconds.
I made a search on the forum, found 4 topics on the subject, but still don't understand how to correct the frequency.
In the data sheet page 52 is written:
Quote: | The entire program memory will be erased, including OSCCAL value, when the code protection is
turned off. | and I suppose this what happened to me.
Page 54 of the data sheet have explanation how to calibrate the internal oscillator, also Ttelmah explained the subject in one of the topics.
So what I have done, I insert the ASM bellow in the beginning of the main and the frequency is correct.
Code: | #ASM
bsf 0x83,5 ;STATUS, RP0
movlw 0x40
movwf 0x90 ;OSCCAL
bcf 0x83,5;STATUS, RP0
#ENDASM |
My question is how can I do it in CCS?
Best wishes
Joe |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Aug 31, 2017 7:34 am |
|
|
Don't.
Just write the required value to the memory location where it is stored.
At boot, the compiler adds code to automatically copy the stored calibration value from ROM to the OSCCAL register.
So just update the stored value.
The value is stored as a RETLW instruction at 0x3FF
Code: |
#ROM 0x3FF = 0x3440
|
Will store your 0x40 into the location that is read.
Many programmers have the option to do this automatically for you. In the PicKit for example, there is a routine to automatically calculate the correct value and store it (it runs a test on the chip against the programmers crystal). |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Thu Aug 31, 2017 7:43 am |
|
|
Thank you for the answer Ttelmah
It is easy and simple if you know what to do
Best wishes
Joe |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Aug 31, 2017 7:58 am |
|
|
That's very often the case... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19515
|
|
Posted: Thu Aug 31, 2017 10:17 am |
|
|
Just worth adding, that a lot of the programming packages do have an option to automatically save the calibration value. Depending what you are using, worth investigating this to avoid the problem recurring... |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Thu Aug 31, 2017 12:31 pm |
|
|
Thanks again Ttelmah
I am using the PIC K150 because I have some hardware problem with the ICSP.
Usually using ICD-U64, never had a problem so never checked.
Best wishes
Joe |
|
|
|