Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

pic18 microcontroller and frequency oscillator configuration

Status
Not open for further replies.

Shafaq Gul

Junior Member level 1
Junior Member level 1
Joined
Dec 24, 2013
Messages
18
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
122
Hi!
I am using pic18f4455 (proteus simulator) n have tried alot to change Internal Oscillator Frequency through IRCF2:IRCF0 bits but its not happening...n even its not taking in account external oscillator.Please help!:???:
 

Hi,

You select the type of oscillator by the Config statements eg Internal, External etc.

You use OSCCON in your code to select the Frequency of the internal oscillator.

For Proteus neither of the above matter as you Right Clip on the 4455 chip, select Edit Properties and then specify the clock frequency you want the simulation to run at.
 
hello,

Wich compiler C18 or mikroC or ?
Show us all your configuration bits.


I am using C18 and proteus ...i connected virtual terminal on which it should display 'y' but its not working.here is my c code.


#include<p18f4455.h>
//using 20MHz external oscillator


#pragma config FOSC =HSPLL_HS//HS oscillator;PLL enabled
#pragma config PLLDIV = 5

#pragma config CPUDIV = OSC3_PLL4
#pragma config USBDIV=2
//microcontroller clock frequency 24MHz

void main()
{

//OSCCONbits.IRCF1=1;//2Mhz
//OSCCONbits.IRCF0=0;
//OSCCONbits.IRCF2=1;

OSCCONbits.SCS0=0;//primary oscillator
OSCCONbits.SCS1=0;
TXSTA=0x24; //selecting asynchronous mode,8 bit transmit and high baud rate

SPBRG=77; // 9600 baud rate ; 24MHz
TXSTAbits.TXEN=1; //transmit enabled
RCSTA=0x90;// serial port enabled ;continuous receive
TXREG='y';//sendind y via TX
TRISB=0;

while(1) // infinite loop
{
while(PIR1bits.TXIF==0);//wait until all transmitted.
while(PIR1bits.RCIF==0);//while receiver is empty.
TXREG=RCREG;//loading data from receive register to transmit register.
PORTB=RCREG;
}
}

- - - Updated - - -

Hi,

You select the type of oscillator by the Config statements eg Internal, External etc.

You use OSCCON in your code to select the Frequency of the internal oscillator.

For Proteus neither of the above matter as you Right Clip on the 4455 chip, select Edit Properties and then specify the clock frequency you want the simulation to run at.

So it means that code would not work here?..i should do it directly?
 

hello,

I don't have Proteus and PIC18F4455 with USB
i just can show you an example with 18F46k22
with many possibility for FOSC internal or via external Quartz.

Maybe is more complicated with USB
because need of 48Mhz clock for USB part..
I am not sure that with Q=20Mhz you can satisfied for USB clock =48Mhz
but with 16Mhz x 4 => 48Mhz


Code:
// PIC 18F46K22

#define OSCILLATEUR_INTERNE

#ifdef OSCILLATEUR_INTERNE
//#pragma config FOSC = INTIO67, FCMEN = OFF, PLLCFG=OFF            // CONFIG1H  16Mhz
#pragma config FOSC = INTIO67, FCMEN = OFF, PLLCFG=ON           // CONFIG1H  32Mhz
#else
#pragma config FOSC = HSHP, PLLCFG=OFF, FCMEN=OFF      
//#pragma config PRICLKEN=ON 
#endif    
#pragma config IESO=OFF,PWRTEN=OFF,BOREN=OFF,WDTEN=OFF,CCP2MX=PORTC1        
#pragma config PBADEN=OFF,CCP3MX=PORTE0,T3CMX=PORTC0,P2BMX=PORTC0
#pragma config MCLRE=EXTMCLR,STVREN=OFF,LVP=ON,XINST=OFF,DEBUG=OFF
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF            // CONFIG5L
#pragma config CPB = OFF, CPD = OFF                                  // CONFIG5H
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF        // CONFIG6L
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF                    // CONFIG6H
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF    // CONFIG7L
#pragma config EBTRB = OFF                                           // CONFIG7H




void Init_UART1(void)
{
// USART_BRGH_HIGH,6  @ 1MHZ     
// USART_BRGH_HIGH,32 @ 10MHZ 
// USART_BRGH_HIGH,51 @ 16MHZ 
// USART_BRGH_HIGH,25 @ 8MHZ 
// init 19200Bd a 10Mhz avec IT en rx
// init 38400Bd a 20Mhz 
// voir para 18.5 spec sheet DS41159B page 186
/*
#ifdef OSCILLATEUR_INTERNE
OSCCON=0b01110000;  //HFINTOSC – (16 MHz)
//111 = HFINTOSC – (16 MHz)
//110 = HFINTOSC/2 – (8 MHz)
//101 = HFINTOSC/4 – (4 MHz)
//100 = HFINTOSC/8 – (2 MHz)
//011 = HFINTOSC/16 – (1 MHz)(3)
#endif
*/
Open1USART( USART_TX_INT_OFF &
USART_RX_INT_ON &
USART_ASYNCH_MODE &
USART_EIGHT_BIT &
USART_CONT_RX &
USART_BRGH_HIGH,104 );  // FOSC= 8x4=32Mhz  19200bds
}



void main() 
{

i1=0;
i2=0;
Drapeaux.Fill=1;
Drapeaux.Blc=1;
DataReady1 = 0;
DataReady2 = 0;
c1=0;
c2=0;

   Init_Hardware(); 
   SortieRC2=1;  // eteint la led tiree au +5V 
   Led_Rouge=0;
    
 #ifdef OSCILLATEUR_INTERNE  
//  the internal oscillator is set to the default frequency of 1 MHz.
// The Internal Oscillator Frequency Select bits  (IRCF<2:0>)
// select the frequency output of the internal oscillator block  
// pour conserver 19200 bauds à 16Mhz sinon retombe à 1200 bauds
// OSCCON=0b01110000;  //HFINTOSC – (16 MHz)
// OSCCONbits.IRCF2=1; //HFINTOSC – (16 MHz)
// OSCCONbits.IRCF1=1;
// OSCCONbits.IRCF0=1;
OSCCON=0b01100000;  //HFINTOSC – (8 MHz)
//OSCCON=0b01010000;  //HFINTOSC – (4 MHz)
//111 = HFINTOSC – (16 MHz)
//110 = HFINTOSC/2 – (8 MHz)
//101 = HFINTOSC/4 – (4 MHz)
//100 = HFINTOSC/8 – (2 MHz)
//011 = HFINTOSC/16 – (1 MHz)(3)
  OSCTUNE=0;
//  OSCTUNEbits.PLLEN=0;  //  0 =sans PLL => 16Mhz  ou 8, 4, 2, 1Mhz 
  OSCTUNEbits.PLLEN=1;  // 1= avec PLL => 8*4= 32Mhz  
#endif   
   
   Tempo(200000L);
   Led_Rouge=!Led_Rouge;  
  
  OUT_RS232
  c1 = 0;
  DataReady1 = 0;
  buffer[0]=0;
  
  Init_UART1();         // 19200 bds
  RCSTA1bits.CREN = 0 ; // disable reception
  Put_RS(CLS);  
  Tempo(300000);
  txt=&Texte[0];
  strcpypgm2ram(txt,RS_Str[1]);    
  k=PutStr_RS(txt);    
  ...
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top