Page 1 of 1

EUSART RS232 auto baud rate detection

Posted: Sun Jan 27, 2013 7:28 pm
by Jan Lichtenbelt
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:
http://www.matrixmultimedia.com/mmforu ... lt#p36793

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/D ... 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.

Re: EUSART RS232 auto baud rate detection

Posted: Sun Jan 27, 2013 11:08 pm
by dazz
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.34 KiB) Downloaded 559 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

Re: EUSART RS232 auto baud rate detection

Posted: Mon Jan 28, 2013 9:45 am
by Jan Lichtenbelt
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