My config line.
Code:@__config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
My config line.
Code:@__config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_ON & _MCLRE_OFF & _LVP_OFF & _CP_OFF
Dave
Always wear safety glasses while programming.
Yes. OSCCON = %01100000 would set it to 4MHz. Bit 0 SCS allows you to switch from the osc set in config to internal. Bits 1, 2 and 3 are read only bits that indicate the oscillator status.Am I correct in thinking that for 4 MHz I would include in my program OSCCON %01100xxx, I'm not sure what bits 0, 1 and 2 would be set to?
Look at the modified version of your example attached here for a few other comments. I haven't tested this, but it should help get you up & running.
Thanks Everyone,
Once again I proved to myself how (dumb) forgetful I am , I now remember the countless number of times I've read newbies asking why their programs won't work and the responses have always been to check the data sheets for the device your using for Comparators and such. I'll definitely be paying more attention to that the next time I use a new unfamiliar micro.
Hey Bruce, I really appreciate you laying out my program and explaining all the settings in your comments, it would have taken me forever to read and try to figure out the datasheet for all those settings not to mention additional posts. The program works great now but one thing I wanted to mention is that my 44 pin demo board doesn't have a crystal installed on the board even though it reflects that in the schematics, there are pads on the board for the crystal and related components but those pads are all un-populated. Even though the program worked good using _INTRC_OSC_NOCLKOUT I changed it to _INTRC_OSC_CLKOUT, am I right in doing that and also is there a way for me to verify that the program is running on 4 MHz without using an oscilloscope?
Thanks Again
jessey
In CLKOUT mode you can send a clock pulse signal out to another device.
NOCLKOUT you can use the pins for I/Os
Program a simple blinky with one LED that will blink at a certain rate. If you code hasand also is there a way for me to verify that the program is running on 4 MHz without using an oscilloscope?
DEFINE OSC 4
and the chip is running at 4MHz, then the LED will blink at the correct rate.
Dave
Always wear safety glasses while programming.
Thanks Dave,
I added the code below in the MainLoop to check out your explanation and I can see that the timing is correct at 4 MHz and runs twice as fast at 8 MHz, that's cool!
ThanksCode:IF Push_Button = Is_Pressed THEN OSCCON = MHz8 ELSE OSCCON = MHz4 ENDIF
jessey
Hello,
I was wondering if someone could suggest why this code below doesn't work to change the oscillator speed of the Internal Oscillator while the program is running but the other code block below does work? Another thing I was pondering is, shouldn't I be setting bit 0 of the OSCCON register to 1? The datasheet for the 16f887 says this about bit 0:
1 = Internal oscillator is used for system clock
0 = Clock source defined by FOSC<2:0> of the CONFIG1 register.
Code:'this doesn't work IF Push_Button = Is_Pressed THEN IF OSCCON = %01100000 THEN OSCCON = %01110000 ELSE OSCCON = %01100000 ENDIF WHILE Push_Button = Is_Pressed PORTD = %10000001 ' Show that button press has stopped the code here WEND ENDIFThanksCode:'this works IF Push_Button = Is_Pressed THEN IF B = 0 THEN B = 1 ELSE B = 0 ENDIF WHILE Push_Button = Is_Pressed PORTD = %10000001 ' Show that button press has stopped the code here WEND ENDIF IF B = 0 THEN OSCCON = %01110000 ' 8 MHz IF B = 1 THEN OSCCON = %01100000 ' 4 MHz
jessey
hi,
I think it is "not so good" to change osc settings WHILE you touch the button ( debounce issue guaranteed !!! ...PORTD can show anything but truth !!! )
good reason for #2 to work better ... ONLY better.
I ( it's me ...) Would look for button state CHANGES instead of simply the button state ...
Alain
Last edited by Acetronics2; - 7th December 2008 at 14:23.
************************************************** ***********************
Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
************************************************** ***********************
IF there is the word "Problem" in your question ...
certainly the answer is " RTFM " or " RTFDataSheet " !!!
*****************************************
Bookmarks