PDA

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



jessey
- 12th February 2006, 10:43
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

Bruce
- 12th February 2006, 14:22
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.

jessey
- 12th February 2006, 20:36
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

Bruce
- 13th February 2006, 00:35
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.

jessey
- 16th February 2006, 22:30
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

Bruce
- 16th February 2006, 23:43
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}