configuring of internal oscillator @ 4MHZ of 16F628A

Submitted by RAHAMANSA on Thu, 09/20/2018 - 01:39

In XC8 what step to be taken to get fr. 4mhz of the mcu 16f628a after the following code..

//--------

#pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function)  // bit cofiguration for internal osc

 

#include <xc.h>
#define _XTAL_FREQ 4000000 // 4MHz This is the speed the controller is running at

//what would be the next action to get 4mhz frq.

tnx.

Hi SA,

I can see that you are using the configuration bits (Windows -> PIC memory Views -> Configuration bits) option in you MPLABX to generate the code and what you have done is also correct.

When you use this line 

#pragma config FOSC = INTOSCIO  // Oscillator Selection bits (INTOSC oscillator: I/O function on RA6/OSC2/CLKOUT pin, I/O function)  // bit cofiguration for internal osc

It already means that you are instructing the PIC to use the internal 4MHz oscilator. You do not have to do anything more than this just continue your program 

In case if you are not using the configuration bits and what to set the fuse bits by yourself then refer page 96 on the datasheet. There are totally 8 different options in which you can set the clock by setting the FOSC0, FOSC1 and FOSC2 bits. I am pasting the bit details below

Capture_0.PNG

 

Hope this helps !

  Joined May 19, 2015      213
Tuesday at 03:45 PM

Tnx Jayant,

then what should be the case for 8, 16, and 20 mhz for selection of internal osc. 

Then is there only changes for below directive,

#define _XTAL_FREQ x // x = 8/16 or 20 MHz

pl correct me.

  Joined September 15, 2017      9
Friday at 10:08 PM

The PIC16F628A has only one internal oscillator and it is 4MHz.

If you want higher frequency you should use external crystal the PIC can support upto 20MHz

  Joined May 19, 2015      213
Tuesday at 03:45 PM