configuring of internal oscillator @ 4MHZ of 16F628A

RAHAMANSA's picture

Offline

Joined: Sep 15, 2017

Replies: 9
configuring of internal oscillator @ 4MHZ of 16F628A
September 20, 2018 - 1:39am

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.

Jayant's picture

Offline

Joined: May 19, 2015

Replies: 208
Set the bits FOSC0, FOSC1 and FOSC2.
September 20, 2018 - 11:13am

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 !

RAHAMANSA's picture

Offline

Joined: Sep 15, 2017

Replies: 9
Tnx Jayant,
September 20, 2018 - 3:56pm

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.

Jayant's picture

Offline

Joined: May 19, 2015

Replies: 208
has only one internal oscillator 4MHz
September 20, 2018 - 5:23pm

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