• AVR Freaks

Hot!PIC32 UART bit timing inaccurate and unstable: SOLVED - for information

Author
boatbodger
Starting Member
  • Total Posts : 53
  • Reward points : 0
  • Joined: 2011/03/27 15:39:07
  • Location: 0
  • Status: offline
2019/11/19 10:01:51 (permalink)
0

PIC32 UART bit timing inaccurate and unstable: SOLVED - for information

I spent quite a long time wondering why - when I looked at the Tx output of the UART on a storage 'scope - the timing seemed a bit erratic, and generally about 2% fast, given that the dev board I am using is clocked with a crystal oscillator.  That should be pretty much dead on - right?
My hardware is an Eval kit D320010 which has the PIC32MZ2064DAR169 processor.
Well.  I started to think the PLL must be misoperating.  I found a really useful spreadsheet tool at h_t_t_p://microchip.wikidot.com/local--files/32bit:mx-osc/PIC32_OSC_CONFIG_v1.1.xlsx
Take note that this has separate tabs for the MX and the MZ clock systems - there are subtle differences.
This led me to look at the values in the configuration register DEVCFG2.
I found that the 'board pack' for the dev board had most helpfully selected the internal free running clock, so I wasn't using the crystal at all.
The DEVCFG2 config reg is set up in the C file initialization.c
I have adjusted these values from the default:
#pragma config FPLLIDIV = DIV_1
#pragma config FPLLRNG = RANGE_5_10_MHZ
#pragma config FPLLICLK = PLL_FRC
#pragma config FPLLMULT = MUL_50
#pragma config FPLLODIV = DIV_2
to read:
#pragma config FPLLIDIV = DIV_3
#pragma config FPLLRNG = RANGE_5_10_MHZ
#pragma config FPLLICLK = PLL_POSC
#pragma config FPLLMULT = MUL_50
#pragma config FPLLODIV = DIV_2
All sorted.  Now, the bit timing is - as expected - spot on.
Big thanks to Robert Smith, who authored the spreadsheet - it really helped me understand the complexities of the clock distribution.
A pity the author of the Board Pack made the FRC choice!
post edited by boatbodger - 2019/11/20 11:39:27
#1

9 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18060
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: PIC32 UART bit timing inaccurate and unstable 2019/11/19 14:52:23 (permalink)
    0
    Insufficient Data for Proper Analysis Captain.
    1. Many PIC32MZ chips have  Crystal Errata.
    2. Did you check the Crystal on a scope.  or send it out an OC module to check it?
    3. Did you take your Crystal, PLL, Perpherial divider, and UART settings and calculate them to see if they are correct.  It could be your Math.  
    4. What is telling you you are Off?
     
    #2
    boatbodger
    Starting Member
    • Total Posts : 53
    • Reward points : 0
    • Joined: 2011/03/27 15:39:07
    • Location: 0
    • Status: offline
    Re: PIC32 UART bit timing inaccurate and unstable 2019/11/20 01:26:59 (permalink)
    0
    Thanks for your response NKurzman (and for the many, many others you have posted on this forum).
     
    I have edited the title of my post to make it clearer that I had solved the problem - which was that the system was using the FRC, not the XO.  That had come about as a result of me using a Harmony project, and it did not occur to me that the writer of the Board Package would have used the FRC until I looked at the config registers.
     
    The FRC (which I have not tried to tune) on my PIC32MZ sample is about 2% fast (which is within its spec) and there is some jitter which is obvious on the 'scope when looking at the UART output running at 250kbit/s (which I require for DMX lighting control).
    For the record:
    1. I did not know that - I will take a look for when I do my PCB design (I'm just using the eval kit at present)
    2 & 4. It was looking at the bit timing of the UART output on a 'scope which showed me the absolute error and the jitter.  The 'scope has "RS232 decode", and was struggling to resolve the characters.
    3. It was when I did that check using the excellent spreadsheet Microchip have provided that I suddenly realised that the problem was that I was using the wrong clock generator - FRC instead of XO!
     
    #3
    ric
    Super Member
    • Total Posts : 24638
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: PIC32 UART bit timing inaccurate and unstable 2019/11/20 05:42:14 (permalink)
    0
    Always check the Errata for your PIC chip before committing to a PCB! :)
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #4
    crosland
    Super Member
    • Total Posts : 1696
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: PIC32 UART bit timing inaccurate and unstable 2019/11/20 07:39:12 (permalink)
    +3 (3)
    Equally as important, NEVER trust, or assume anything about, someone else's auto-generated code, especially if it comes out of Harmony.
    #5
    boatbodger
    Starting Member
    • Total Posts : 53
    • Reward points : 0
    • Joined: 2011/03/27 15:39:07
    • Location: 0
    • Status: offline
    Re: PIC32 UART bit timing inaccurate and unstable 2019/11/20 09:55:33 (permalink)
    +1 (1)
    This is my first Harmony project and I have to say I am a bit underwhelmed, so far.  I expect I'll get to understand its plus-es and minus-es.  I have already learned that even though I guess Harmony gets you started - this is also my first PIC32 project -  actually, there are no shortcuts in this world, and it does not absolve one from understanding the gory gory detail of DMA, UART, SQI, More DMA, mpfs, http_net all at the detailed level if you want anything to work.
     
    But learning is "fun", so that's all OK for me...
    #6
    boatbodger
    Starting Member
    • Total Posts : 53
    • Reward points : 0
    • Joined: 2011/03/27 15:39:07
    • Location: 0
    • Status: offline
    Re: PIC32 UART bit timing inaccurate and unstable: SOLVED - for information 2019/11/20 10:48:34 (permalink)
    +1 (1)
    I have also found that in the Errata sheet it states:
    "The UART TX Stop bit duration is shorter than the expected in High-Speed mode (BRGH bit (UxMODE<3>) = 1) for baud rates less than 7.5 Mbps."
    I had also noticed this on the 'scope at 250kbit/s.  It explains why the 'scope (Rigol DSO) sometimes struggles to decode the serial data - it's not getting a full bit's worth of "stop" at the end of the character.
     
    #7
    NKurzman
    A Guy on the Net
    • Total Posts : 18060
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: PIC32 UART bit timing inaccurate and unstable: SOLVED - for information 2019/11/20 11:10:38 (permalink)
    0
    You never said which PIC32 you had, 
    #8
    boatbodger
    Starting Member
    • Total Posts : 53
    • Reward points : 0
    • Joined: 2011/03/27 15:39:07
    • Location: 0
    • Status: offline
    Re: PIC32 UART bit timing inaccurate and unstable: SOLVED - for information 2019/11/20 11:40:23 (permalink)
    0
     PIC32MMZ2064DAR169 - now mentioned in edited OP
    #9
    Howard Long
    Super Member
    • Total Posts : 727
    • Reward points : 0
    • Joined: 2005/04/04 08:50:32
    • Status: offline
    Re: PIC32 UART bit timing inaccurate and unstable 2019/11/21 02:54:37 (permalink)
    0
    boatbodger
    This is my first Harmony project and I have to say I am a bit underwhelmed, so far.  I expect I'll get to understand its plus-es and minus-es.  I have already learned that even though I guess Harmony gets you started - this is also my first PIC32 project -  actually, there are no shortcuts in this world, and it does not absolve one from understanding the gory gory detail of DMA, UART, SQI, More DMA, mpfs, http_net all at the detailed level if you want anything to work.

     
    Precisely, with one caveat. If the tool is harder to use than working bare metal (which in most cases it is), then its value is seriously degraded. Unless I am using USB or a network stack, I still go bare metal on PIC32MX/MZ, and use Harmony to give me a very few bits and pieces I can copy and paste for stuff like chip initialisation. Even with Harmony, apart from USB and network stack, the other peripherals I go bare metal.
     

     But learning is "fun", so that's all OK for me...



    I wouldn't call learning (or using) Harmony fun!
    post edited by Howard Long - 2019/11/21 03:06:29
    #10
    Jump to:
    © 2019 APG vNext Commercial Version 4.5