1
\$\begingroup\$

I'm using a PIC 16F887 and I'd like to use the internal oscillator HFINTOSC. To accomplish this, I set the IRCF 2:0 bits to 110 (4Mhz prescaler) and the FOSC 2:0 config bits to INTOSC.

Now I should do something I really can't understand: according to the datasheet (see pag. 61) I should set the bit SCS in order to use the internal clock source (see the final MUX on the diagram on pag. 61). Because the SCS bit is in the OSCON register I should set it programmatically on my code but the code itself needs a clock source to be executed! How can I execute a code to set a bit to use a clock if the code needs a clock source in the first place?????

I quote the datasheet for the SCS bit:

4.6.1 SYSTEM CLOCK SELECT (SCS) BIT The System Clock Select (SCS) bit of the OSCCON register selects the system clock source that is used for the CPU and peripherals. • WhentheSCSbitoftheOSCCONregister=0, the system clock source is determined by configuration of the FOSC<2:0> bits in the Configuration Word Register 1 (CONFIG1). • WhentheSCSbitoftheOSCCONregister=1, the system clock source is chosen by the internal oscillator frequency selected by the IRCF<2:0> bits of the OSCCON register. After a Reset, the SCS bit of the OSCCON register is always cleared.

\$\endgroup\$
4
\$\begingroup\$

You don't need to also write the SCS bit if you already selected the internal oscillator in the Configuration bits.

bit 0 SCS: System Clock Select bit

  • 1 = Internal oscillator is used for system clock
  • 0 = Clock source defined by FOSC<2:0> of the CONFIG1 register

The SCS bit is 0 by default, so the system clock is selected by the FOSC<2:0> CONFIG1 bits.

You don't even have to set the IRCF<2:0> bits, because their reset value is 110 = 4 MHz.

\$\endgroup\$
  • \$\begingroup\$ So basically to select the internal clock at 4MHz I don't have to touch any of the registers? (configuration word excluded) \$\endgroup\$ – Gianluca Ghettini Apr 26 '15 at 14:21
  • \$\begingroup\$ @G_G That's my interpretation of the datasheet. I've only used the PIC16F887 with an external oscillator. \$\endgroup\$ – m.Alin Apr 26 '15 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.