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.
I had been using this:
Code: Select all
asm
bsf STATUS, RP0
call $3ff
movwf OSCCAL
bcf STATUS, RP0
end asm
Code: Select all
OSCCAL = %01000100 'Or DEC 68, HEX 44
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.
Dave "absolute beginner" Hansen