Dave's Absolute Beginners Corner. Subject: OSCCAL values

General discussion on mikroBasic.
Post Reply
Author
Message
Dave Hansen
Posts: 33
Joined: 20 Aug 2009 19:48

Dave's Absolute Beginners Corner. Subject: OSCCAL values

#1 Post by Dave Hansen » 09 Sep 2009 21:48

Dave's Absolute Beginners Corner. 8)

Subject: OSCCAL values

I've been frustrated in trying to restore the OSCCAL value back into my 12F675. I had erased it by accident and wasn't sure what to do. :oops:

I had been using this:

Code: Select all

asm
 bsf STATUS, RP0
 call $3ff
 movwf OSCCAL
 bcf STATUS, RP0
end asm
But all this did was pull out an already corrupted value. I found a few clues on this forum but I was still a bit confused. I next tried tinkering with this command:

Code: Select all

OSCCAL = %01000100 'Or DEC 68, HEX 44
And it seemed to work. :o The first 6 bits (from left to right) are the OSCCAL value. The last two bits are not used. So binary value "1" starts in the third column from the right. I use binary values because it's easier for me to keep track of the bits.

Here's the details of what I did:

BEWARE! If you haven't messed up your OSCCAL value as I did then don't mess with this unless your SURE the internal clock is not set correctly. :!:

I used GP4/CLKOUT (pin 3) to monitor the frequency. You have to set the 3 FOSC bits in the CONFIG word as well to INTOSC with clock out. This can be done in the Edit Project menu in mikroBasic. Select _INTRC_OSC_CLKOUT =$xxxx. I used an oscilloscope with a built in frequency counter and began changing the binary code until I got as close to 1MHz as was possible. This takes some patience. If you don't have a scope or a frequency counter try the above value. It should be close. You could also use the chips internal timers to get a value. Now granted every chip is different, but I figured a person could at least get a start. Also keep in mind that the chips temperature and supply voltage can affect the internal oscillator. I would power the chip up and let it warm up for an hour in the environment you intend to use it in. The values I'm going to list are approximations but should be close enough. This was with a room temperature of about 75 deg F.

10000100 1.148 MHz
10000000 1.140
01111100 1.135
01110100 1.106
01101100 1.090
01011100 1.050
01001100 1.015
01001000 1.010
01000100 1.000
01000000 990 kHz
00111100 983 kHz

It's likely this could be done in assembly, but that would have to be up to someone else more expert than I. If you know of a better, easier, or more efficient way to do this please add to this post. And please give lots of details. The more the better! Remember, absolute beginner here.

P.S. I'm using mikroBasic 7.2. I tried to use mikroBasicPro, but it kept crashing. Probably because my old laptop barely meets minimum system requirements. :cry:

Dave "absolute beginner" Hansen

Liro
Posts: 107
Joined: 05 Nov 2006 00:07
Location: Strasbourg - FRANCE
Contact:

#2 Post by Liro » 20 Sep 2009 21:20

Hi,

You'll need a PICkit2 wich allows you to restore the OSCCAL value or a oscilloscope and a function generator see microchip's appnote:
http://ww1.microchip.com/downloads/en/A ... 00250a.pdf
----------------------------------
L'électronique pour le plaisir!
http://ludvol.free.fr

Dave Hansen
Posts: 33
Joined: 20 Aug 2009 19:48

#3 Post by Dave Hansen » 21 Sep 2009 18:59

Thanks for the info, but there's a few problems with this route. :(

First I don't have the money to purchase another programmer at the moment :cry: (And if I did I would probably get an EasyPIC6). My Vellman programmer will have to do for now.

Second the code is in assembly. Now I could probably copy and paste this into an assembler program like MPLAB, but I don't really want to mess with assembly code right now. It's all I can do to keep up with all that mikroBasic can do.

The method I did below seems to function so I'm satisfied for the moment. Still maybe someone could convert that assembly program into some mikroBasic code. 8)

Any takers?

robyn.aston
Posts: 3
Joined: 16 Jun 2012 16:03

Re: Dave's Absolute Beginners Corner. Subject: OSCCAL values

#4 Post by robyn.aston » 06 Jun 2014 11:07

Not quite the same problem but related:

I've ticked 'OSCAL protect' within Mikroprog but it doesn't preserve the frequency. As suggested, I have to use a scope and change the OSCAL value to get back to 1Mhz, requiring several iterations.

As I'm programming 50 chips at a session it's very time consuming. What am I doing wrong?
Robyn Aston
'Custom Power Design' A division of SMET LTD.
The Markham Centre,
Station Road, Theale,
Berkshire. RG7 4PE.
Tel. +44 (0)118 930 2299.
Fax. +44 (0)118 930 2206.
www.custompsudesign.com

Mob. 07885 459436.
'Skype' name: robyn.aston

Post Reply

Return to “mikroBasic General”