Monday, March 24, 2014

Microchiping - Internal Oscillator Setup

PIC16F1938 has a configurable internal oscillator module (31 kHz - 32 MHz). Setting it up is a very simple task, involving one single register, except the case you need a 32 MHz Fosc.

PIC16F1938 - Oscilator Module
PIC16F1938 - Oscilator Module (1)

OSCCON register must be altered to setup the internal oscillator.
If SCS<1:0> bits are 10 or 11 the system clock uses the internal oscillator block. Bits IRCF<3:0> are used to select the oscillator frequency.

OSCCON Register
OSCCON Register (1)

For example the function used to initialize the internal oscillator module at a frequency of 16 MHz will look like this:

   void InitIntOsc(void) {
     
      // system clock uses the internal oscillator (SCS<1:0> = 11)
      OSCCON |= 0x03;
      // set the frequency to 16 MHz
      OSCCON |= 0x78;

   }  


(1) PIC16(L)F1938/9 Datasheet - PDF!

No comments:

Post a Comment