Baud rate problem


+ Reply to Thread
Results 1 to 14 of 14

Thread: Baud rate problem320 days old

  1. #1
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,353
    Thumbs Up
    Received: 44
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Baud rate problem

    I am trying to run one of the USARTs on a 24HJ128GP502 at 115,200 bits/second.

    I thought I had defined the clock frequency wrong but Delayms gives the expected result on my scope.

    I'm pretty sure my scope is accurate and it shows a $FF character to be approx 43uS wide.
    Can somebody verify the following for me, I'm not sure if my maths are right:

    1/115200 gives a bit width of 8.6uS. So 10 bits should occupy 86uS from start of start bit to end of stop bit.

    I have Declare Hserial2 Baud = 115200.

    If I use Declare Hserial2_Baud = 57600 then it gives roughly the right width on my scope.
    Am I on the right lines? If so then I think the baud calculation for 115200 (at least) is out by a factor of two. It seems OK at 9600.

    Thanks
    Charlie
    Last edited by charliecoultas; 23rd January 2019 at 12:32.

Attention

This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

The advertisements we display are relevant to this web site and your browsing history

Please consider supporting us by disabling your ad blocker.


Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

If you can, please report issues in the forum area WebSite / Forum Issues


Thank you for your attention.

  • #2
    Senior Member SimonJA's Avatar
    Join Date
    Mar 2006
    Posts
    827
    Thumbs Up
    Received: 14
    Given: 16
    Total Downloaded
    889.46 MB

    0 Not allowed!

    Default Re: Baud rate problem

    Just tried that setup with a 24FJ64GA004 and get a byte width of 82uS so is in line with what you had calculated (measured on a logic analyser).

    I have compiler version 3.6.2.7, that's the Proton version not Proton24 which doesn't seem to display on the help about.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #3
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,367
    Thumbs Up
    Received: 78
    Given: 45
    Total Downloaded
    1.39 GB

    0 Not allowed!

    Default Re: Baud rate problem

    Does the USART operate at a lesser baud rate so as to prove its working?

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #4
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,353
    Thumbs Up
    Received: 44
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: Baud rate problem

    Thanks Simon, that helps.

    Yes Norm, it works fine at 9600. I tried a few different Declare HsSeirial_Baud = with the following result:

    9600 about 1mS byte width which seems right
    19200 .. 2mS .. .. (should be half the time not double?)
    4800 .. 2mS .. .. (wrong??)

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #5
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,353
    Thumbs Up
    Received: 44
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: Baud rate problem

    By trial and error I have got it working. I output 10 bytes and kept adjusting the serial baud rate until the ten bytes took 830uS on the scope. The Hserial_Baud was setting 530,000. The music player module understands the data which should be at 115,200.

    Very odd but it's working. (The Xtal declare is 79.23)

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #6
    Fanatical Contributor top204's Avatar
    Join Date
    Feb 2002
    Posts
    3,426
    Thumbs Up
    Received: 296
    Given: 142
    Total Downloaded
    1.68 GB

    0 Not allowed!

    Default Re: Baud rate problem

    A strange one Charlie because the Baud rates are calculated by the same routine for all USARTS, and the SFRs are all set with the same values if the Baud rate is the same.

    In your program with both USARTS set to the same Baud rate, press the F2 button and view the asm. Go down to the asm that has the Baud rates in comments (just after proton_main_start_:). This is the actual Baud rates that can be achieved with the particular xtal frequency. For example, a program that has both USARTS set to 115200 Baud, and using a 32MHz crystal for tests, produces this section of asm code before the users program starts:

    Code:
        mov.w #0x8808,W0
        mov.w W0,U1MODE
        bset.w U1STA,#pp_utxen
        mov.w #34,W0
        mov.w W0,U1BRG
    ; uart1: actual baud = 114285.7
    ; uart1: baud error = 0.794%
        mov.w #0x8808,W0
        mov.w W0,U2MODE
        bset.w U2STA,#pp_utxen
        mov.w #34,W0
        mov.w W0,U2BRG
    ; uart2: actual baud = 114285.7
    ; uart2: baud error = 0.794%
    If all the SFRs are being loaded with the same values and one of them is working, then they will both be operating at the correct Baud rate, so why one wouldn't work is a mystery.

    Have you set the PPS for the pin used for USART2?

    This is something I'm going to change in future versions of Proton24, the same as I did in Proton, and make the pins auto setup for PPS.

    I don't have a PIC24HJ128GP502 device, but the PIC24 devices, pretty much, all use the same mechanisms, and their Baud rate generation are all the same.

    I tried 2 USARTS in a simple program for tests and it worked OK. Here it is, for the PIC24FJ64GA002 device, but they operate the same:

    Code:
        Device = 24FJ64GA002
        Declare Xtal = 32
     
        Declare Hserial1_Baud = 115200                             ' USART1 baud rate
        Declare Hserial2_Baud = 115200                             ' USART2 baud rate
        Declare HRSOut1_Pin = PORTB.14                             ' Select the pin for TX with USART1
        Declare HRSOut2_Pin = PORTB.13                             ' Select the pin for TX with USART2
    
        CLKDIV = 0                                                 ' CPU peripheral clock ratio set to 1:1
        Write_OSCCONH($10)                                         ' Enable the PLL to operate the device at 32MHz
        
        PPS_Output(cOut_Pin_RP14, cOut_Fn_U1TX)                    ' Make Pin RB14 U1TX
        PPS_Output(cOut_Pin_RP13, cOut_Fn_U2TX)                    ' Make Pin RB13 U2TX
    
        
        Do
            HRSOut1Ln "Hello World From 1"
            HRSOut2Ln "Hello World From 2"
            DelayMS 500
        Loop
        
    '----------------------------------------------------------------------------
    ' For internal 8MHz oscillator with PLL
    ' OSC pins are general purpose I/O
    '
        Config Config1 = JTAGEN_OFF, GCP_OFF, BKBUG_OFF, COE_OFF, ICS_PGx1, FWDTEN_OFF, WINDIS_OFF, FWPSA_PR128, WDTPOST_PS256
        Config Config2 = IOL1WAY_OFF, COE_OFF, IESO_OFF, FNOSC_FRCPLL, FCKSM_CSECME, OSCIOFNC_ON, POSCMOD_NONE 
    Last edited by top204; 23rd January 2019 at 17:08.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #7
    Prolific Poster normnet's Avatar
    Join Date
    Jul 2004
    Posts
    2,367
    Thumbs Up
    Received: 78
    Given: 45
    Total Downloaded
    1.39 GB

    0 Not allowed!

    Default Re: Baud rate problem

    I remember using a baud rate crystal for 115,200 baud as it needs to be right on at that speed.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #8
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,353
    Thumbs Up
    Received: 44
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: Baud rate problem

    Thanks Les, Norm. I tried using my laptop to compile and the results differ. My desktop PC has the problem, the laptop gives the right result. Same vsn of compiler, 1.0.5.1 on both. U1 is set to 9600, no problem, it works ok.

    I checked the assembler code Les and it was correct. I calculated that 115200 would need U2BRG = 85 and U2MODE.3 should be set. This is very odd, I don't think it's anything to do with the compiler.

    Setting USART2 baud rate to 530000 or 115200 on the desktop PC gives the same result, a byte time of 83uS.

    Don't spend anymore time trawling this Les, the fault is elusive but I'll see what I can find.

    Charlie

    Declare Hserial2_Baud = 9600 ;530000 ;115200 ;VS1000 drive from USART2


    Declare HRSIn1_Pin = PORTB.9 ;IN
    Declare HRSOut1_Pin = PORTB.8 ;OUT

    Declare HRSIn2_Pin = PORTB.11 ;IN from vs1000 module
    Declare HRSOut2_Pin = PORTB.10 ;OUT to vs1000 module
    Declare Optimiser_Level = 2 ;recommended by Les
    Declare Dead_Code_Remove = On ; .. .. ..

    Declare Shift_DelayUs 0
    PLL_Setup(43, 2, 2, $0300) ;Configure the Oscillator to operate at 79.23MHz

    PPS_Output(cOut_Pin_RP8, cOut_Fn_U1TX) ;put uart1 output on RB8 (Peripheral remapping PPS)
    PPS_Input(cIn_Pin_RP9, cIn_Fn_U1RX) ; .. .. input on read_sram
    PPS_Output(cOut_Pin_RP10, cOut_Fn_U2TX) ;put uart2 output on RB10
    PPS_Input(cIn_Pin_RP11, cIn_Fn_U2RX) ; .. .. input on RB11
    Last edited by charliecoultas; 24th January 2019 at 09:12.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #9
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,231
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: Baud rate problem

    Setting USART2 baud rate to 530000 or 115200 on the desktop PC gives the same result
    If you are using device manager to change baud rate, you will get weird results. Use some safe app like Putty.
    George.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #10
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,353
    Thumbs Up
    Received: 44
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Post Re: Baud rate problem

    I'm setting the baud rate of a 24HJ128GP502 PIC George, thankfully there's no Windows involvement.
    The "desktop PC" holds the compiler, sorry but I can see the possible confusion. The PIC is driving/listening to a VS1000 audio module, which talks/listens at 115,200.

    If I request 4 times the actual baudrate from Proton it works! If I request 115,200 I get something faster than that, nearly double the baud rate.
    Yet when I compiling the same code on my laptop, everything works as it should.

    Charlie
    Last edited by charliecoultas; 24th January 2019 at 16:53.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #11
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,231
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: Baud rate problem

    Seems likely it's your PC interface thats the issue, try a real serial port (who has one of those anymore, don't get me started) oe a USB/Serial converter.
    George.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #12
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,353
    Thumbs Up
    Received: 44
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: Baud rate problem

    Nothing to do with the PC George, problem is confined to the 24HJ128GP502 chip.

    No serial ports involved, just a 115,200 inerface to a VLSI VS1000 music module, which is part of a model for the Heath Robinson museum. If you type "PLAY ME A TUNE" it plays a piano piece. It is this interface that I am struggling with.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #13
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,231
    Thumbs Up
    Received: 75
    Given: 181
    Total Downloaded
    5.15 GB

    0 Not allowed!

    Default Re: Baud rate problem

    You said in post #8 that you got different result on different PC's.
    George.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  • #14
    Prolific Poster charliecoultas's Avatar
    Join Date
    Sep 2010
    Posts
    1,353
    Thumbs Up
    Received: 44
    Given: 39
    Total Downloaded
    3.36 GB

    0 Not allowed!

    Default Re: Baud rate problem

    I meant that if I compiled on desk pc it failed, if compiled on laptop it worked. The rs232 comms was between a 24 series chip and a music player. Very odd as both vsns of compiler were latest.

    BUT I'VE FOUND THE PROBLEM:

    I declared the baud rate at the start of the code: Declare Hserial2_Baud = 115200

    But then later on I set the Mode and Status registers using: U2MODE = 00100000000000
    U2STA = 00010000000000 ;turn xmittr on

    I didn't realise that Declare Hserial_Baud does this as well. If using higher speed baud rates there is a bit in the MODE register that needs to be set, and I was clearing it again using my U2MODE setting.

    It works OK on 9600 baud because that bit isn't set so clearing it later makes no difference.

    I confused things between the two PC's, they do in fact both give the correct results now.

    Thanks for the responses, I'm wiping the egg off my face.
    Last edited by charliecoultas; 26th January 2019 at 09:50.

  • Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

    Thread Information

    Users Browsing this Thread

    There are currently 1 users browsing this thread. (0 members and 1 guests)

       

    Similar Threads

    1. Hi Baud Rate Project
      By nat in forum Proton Plus Compiler v3
      Replies: 4
      Last Post: 5th March 2011, 16:48
    2. [SOLVED !] Baud rate
      By pepito in forum quickBlue Bluetooth Development
      Replies: 4
      Last Post: 19th July 2007, 23:41
    3. [SOLVED !] quickblue baud rate
      By ADLIN SYSTEMS in forum quickBlue Bluetooth Development
      Replies: 2
      Last Post: 26th August 2006, 18:37
    4. [SOLVED !] baud rate
      By ADLIN SYSTEMS in forum USBWiz
      Replies: 7
      Last Post: 13th August 2006, 09:41
    5. Rs 232 baud rate
      By jackjay2 in forum Wish List / Product Feedback
      Replies: 4
      Last Post: 19th September 2004, 10:14

    Posting Permissions

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