DEFINE OSCCAL_1K 1 kills sound


Closed Thread
Results 1 to 11 of 11
  1. #1

    Default DEFINE OSCCAL_1K 1 kills sound

    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

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    The 12F629 has a RETLW xx instruction at 03ffh.

    Using DEFINE OSCCAL_1K 1 causes PBP to generate the following .asm code fragment;
    Code:
     
            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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4


    Did you find this post helpful? Yes | No

    Default

    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

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    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.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6


    Did you find this post helpful? Yes | No

    Default OPTION_REG

    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

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    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
    Last edited by mister_e; - 8th November 2004 at 10:03.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8


    Did you find this post helpful? Yes | No

    Default

    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

  9. #9


    Did you find this post helpful? Yes | No

    Default

    Actually many of the free software programming packages do NOT save and reload osccal. they simply erase it.

  10. #10
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Question PICkit2 DEFINE OSCCAL_1K 1

    Thanks for all of the useful information you guys.
    Does anyone know what the PICkit2 does with the osccal ?
    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  11. #11
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    He's keeping it... and can recover it for you if you lost it before ... nice for a such nifty programmer huh?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Thermo 7 segments - little problem
    By fratello in forum mel PIC BASIC Pro
    Replies: 49
    Last Post: - 27th July 2013, 07:31
  2. RS485 bus - starting probem
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 27th January 2010, 13:35
  3. 32 bit square root
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 6th May 2009, 03:37
  4. one line led light make image
    By bioul in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 12:19
  5. HSERIN doesn´t work
    By wurm in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 29th July 2007, 14:23

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts