• AVR Freaks

Helpful ReplyHot!dsPIC33CH Curiosity Dev Board - MCC UART Baud Rate issue

Author
edga
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2019/07/10 07:05:25
  • Location: Italy
  • Status: offline
2019/07/15 00:26:43 (permalink)
0

dsPIC33CH Curiosity Dev Board - MCC UART Baud Rate issue

I am dealing for the first time with a dsPIC22CH Curiosity Development Board, equipped with a dsPIC33CH512MP508 (although it is dual-core, I use it only in Master mode as if it was a single core).
 
For the sake of simplicity, I configured the UART1 module with MCC and used the functions defined in the tool-generated files 'uart1.c' and ' uart1.h'. To test their functioning, I decided to send  some dummy strings to CoolTem serial reader
 (with which I'm pretty acquainted).
 
With the following UART settings everything run smoothly and I see correctly the dummy strings printed on the terminal:
•        Clock Source: Fosc/2 = 4 MHz (derived from Primary Oscillator)
•        Baud Rate: 38400
•        Parity: none
•        Data Bits: 8
•        Stop Bits: 1
But, once I set a clock source higher than 4 MHz, I do not receive the dummy strings correctly anymore, even if the baud rate is kept the same and everything else (except the clock source itself) is kept equal, and I see the typical non-sense random chars as if there is misalignment of Baud Rate settings between TX and RX.
 
Checks already performed:
 
•        The code automatically generated by MCC is such that the equation for the final baud rate is satisfied (pag.12 of Microchip document DS70000582E UART dsPIC33 Family reference manual).
•        The High Baud Rate Select bit BRGH is set to 1 and the desired Baud Rate lies within the allowed range.
•        I've tried to derive the UART clock from other sources without obtaining differences.
Am I missing some requirements and/or limitations?
 
Thanks in advance
#1
du00000001
Just Some Member
  • Total Posts : 3053
  • Reward points : 0
  • Joined: 2016/05/03 13:52:42
  • Location: Germany
  • Status: offline
Re: dsPIC33CH Curiosity Dev Board - MCC UART Baud Rate issue 2019/07/18 19:31:21 (permalink)
4 (1)
Start by measuring the actual baudrate: transmit e.g. characters 0x55 and use a scope to get the baud rate.

PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
#2
edga
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2019/07/10 07:05:25
  • Location: Italy
  • Status: offline
Re: dsPIC33CH Curiosity Dev Board - MCC UART Baud Rate issue 2019/07/19 00:09:48 (permalink)
0
I've recently switched to another project but as soon as I have some spare time I will try and write here the result. 
#3
JPortici
Super Member
  • Total Posts : 770
  • Reward points : 0
  • Joined: 2012/11/17 06:27:45
  • Location: Grappaland
  • Status: offline
Re: dsPIC33CH Curiosity Dev Board - MCC UART Baud Rate issue 2019/07/19 01:30:23 (permalink) ☄ Helpfulby edga 2019/07/19 06:33:51
0
I see you are useing MCC. and for higher clock i suppose you are using the PLL.
the dsPIC33C uses a different oscillator circuit and the clock selection for the PLL is actually the PLL/2 tap. (i.e: PLL at 200MHz to achieve 100 MHz/50MIPS)
From other threads i have figured that MCC may not be keeping track of this in all modules so it's actually performing the calculations with a different clock frequency. I don't want to bother to try because UART is so simple to use, what's the point of messing around with code generators and their own bugs? (rethorical question)
#4
Ovollyn
New Member
  • Total Posts : 12
  • Reward points : 0
  • Joined: 2019/07/17 10:29:37
  • Location: 0
  • Status: offline
Re: dsPIC33CH Curiosity Dev Board - MCC UART Baud Rate issue 2019/07/19 06:27:39 (permalink) ☄ Helpfulby edga 2019/08/04 03:12:38
4 (1)
Hello edga,

Maybe look at the following link, this might help you fix your problem:

http://ww1.microchip.com/downloads/en/DeviceDoc/dsPIC33-PIC24-FRM-Oscillator-Module-with-High-Speed-PLL-70005255b.pdf

at page 52, there is a code example where they show you how to fix your clock frequency using the PLL (in this example, they show for 50MHz). As JPortici mention, to get a 50MHz/50MIPS CPU (FCY), you need to have a 200MHz clock frequency. Once your clock frequency is set,you can check it via the CLKO pin and an oscilloscope (in my case, as I am using a dsPIC33CH128MP502 with a SSOP format, CLKO is on pin 10).
To set your UxBRG register, for the UART peripheral, you need to fix the following value:
 
UxBRG = (unsigned int)((FCY/(BAUDRATE*16))-1);
 
where FCY is the CPU  clock (here 50000000UL), and baudrate the desired baudrate that you want.

Hope this have helped you,

Regards,

M.
 
#5
edga
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2019/07/10 07:05:25
  • Location: Italy
  • Status: offline
Re: dsPIC33CH Curiosity Dev Board - MCC UART Baud Rate issue 2019/07/19 06:33:55 (permalink)
0
Actually, I thought PLL was enabled by default by MCC since I was asking for higher frequency clock but it was not. 
I enabled it, tuned the scalers and now it is working, also with Fosc = 60 MHz. 
 
PS: Yes I know, I should definitely avoid using MCC. 
 
Thanks for your help.
#6
Jump to:
© 2019 APG vNext Commercial Version 4.5