Do I have to use Table Reads & Writes to change the OSCSEN bit on a 18F452?


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    jessey's Avatar
    jessey Guest

    Default Do I have to use Table Reads & Writes to change the OSCSEN bit on a 18F452?

    Hello,

    I'm trying to figure out how to implement the Low Power (LP) mode on my 18F452 and then have the ability to switch between the main oscillator and the Timer1 oscillator at will while the program is up and running to conserve battery power. The project's power supply can be switched between operating off the mains to batteries and vise versa by plugging and or unplugging the transformer so while operating off the batteries I'd like to be able to have Timer1 use a 32 KHz crystal. I have a few questions on how to do this after reading the manual.

    The manual for the 18F452 states that in order to be able to use the "Oscillator Switching Feature" that it has to be enabled by programming the (OSCSEN) bit in the Configuration Register1H to a 0. When I look at section 19-1: it shows that the OSCSEN is bit 5 but it's not a write-able bit. Further reading suggests to me that the only way to access this bit is in the CONFIG1H register and I'd have to use Table Reads and Table Writes to change that bit. I'm hoping I'm wrong as it's very confusing for me trying to figure out how to do that. Is there another way of doing this? Would selecting the LP mode by placing @ __CONFIG _CONFIG1H, _LP_OSC_1H at the beginning of my code set the OSCSEN bit to an 0 or does that just select the LP mode? I don't have my 32 KHz crystal yet to be able to try it.

    Can anyone suggest a way of accomplishing this?

    Thanks
    jessey

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


    Did you find this post helpful? Yes | No

    Default

    OSCSEN (oscillator system clock switch enable bit) is in configuration word 1H. You enable or disable this option at program time.

    Enabled:
    __CONFIG _CONFIG1H, _OSCS_ON_1H & _XT_OSC_1H

    Disabled:
    __CONFIG _CONFIG1H, _OSCS_OFF_1H & _XT_OSC_1H

    This just enables the feature. It does not turn it on.

    To use the crystal connected to Timer1 & switch from primary osc to this one, you have to set T1OSCEN & OSCCON.0 to switch to the Timer1 osc.
    Regards,

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

  3. #3
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default This is a great forum, thanks again Bruce.

    Hi Bruce,

    So using @__CONFIG _CONFIG1H, _OSCS_ON_1H & _XT_OSC_1H enables the Oscillator Switching Feature and starts my program off using the crystal that I have connected between OSC1 & OSC2 (pins 13 & 14). Then to switch to the 32 KHz crystal that I have connected between RC0/T1OSO & RC1/T1OSI (pins 15 & 16) I write T1CON.3=1 to set the T1OSCEN bit followed by another write OSCCONO.0=1 to set the SCS bit.

    Then at any time that I want to switch back to using the main oscillator again, all I have to do is to clear the SCS bit (OSCCONO.0=0). Thanks for that very useful information, now I can't wait until my 32 KHz crystal gets here so I can try it.

    Thanks Again
    jessey

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


    Did you find this post helpful? Yes | No

    Default

    Hi Jessey,

    Yep. That's pretty much all there is to it.

    This enables osc switching in config word: _OSCS_ON_1H.

    T1CON.3 = 1 enables the Timer1 oscillator.

    OSCCON.0 = 1 switches from whatever external primary osc you're using to the one on Timer1.

    Switch to Timer1 osc: OSCCON.0 = 1
    Switch to main osc: OSCCON.0 = 0

    NOTE: Its not OSCCON0.0. It's OSCCON.0.
    Last edited by Bruce; - 13th February 2006 at 00:38.
    Regards,

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

  5. #5
    jessey's Avatar
    jessey Guest


    Did you find this post helpful? Yes | No

    Default How do I select the capacator values for the Timer1 crystal for LP mode?

    Hi Bruce,

    Yes I see that now (OSCCON0.0), a typo error, I didn't notice it when I posted. I'll have to be more diligent in the future.

    I thought that a friend of mine had a 32 KHz crystal that he was going to give me but when we searched for it, we couldn't find one. So now I'm in the process of ordering some from Digi-Key and I thought I'd check with you before I placed my order.

    In the manual it recommends a Epson C-001R32.768K-A crystal and then goes on to say that Microchip suggests 33 pF as a starting point in validating the oscillator circuit for the Epson crystal. The manual also goes on to state that since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components.

    Since the appropriate recommended value from the manufacturer for the external capacitors is just a starting point then (if you've had any experience in this) what values of capacitors should I be ordering to compliment a crystal that the manufacturer has recommended a 12.5 pf caps for? Should I be purchasing several values above and below the recommended value, so I'll have them on hand, being that the initial recommended value is just a starting point? And how would I decide on what value would be best suited for my application?

    Thanks
    jessey

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


    Did you find this post helpful? Yes | No

    Default

    Hi Jessey,

    Just use whatever cap values are specified by the manufacturer of the crystal.

    I've been using the SE3201 32kHz cylinder type with 12.5pF caps for years and it's rock solid. Never had any start-up or accuracy problems with them.

    I've got a whole box of them on-hand. Drop me an email with your shipping address, and I'll toss a couple SE3201 with caps in an envelope for you. No charge if you don't mind snail-mail..;o}
    Regards,

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

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. Doubt with interrupt on change
    By lugo.p in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 5th March 2010, 15:22
  3. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

Members who have read this thread : 0

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