PDA

View Full Version : DEFINE OSCCAL_1K 1 kills sound



peterdeco1
- 1st November 2004, 18:09
Hello Melanie & Everyone. When I add DEFINE OSCCAL_1K 1 to my code using a 12F629, it makes the pause command extremely accurate. However it disables the sound command. Can you tell me why? Thank you. - Peter

mister_e
- 1st November 2004, 18:35
Maybe i'm wrong here but you probably lose the OSCCAL define on previous programming this device. Is any other never used before 12F675 close to you. If there's, read oscillator calibration within MPLAB an write it down on the chip (liquid paper on the bottom side). and now try with this one.

But maybe i'm wrong to say that there's no factory OSCCAL with those 12F serie like 12c508,509 or 12c671.

let me know

Bruce
- 2nd November 2004, 00:28
The 12F629 has a RETLW xx instruction at 03ffh.

Using DEFINE OSCCAL_1K 1 causes PBP to generate the following .asm code fragment;


call 03ffh ; Get oscillator calibration for 1K
MOVE?AB OSCCAL ; Set oscillator calibration


All this does is call location 03ffh. The RETLW instruction returns the factory oscillator calibration value in the W register, then it's placed in the osccal register by MOVE?AB OSCCAL.

If you have erased location 03ffh in this PIC, then you don't use DEFINE OSCCAL_1K 1 since there's no RETLW or xx value there,
and now there's no reason to call location 03ffh.

You can check this by placing your 12F629 in your programmer, and reading it, then viewing the .HEX file read from it.

Location 03ffh should have something like 3478.

34 = RETLW
78 = the factory osccal calibration value

Note that 78h is an arbitrary # that will vary from PIC to PIC. This is the factory oscccal calibration value. The 34 is always there if not erased.

If you have erased your 12F629 part including location 03ffh - you can still set the osccal register up for "center frequency" by loading it with 128d on power up.

Just drop OSCCAL = 128 in the top section of your code.

You can fine tune the osccal value by placing a scope on GP4, and tweaking the osccal value until you see a 1MHz signal output on GP4.

Setup GP4 to output the system clock Fosc/4 like this;

@ DEVICE INTRC_OSC_CLKOUT

If you're really hard-core, and want to use DEFINE OSCCAL_1K 1 each time, but you've erased this location, you can use;

POKECODE @$3FF, $78

Where you just replace $78 with your own osccal value you've determined outputs 1MHz on GP4.

If you're using MeLabs serial programmer, be sure to have Erase & Program Calibration selected. Otherwise the serial programmer will not erase or re-program this location.

peterdeco1
- 4th November 2004, 09:32
Thanks for the advice. I duplicated the experiment and had no trouble with the sound command. I erased the PIC several times & that didn't stop the sound command either. Must have been a bad PIC. Please help me understand something. Lately, I've been using Picstart Plus. There is an option to "erase flash device." When you click it, it erases it. On my other programmer & software, if you erase any 8 pin flash PIC's, it says "reprogramming calib byte"...then it erases...then it says "restored factory values OSCAL value &HO." Does Picstart Plus do this? Does DEFINE OSCAL_1K 1 do this? I don't really know what's going on. Thank you. - Peter

Bruce
- 4th November 2004, 14:18
I have a Picstart Plus too, and it does not erase the factory osccal calibration instruction/value. That's why you receive the messaage "Calibration memory already programmed" when you program the 12F part with a Picstart Plus.

An easy way to check any programmer is to first read the part, record the value shown in the last program memory location (that's your factory osccal calibration value) as mentioned before.

Then erase it. Re-read it, and see if this has changed. Most programmers won't automatically erase this location. Some will first read it, store it in memory, then program it right back in.

DEFINE OSCAL_1K 1 only causes program flow to jump to the last program memory location, and load the factory osccal calibration value. It has nothing to do with erasing anything.

The MeLabs Serial programmer will erase this location, but only if you have this option enabled as mentioned previously.

peterdeco1
- 8th November 2004, 09:32
Hello Melanie & Everyone. For the first time I enabled weak pullups on a 16F818 by using OPTION_REG 7 = 0. I found this command here on the forum but would never have figured it out from the datasheet. My question is: where does the 7 come from? What is OPTION_REG 6? Or 5?, etc. How do you enable pullups only on certain pins? Again, I don't understand the correlation between the datasheet and the PBP command. Thank you. - Peter

mister_e
- 8th November 2004, 09:59
Hi Peterdeco1

>found this command here on the forum but would never have figured it out from the datasheet. My question is: where does the 7 come from? What is OPTION_REG 6? Or 5?, etc. How do you enable pullups only on certain pins? Again, I don't understand the correlation between the datasheet and the PBP command. Thank you. - Peter

see datasheet p19... Option Register BIT 7

7 is the Bit number to set.

Must be write :

OPTION_REG.7=0

regards

peterdeco1
- 8th November 2004, 11:29
Thank you Steve. I think I got it now! I didn't understand that OPTION_REG 5 = 0 meant "bit 5" in the datasheets. I really appreciate it. - Peter

nomad
- 20th October 2007, 01:32
Actually many of the free software programming packages do NOT save and reload osccal. they simply erase it.

Pic_User
- 18th November 2008, 18:36
Thanks for all of the useful information you guys.
Does anyone know what the PICkit2 does with the osccal ?
-Adam-

mister_e
- 18th November 2008, 19:03
He's keeping it... and can recover it for you if you lost it before ... nice for a such nifty programmer huh?