+ Post New Thread
Results 1 to 7 of 7
  1. #1
    Full Member level 1
    Points: 907, Level: 6

    Join Date
    Apr 2016
    Posts
    116
    Helped
    0 / 0
    Points
    907
    Level
    6

    mikro PIC18F4620 UART recv PLL bug!

    Hey
    I tried to send UART commands from Arduino to PIC18F4620.
    It did not work at any baud rates, pic received garbage, only 'x' characters.

    But then I realized that my PIC is using HS oscillator with 4X PLL.
    And I tried this code:
    Code:
    // the setup routine runs once when you press reset:
    void setup() {
      // initialize serial communication at 9600 bits per second:
      Serial.begin(2400);
    }
    
    // the loop routine runs over and over again forever:
    void loop() {
      Serial.println("Aaa");
      delay(100);        // delay in between reads for stability
    }
    and on pic:
    Code:
         UART1_Init(600);
           
            while(1)
            {
               if (1 && UART1_Data_Ready() == 1) {
                /// UART_Read_Text(tmp, "\n", 64)     ;
                tmp[0] = UART1_Read();
                tmp[1] = 0;
                My_Print(tmp);
           }
    and it received "A", 'a', and some garbage, but works way better than my other ideas.

    What's wrong?

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 4
    Points: 7,241, Level: 20

    Join Date
    Jan 2015
    Posts
    1,013
    Helped
    320 / 320
    Points
    7,241
    Level
    20

    Re: mikro PIC18F4620 UART recv PLL bug!

    Show us the config settings and the oscillator initialisation code as you MUST get the oscillator set up correctly before anything else.
    Also what frequency crystal are you using?
    Susan



    •   AltAdvertisment

        
       

  3. #3
    Full Member level 1
    Points: 907, Level: 6

    Join Date
    Apr 2016
    Posts
    116
    Helped
    0 / 0
    Points
    907
    Level
    6

    Re: mikro PIC18F4620 UART recv PLL bug!

    Quote Originally Posted by Aussie Susan View Post
    Show us the config settings and the oscillator initialisation code as you MUST get the oscillator set up correctly before anything else.
    Also what frequency crystal are you using?
    Susan
    I think I have already figured this out.
    I am using 8MHz crystal, but mikroC expects me to enter "320000" value in the text field.
    I mean, it expects me to enter value after PLL (8 * 4 = 32).

    I'm not sure if it's a bug or the feature, but for me it seems just stupid, I was always sure that I am supposed to type the PCB crystal frequency in the textbox.



    •   AltAdvertisment

        
       

  4. #4
    Super Moderator
    Points: 70,762, Level: 64
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    14,471
    Helped
    3292 / 3292
    Points
    70,762
    Level
    64

    Re: mikro PIC18F4620 UART recv PLL bug!

    Hi,

    I am using 8MHz crystal, but mikroC expects me to enter "320000" value in the text field.
    I mean, it expects me to enter value after PLL (8 * 4 = 32).
    8M = 8,000,000
    8M x 4 = 32,000,000, not 320,000 --> there are two "0" missing.

    Klaus



  5. #5
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    126 / 126
    Points
    5,417
    Level
    17

    Re: mikro PIC18F4620 UART recv PLL bug!

    No, You have to enter 32 MHz in the MCU Clock Frequency text box. It is not Crystal frequency text box. *MHz Crystal freq * 4x PLL = 32 MHz. If you use USB in the PIC18F4550 then you have to enter Clock as 48 MHz.



    •   AltAdvertisment

        
       

  6. #6
    Full Member level 1
    Points: 907, Level: 6

    Join Date
    Apr 2016
    Posts
    116
    Helped
    0 / 0
    Points
    907
    Level
    6

    Re: mikro PIC18F4620 UART recv PLL bug!

    Quote Originally Posted by KlausST View Post
    8M = 8,000,000
    8M x 4 = 32,000,000, not 320,000 --> there are two "0" missing.
    Klaus
    Sorry, just a typo in my post, I had it typed correctly in the mikroC.


    Quote Originally Posted by Okada View Post
    No, You have to enter 32 MHz in the MCU Clock Frequency text box. It is not Crystal frequency text box. *MHz Crystal freq * 4x PLL = 32 MHz. If you use USB in the PIC18F4550 then you have to enter Clock as 48 MHz.
    Why 48MHz and not 32MHz?



  7. #7
    Banned
    Points: 5,417, Level: 17

    Join Date
    Jun 2016
    Posts
    1,159
    Helped
    126 / 126
    Points
    5,417
    Level
    17

    Re: mikro PIC18F4620 UART recv PLL bug!

    48 MHz is for PIC18F4550 if you are using USB in it. For your PIC it is 8 MHz * 4x PLL = 32 MHz. It is the MCU Clock Frequency and not Crystal Frequency.

    FOSC is different. MCU Clock of 32 MHz gets divided by 4 and FOSC will be 32 MHz / 4 = 8 MHz.



--[[ ]]--