View previous topic :: View next topic |
Author |
Message |
tumrobot
Joined: 24 Aug 2010 Posts: 3
|
UART for non standard baud rate |
Posted: Wed Aug 25, 2010 12:05 am |
|
|
Hi
Can I use uart for non standard baud rate?
Code: |
#include <18F458.H>
#fuses HS, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=10400, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
|
Or do I need to create non standard function by myself ? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed Aug 25, 2010 1:23 am |
|
|
The PIC processors can generate many non standard baud rates. The possible baud rates depend on your clock frequency and processor model. See the datasheet for examples.
The CCS compiler will generate an error message on compilation when the nearest possible frequency is more than 3% off. So, short answer, if the compiler doesn't complain your baud rate is possible.
P.S.: for a PIC18 at 20MHZ it most likely will generate a baud rate of 10417, an error of +0.16% |
|
|
jbmiller
Joined: 07 Oct 2006 Posts: 73 Location: Greensville,Ontario
|
|
Posted: Wed Aug 25, 2010 5:09 am |
|
|
Sure can ! Work 'backwards',do the math to find a crystal and dividers to get what YOU need.
I've done it for years as an 'antihacker' ploy. real hard to lock onto serial data at 8003 baud !
Just remember that basic timing won't be 'standard'( ie 4Mhz xtal= 1 us/cycle). |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed Aug 25, 2010 7:37 am |
|
|
Hmm.... so acording to all previous posts, i can assume that i can implement MIDI !!!! its got a "wierd" baud rate as well (31250 bps)....
using a 1Mhz crystal / div 32? .... i dont really know how my pic's uart goes from 20Mhz to 9600bps
@jbmiller: if its not to much trouble could you explain a bit more on the math part?
sorry to parachute my way into this post _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
Gabriel
Joined: 03 Aug 2009 Posts: 1067 Location: Panama
|
|
Posted: Wed Aug 25, 2010 8:57 am |
|
|
never mind.....
PCM had a previous post on this....
thanks anyways... _________________ CCS PCM 5.078 & CCS PCH 5.093 |
|
|
tumrobot
Joined: 24 Aug 2010 Posts: 3
|
|
Posted: Sun Aug 29, 2010 10:51 am |
|
|
I try to interface MCU to PC by use RS-232 baudrate 10400 at MCU and use Docklight Scripting V1.8 ser baudrate 10400 also.
I think it not working
Here is my code
Code: |
#include <18F458.h> // Standard Header file
#fuses HS,NOWDT,NOPROTECT,NOLVP // Configuration word
#use delay(clock=20000000) // oscillator
#use rs232(baud=10400 ,xmit=pin_c5,rcv=pin_c4,stream=HOSTPC,errors)
void main(void)
{
while (TRUE) // Loop nothing
{
fprintf(HOSTPC,"\r\n*** Test UART ***\r\n");
}
}
|
So somebody have non standard baudrate function for RS-232?
Last edited by tumrobot on Sun Aug 29, 2010 10:40 pm; edited 1 time in total |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Sun Aug 29, 2010 11:01 am |
|
|
Is the baud rate 10400 or 104000? Your post mentions both. _________________ Andrew |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sun Aug 29, 2010 11:49 am |
|
|
Look at PDF page 187 of the datasheet for the PIC. It shows how to calculate the error for the desired bit rate. _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
tumrobot
Joined: 24 Aug 2010 Posts: 3
|
|
Posted: Sun Aug 29, 2010 10:39 pm |
|
|
# andrewg
Quote: | Is the baud rate 10400 or 104000? Your post mentions both. |
Sorry i need to use buad rate 10400
#bkamen
Quote: | Look at PDF page 187 of the datasheet for the PIC. It shows how to calculate the error for the desired bit rate. |
CALCULATING BAUD RATE ERROR
TABLE 18-1: BAUD RATE FORMULA
TABLE 18-2: REGISTERS ASSOCIATED WITH BAUD RATE GENERATOR
Desired Baud Rate = FOSC/(64 (X + 1))
Solving for X:
X = ((FOSC/Desired Baud Rate)/64) – 1
X = ((20000000/10400)/64) – 1
X = [29.048] = 29
Calculated Baud Rate = 20000000/(64 (29 + 1))
= 10416
Error = (Calculated Baud Rate – Desired Baud Rate)
Desired Baud Rate
= (10416 – 10400)/10400
= 0.001538%
from the calculation should be working but i still can't comunication with 10400 buadrate |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Sun Aug 29, 2010 11:53 pm |
|
|
do you have an oscilloscope to check the output timing?
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Aug 30, 2010 12:40 am |
|
|
Code: | #use rs232(baud=10400 ,xmit=pin_c5,rcv=pin_c4,stream=HOSTPC,errors) | Here you have changed the I/O pins from the hardware UART connections to other I/O pins. Why???
It should still work as the CCS compiler will create a software UART, but this comes with limitations that you should be aware of. For one, the hardware baudrate generator that you still refer to is not being used anymore and you lost the ability to use UART interrupts.
Is the program you posted the exact same program you are testing with?
I recommend you change the pins to the original C6 and C7 so the hardware UART is being used. |
|
|
|