EUSART RS232 auto baud rate detection

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

User avatar
Jan Lichtenbelt
Posts: 794
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 261 times
Contact:

EUSART RS232 auto baud rate detection

Postby Jan Lichtenbelt » Sun Jan 27, 2013 7:28 pm

Using 32 MHz internal oscillator increases sometimes the accuracy and/or the speed of processes. The disadvantage is that the LCD cannot be used. There is a simple solution to transfer the data by means of RS232 to a second microchip on 19.6 MHz with LCD.
I gave routines for that elsewhere:
[url]
viewtopic.php?f=46&t=10884&p=36793&hilit=rs232+Lichtenbelt#p36793
[/url]

It works fine, but , as always, I though that could be better with an auto baud rate detector. And as programmer I started to program it myself with a software timer and detection of the time needed to receive the "U" character. This gives, together with the startbit and the stopbit, 5 pulses. Doing this one needs to go to the assembler level and each change can destroy the number of program steps and thus destroy the triggering.

Read the datasheet of the PIC16F1939 http://ww1.microchip.com/downloads/en/DeviceDoc/41574B.pdf and chapter 25.4 shows the EUSART Baud Rate Generator (BRG). And why to find out the wheel myself if someone else has done that before.

Reading this datasheet and searching on internet I found a simple solution
http://www.microchip.com/forums/m233642.aspx
which I transformed into a Flowcode V5 program, but with 90% C-code.

To test the program I added LCD screen AND the EB004 LED board. This last one to make visible a very fast changing byte.

But the theory is more simple than the practice. I used a function generator with square wave with a frequency of 4800, which is equal to a continuously range of "U" (U =0101010b) at a double baud rate of 9600. And I used and other microchip which sends "U" characters separated by 2 msec delays at 9600 bauds.

But I failed to get the baud rate of 9600 detected and found only the ascii 153 (10011001) character. That seems that the baud rate detected is a factor 2 to fast. But even changing this ba(u)d rate, does not improve the result.

Interesting problem. Who can help?


Kind regards

Jan Lichtenbelt

attached flowcode test program and the C-code version of it.
Attachments
RX UART Auto-Baud V3.c
(17.28 KiB) Downloaded 462 times
RX UART Auto-Baud V3.fcf
(15.93 KiB) Downloaded 398 times

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 514 times
Been thanked: 467 times
Contact:

Re: EUSART RS232 auto baud rate detection

Postby dazz » Sun Jan 27, 2013 11:08 pm

Hi Jan
I'm not very good with c, but a quick check of the datasheet and boost c: , i changed the syntax of the (baudcon,ABDEN) call it compiled to hex without grumbling ,hex file attached to see if it worked
below is the change i made between the init and auto calls
RX UART Auto-Baud V3.hex
(6.49 KiB) Downloaded 320 times

Code: Select all

----------------------------------------
Initialise EUSART Rx:

cr_bit(txsta,SYNC);  // set asynchronous mode
st_bit(rcsta,SPEN);  // Enable serial port (Rx,...)
st_bit(rcsta,CREN);  // enable asynchronous receiver

----------------------------------------

----------------------------------------
C Code:

st_bit(baudcon,ABDEN);

----------------------------------------

----------------------------------------
Label AUTOBAUD and set any baud rate:

AUTOBAUD:

spbrgh=0;            // Baud Rate generator BRG
spbrgl=31;            // Baud Rate generator BRG

----------------------------------------

Regards
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

User avatar
Jan Lichtenbelt
Posts: 794
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 261 times
Contact:

Re: EUSART RS232 auto baud rate detection

Postby Jan Lichtenbelt » Mon Jan 28, 2013 9:45 am

Dear Dazz,

Thanks for your help. Your right, the auto baud rate detection mode has to be enabled. I forgot. I improved the program see attached files V3.1. But the result is the same, that means wrong.

You can help?

kind regrads


Jan Lichtenbelt
Attachments
RX UART Auto-Baud V3.1.c
(17.39 KiB) Downloaded 412 times
RX UART Auto-Baud V3.1.fcf
(16.16 KiB) Downloaded 388 times