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
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
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