pic18f4520 baud rate change to 115200


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2007
    Posts
    2

    Default pic18f4520 baud rate change to 115200

    hi guys....

    right now the default is 19200...using a 4MHZ osscilator. i need 115200 baud rate for my gsm modem...rumour that i need got to change to a 20Mhz osscilator...but can i change it into 16Mhz?


    and what do i've to change in the code as well

    penUSART (USART_TX_INT_OFF & // Transmit interrupt ON/OFF
    USART_RX_INT_ON & // Receive interrupt ON/OFF
    USART_ASYNCH_MODE & // ASYNCH/SYNCH MODE
    USART_EIGHT_BIT & // Transmission Width
    USART_CONT_RX &
    USART_BRGH_HIGH,8);


    is the code right for 115200 baud rate...


    thanks in advance

  2. #2
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    115Kbaud with a 4MHz XTAL is tough. Because the divisor has to be an integer, you can get only within 3.55% of the exact baud rate. That error is probably a bit too much. Look at the datasheet table 18-3.

    20Mhz works much better. That gives you a 1.36% error. Small enough to work well.
    In this case, set BRGH = 1 and SPBRG = 10
    Charles Linquist

  3. #3
    Join Date
    Sep 2007
    Posts
    2


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Charles Linquis View Post
    115Kbaud with a 4MHz XTAL is tough. Because the divisor has to be an integer, you can get only within 3.55% of the exact baud rate. That error is probably a bit too much. Look at the datasheet table 18-3.

    20Mhz works much better. That gives you a 1.36% error. Small enough to work well.
    In this case, set BRGH = 1 and SPBRG = 10
    what about 16Mhz XTAL

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    With 16 MHz the best error Percentage you'll get will be -0.79% witch is usually fair enough.

    This assume you're aware that you MUST use the 16 bit baudrate generator for that.

    Now to set it in C... it's your problem In PicBasic Pro
    Code:
    DEFINE HSER_RCSTA 90h ' Enable serial port & continuous receive
    DEFINE HSER_TXSTA 24h ' Enable transmit, BRGH = 1
    DEFINE HSER_CLROERR 1 ' Clear overflow automatically
    DEFINE HSER_SPBRG 34  ' 115200 Baud @ 16MHz, -0.79%
    SPBRGH = 0
    BAUDCON.3 = 1         ' Enable 16 bit baudrate generator
    My PicMultiCalc should help you a little bit
    http://www.mister-e.org/pages/utilitiespag.html
    Last edited by mister_e; - 30th September 2007 at 08:44.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. A Serial GLCD 128x64 Simple Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 8th March 2010, 20:58
  2. Replies: 14
    Last Post: - 20th March 2008, 13:54
  3. Auto Baud Rate Detection
    By mytekcontrols in forum Serial
    Replies: 10
    Last Post: - 31st October 2005, 02:17
  4. PIC12F675, accuracy of baud rate with Internal Oscillator
    By Chris Mayhew in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st August 2005, 22:41
  5. Baud Rate and Timing Calculator
    By picnaut in forum General
    Replies: 3
    Last Post: - 23rd January 2004, 16:48

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts