+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Full Member level 2
    Points: 1,445, Level: 8
    #MAAM#'s Avatar
    Join Date
    Nov 2009
    Location
    Egypt
    Posts
    131
    Helped
    27 / 27
    Points
    1,445
    Level
    8

    pic18f46k22 problem in uart with internal oscillator in mikroc compiler

    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

  2. #2
    Banned
    Points: 23,048, Level: 36

    Join Date
    Dec 2012
    Location
    Bangalore, India
    Posts
    4,325
    Helped
    798 / 798
    Points
    23,048
    Level
    36

    Re: pic18f46k22 problem in uart with internal oscillator in mikroc compiler

    INTRC timing is not precise.



    •   Alt5th August 2013, 10:50

      advertising

        
       

  3. #3
    Full Member level 2
    Points: 1,445, Level: 8
    #MAAM#'s Avatar
    Join Date
    Nov 2009
    Location
    Egypt
    Posts
    131
    Helped
    27 / 27
    Points
    1,445
    Level
    8

    Re: pic18f46k22 problem in uart with internal oscillator in mikroc compiler

    Quote Originally Posted by jayanth.devarayanadurga View Post
    INTRC timing is not precise.
    please more clarify ?



    •   Alt5th August 2013, 11:12

      advertising

        
       

  4. #4
    Advanced Member level 1
    Points: 2,777, Level: 12

    Join Date
    Apr 2010
    Location
    UK
    Posts
    439
    Helped
    70 / 70
    Points
    2,777
    Level
    12

    Re: pic18f46k22 problem in uart with internal oscillator in mikroc compiler

    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).


    1 members found this post helpful.

    •   Alt5th August 2013, 11:40

      advertising

        
       

  5. #5
    Banned
    Points: 23,048, Level: 36

    Join Date
    Dec 2012
    Location
    Bangalore, India
    Posts
    4,325
    Helped
    798 / 798
    Points
    23,048
    Level
    36

    Re: pic18f46k22 problem in uart with internal oscillator in mikroc compiler

    INTRC clock is not good for UART communication.


    1 members found this post helpful.

  6. #6
    Full Member level 2
    Points: 1,445, Level: 8
    #MAAM#'s Avatar
    Join Date
    Nov 2009
    Location
    Egypt
    Posts
    131
    Helped
    27 / 27
    Points
    1,445
    Level
    8

    Re: pic18f46k22 problem in uart with internal oscillator in mikroc compiler

    thank you all. I will check tomorrow in company and i will tell you the result



  7. #7
    Advanced Member level 2
    Points: 3,724, Level: 14
    paulfjujo's Avatar
    Join Date
    Jun 2008
    Location
    France 01120
    Posts
    555
    Helped
    97 / 97
    Points
    3,724
    Level
    14

    Re: pic18f46k22 problem in uart with internal oscillator in mikroc compiler

    hello,

    Quote Originally Posted by 123jack View Post
    ....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 ...


    1 members found this post helpful.

  8. #8
    Full Member level 2
    Points: 1,445, Level: 8
    #MAAM#'s Avatar
    Join Date
    Nov 2009
    Location
    Egypt
    Posts
    131
    Helped
    27 / 27
    Points
    1,445
    Level
    8

    Re: pic18f46k22 problem in uart with internal oscillator in mikroc compiler

    Quote Originally Posted by paulfjujo View Post
    hello,



    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 ...
    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.



  9. #9
    Full Member level 2
    Points: 1,445, Level: 8
    #MAAM#'s Avatar
    Join Date
    Nov 2009
    Location
    Egypt
    Posts
    131
    Helped
    27 / 27
    Points
    1,445
    Level
    8

    Re: pic18f46k22 problem in uart with internal oscillator in mikroc compiler

    Thank you all guys my code working fine now

    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]



+ Post New Thread
Please login