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 CCS Technical Support

Internal Oscillator Calibration

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



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

Internal Oscillator Calibration
PostPosted: Thu Aug 31, 2017 6:48 am     Reply with quote

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: 19520

View user's profile Send private message

PostPosted: Thu Aug 31, 2017 7:34 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 31, 2017 7:43 am     Reply with quote

Thank you for the answer Ttelmah

It is easy and simple if you know what to do Smile

Best wishes
Joe
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Aug 31, 2017 7:58 am     Reply with quote

That's very often the case... Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Thu Aug 31, 2017 10:17 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Aug 31, 2017 12:31 pm     Reply with quote

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
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