[SOLVED] pic18f46k22 problem in uart with internal oscillator in mikroc compiler

Status
Not open for further replies.

#MAAM#

Full Member level 2
Joined
Nov 21, 2009
Messages
131
Helped
29
Reputation
58
Reaction score
27
Trophy points
1,308
Location
Egypt
Visit site
Activity points
1,920
Hi guys,

When i using pic18f46k22 with uart library by using internal oscillator for various values such as 0.5,1,2,8,16 MHz it doesn't work properly. When i using external oscillator crystal 11.0592 MHz it works fine. what can i do to solve this problem because i haven't free pin to use external oscillator in my project ??

I'm using MikroC V5

thanks
 

The internal osc in a PIC is subject to variations in temperature and possibly other fluctuations.
The LFINTOSC is the only internal oscilator designed to be stable over temperature (see datasheet p36)
Also remember a reset clears the internal clocks (back to 1Mhz if I remember rightly).
 
Reactions: #MAAM#

    #MAAM#

    Points: 2
    Helpful Answer Positive Rating
thank you all. I will check tomorrow in company and i will tell you the result
 

hello,

....Also remember a reset clears the internal clocks (back to 1Mhz if I remember rightly).

Yes, default choice is 1MHZ when using internal oscillator
To avoid change of FOSC at reset , add to the init program :

Code:
#define OSCILLATEUR_INTERNE
....
....
void main()
{
....
#ifdef OSCILLATEUR_INTERNE      // i use define to switch between QUARTZ Oscill  and Internal Oscill 
//  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; 
 // OSCCONbits.IRCF2=1; //HFINTOSC – (16 MHz)
 // OSCCONbits.IRCF1=1;
 // OSCCONbits.IRCF0=1;
  OSCTUNE=0;
  OSCTUNEbits.PLLEN=0;  // 1= avec PLL => 64Mhz ou 40Mhz   0 =sans PLL => 16Mhz  ou 10Mhz
#endif

what is your speed of UART link ?
Are you using interrupt for receiving data ?
Do you have also trouble when sending data ?

i allready use 18F46K22 with internal oscillator at 19200 bauds ( FOSC=16MHz) NO problemo..
Maybe you also can adjust OSCTUNE ...
 
Reactions: #MAAM#

    #MAAM#

    Points: 2
    Helpful Answer Positive Rating

thank you paulfjujo for your reply, my speed of uart 9600 bps and i can't change the speed because i communicate with other processor at this speed. I'm in test phase with uart and when i finished i will use interrupt to receive data. I don't no exactly where is the problem in sending or receiving.
 

Thank you all guys my code working fine now :smile:

the problem is to adjust OSCCON and OSCTUNE as paulfjujo said

Code:
  OSCCON = 0b01110000;  // bit7: device enters SLEEP on sleep instruction[0]
                        // bit6-4: HFINTOSC 16MHz [111]
                        // bit3: status bit [0]
                        // bit2: status bit [0]
                        // bit1-0: clock defined by CONFIG bits [00]

  OSCTUNE = 0b00000000; // bit7:  device clock derived from the MFINTOSC or HFINTOSC source
                        // bit6: PLL disabled [0]
                        // bit5-0: oscillator tuning [000000]
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…