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.
EUSART RS232 auto baud rate detection
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
EUSART RS232 auto baud rate detection
- Attachments
-
- RX UART Auto-Baud V3.c
- (16.54 KiB) Downloaded 708 times
-
- RX UART Auto-Baud V3.fcf
- (15.93 KiB) Downloaded 635 times
-
- Posts: 1314
- Joined: Sun Jan 15, 2012 3:15 pm
- Has thanked: 474 times
- Been thanked: 458 times
- Contact:
Re: EUSART RS232 auto baud rate detection
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
Regards
Dazz
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
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
----------------------------------------
Dazz
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php
- Jan Lichtenbelt
- Posts: 797
- Joined: Tue Feb 17, 2009 8:35 pm
- Location: Haren GN, the Netherlands
- Has thanked: 128 times
- Been thanked: 264 times
- Contact:
Re: EUSART RS232 auto baud rate detection
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
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
- (16.65 KiB) Downloaded 655 times
-
- RX UART Auto-Baud V3.1.fcf
- (16.16 KiB) Downloaded 634 times