Terminal Character Issue

Terminal Character Issue

Postby GettinBetter » Sun Nov 24, 2019 11:03 am

HW: Explorer 16/32, 8MHz, PIC24FJ256GB110 PIM
SW: MPLABX v5.2, MCC, terminal via UART1/USB
Aims: Output data to terminal via UART.

PIN Config:
Debug (PGEC2- pin 26, PGED2 - Pin 27) Previously Tested.
UART (Tx - 50, Rx out - Pin 49 in ) Previously Tested.

Hi Guys,
During messing around with an orientation sensor programming exercise yesterday, the character output to terminal has gone wrong.
So as part of the diagnostic process I loaded a known simple working program, which now had the same issue, then created a completely new simple 'hello world' example which also has the same issue.
Hello World
becomes
d-E_Pëev

Its consistent but wrong.

My initial exploration leads to the possibility that the baud rate is wrong?

from the uart1.c file I see
Code: Select all
   // BaudRate = 19200; Frequency = 2000000 Hz; BRG 25;
   U1BRG = 0x0019;


With BRGH=1
and using the Eq 17-2 from the 'family' data sheet... I get Baud Rate = 4000000/(4*(25+1)) = 38461.53 which seems wrong to me?

Am I on the right track? What's more strange is that it's only just started to happen, could it be and update error? I have got my IDE set to check at every start.

Regards
Les

EDIT...
When I tested my echo back to terminal prog which worked in in the past, it echos back all the standard chars normally, but any numbers are resolved as foreign language fonts. The text sent from the prog has the wrong formatting and chars as well, in fact complete garbage.
History teaches us that history doesn't teach us.
User avatar
GettinBetter
 
Posts: 43
Joined: Wed Jun 06, 2018 8:48 pm

Re: Terminal Character Issue

Postby Roche » Sun Nov 24, 2019 5:50 pm

Are you using a serial to USB converter into the PC? try resetting it - they sometimes go awry. Also - try changing the baud rate on the terminal program - see if you can get a match. Also - is the clock/PLL getting changed in your code somewhere that you aren't expecting it to happen....
Roche
 
Posts: 72
Joined: Fri Jul 11, 2014 12:35 pm
PIC experience: Professional 5+ years with MCHP products

Re: Terminal Character Issue

Postby AussieSusan » Tue Nov 26, 2019 2:29 am

Are you actually setting BRGH to 1 or leaving it at the default of 0.
When your comment says 'Frequency=2000000 Hz', is that the Fosc or the crystal frequency or what? In either case why do you use 4000000 in your formula?
Susan
AussieSusan
Verified identity
 
Posts: 173
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist

Re: Terminal Character Issue

Postby GettinBetter » Wed Nov 27, 2019 7:58 pm

Roche wrote:Are you using a serial to USB converter into the PC? try resetting it - they sometimes go awry.

Did that...after reading your post

Roche wrote:Also - try changing the baud rate on the terminal program - see if you can get a match.

... and that first, before posting.

Roche wrote:Also - is the clock/PLL getting changed in your code somewhere that you aren't expecting it to happen....

Yes checked.

Also....Updated MPLABX to 5.3, wrote another 'hello world' prog, to test UART with no joy.

Bought a couple of new PIM(best have a couple just in case) even if it is ok. Today they sent dsPIC33CH128MP508, :cry: ordered them from work so will have to recheck the order there tomorrow. :?

AussieSusan wrote:Are you actually setting BRGH to 1 or leaving it at the default of 0.

The MCC sets the U1BRG to 1 based on the Rate I want/chose (i.e. 19200) & the oscillator being used. I looked it up in the MCC files to confirm which equation to use.

AussieSusan wrote:When your comment says 'Frequency=2000000 Hz', is that the Fosc or the crystal frequency or what? In either case why do you use 4000000 in your formula?
Susan

Good point :o
Went back and rechecked.
I used the FRC crystal on the board (8MHz) but I have used the FRC prescaler 1:2 so making it 4MHz/2 .... Oops, my bad. I don't normally use the prescaler.
So now we get Baud Rate = 2000000/(4*(25+1)) = 19230 (error = 0.15625%), which is definitely in the right ball park. I was barking up the wrong tree there.
So thank you for your comment AussieSusan.

Regards
Les
History teaches us that history doesn't teach us.
User avatar
GettinBetter
 
Posts: 43
Joined: Wed Jun 06, 2018 8:48 pm

Re: Terminal Character Issue

Postby ric » Thu Nov 28, 2019 10:29 pm

So is your problem sorted?
If not, do you have a scope you can use to inspect the Tx signal itself, to directly measure the baud rate?
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Terminal Character Issue

Postby GettinBetter » Fri Nov 29, 2019 7:56 pm

No, not yet, real life chores and exhaustion :( getting in the way, will pick it up again later this evening or tomorrow.

Regards
Les
History teaches us that history doesn't teach us.
User avatar
GettinBetter
 
Posts: 43
Joined: Wed Jun 06, 2018 8:48 pm

Re: Terminal Character Issue

Postby GettinBetter » Sat Nov 30, 2019 8:52 pm

WOW!!
You need the patience of a saint to work with the MCC... I need to wean myself off it.

So now that the MCC has decided to mess with my UART baud rate, I have to manually set it, by trial and error (using the logic analyser to check timing) found the following.

For a required baud rate of 19200 [ bit duration 52us]: ( using Fcy = 8MHz, Fcy/2 = 4MHz , & no prescaler)

MCC output BR =19200 BRGH = 1, BRG = 0x0033. Result = garbage character baud (bit duration 43 us)
Manually BR =19200 BRGH = 0, BRG = 0x000E. Result = Expected text and formatting (bit duration 49.5us, the closest I could get it to the required 52).

As I had the plug-in settings, set to 'every startup' it must have updated recently? maybe. Would love to know what really happened.

Thank you ric, the scope sorted it.
History teaches us that history doesn't teach us.
User avatar
GettinBetter
 
Posts: 43
Joined: Wed Jun 06, 2018 8:48 pm

Re: Terminal Character Issue

Postby AussieSusan » Mon Dec 02, 2019 2:59 am

Or you can use the 'old school' way and look at the data sheet.
Section 17.1 gives you the formulae.
Also something is wrong with the information you have used. The formulae all use Fcy so the options should be:
BRGH = 0: BRG = Fcy/(18 * BaudRate) - 1 = 8e6/(16*19200) - 1 = 25 (0x19) - Error -0.16%
BGRH = 1: BRG = Fcy/(4 * BaudRate) - 1 = 8E6/(4*19200) - 1 = 103 (0x67) - Error -0.16%
This should be closer to the actual Baud rate than the -4.8% error you show.
Susan
AussieSusan
Verified identity
 
Posts: 173
Joined: Mon Jun 16, 2014 4:45 am
PIC experience: Experienced Hobbyist


Return to MPLAB X IDE

Who is online

Users browsing this forum: No registered users and 9 guests

cron