View previous topic :: View next topic |
Author |
Message |
Robotan
Joined: 12 Jul 2008 Posts: 18 Location: Canada
|
1Mbps serial communication |
Posted: Fri Aug 15, 2008 6:26 am |
|
|
This question has been asked before, but I'm asking again since it wasn't answered fully. I would like to use a 16f877 to control some dynamixel servo motors. The issue is that the default communication speed for these motors is 1Mbps. I certainly don't need such speed in my application, but I will need to communicate with them at this rate initially just to set them to a lower baud rate. After reading through the 16F877 data sheet, it would seem that I can achieve 1Mbps with a 10Mhz crystal. But the compiler complains when I try and set the baud rate this high. What can I do as a work around? There was mention of doing this via bit banging, but I'm not sure how to do this. I would much prefer to use the built in functions. If there is no other way, could someone post a little sample of how to achieve this baud rate via bit banging?
It would be much appreciated.
Rob |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Aug 15, 2008 8:19 am |
|
|
Quote: | After reading through the 16F877 data sheet, it would seem that I can achieve 1Mbps with a 10Mhz crystal. | You are reading another data sheet than I have. The formula in my data sheet gives a maximum of 625kbaud at 10MHz.
Software bit banging would normally give you about the same maximum baudrate.
If you don't mind having the limited flexibility of a hard coded bit sequence you can achieve a higher baudrate of maximum Fosc/4 = 2.5MHz. Problem here is that your targeted baudrate is not an integer multiple of the clock frequency, so 1Mbaud is an impossible speed.
The easiest, fastest and most solid solution is to replace the crystal on your board by a 16MHz crystal. Than 1Mbaud is no problem for the hardware UART and you don't have to write software functions to set the motor controller to a lower baudrate. |
|
|
Robotan
Joined: 12 Jul 2008 Posts: 18 Location: Canada
|
|
Posted: Fri Aug 15, 2008 11:40 am |
|
|
Right, my mistake. A 16Mhz crystal will give me the desired 1Mbps. I can change the crystal, but how do I get around the compiler limitation of the baud rate? The manual says of the set_uart_speed() function that "baud is a constant 100-115200 representing the number of bits per second"
What am I missing here?
Rob |
|
|
newguy
Joined: 24 Jun 2004 Posts: 1911
|
|
Posted: Fri Aug 15, 2008 12:05 pm |
|
|
Set the baud manually by directly loading the proper register(s). The PIC's datasheet will list the register(s) that the USART uses, and the memory organization section (look for the section called Special Function Registers) will list the address of each register.
In your code you directly access any register you wish with the #byte directive. For instance, to declare "timer0_low_byte" and locate it at the memory address of the timer 0 low byte:
#byte timer0_low_byte = 0x____ (you'd include the actual hex address of that register where the underscores are - and I'm too lazy to look up the actual address - also note - no ;)
After the declaration, if you want to load that register with a certain value, just do this:
timer0_low_byte = 348;
The same goes for the baud rate generator register(s). Figure out what those registers should be loaded with, and then load them with the proper value(s).
To get around the compiler's objections to the speed, you may have to tell the compiler in the #use rs232 line to set any speed that won't cause an error. Later on, do your own speed setting. This will allow you to use the built-in rs232 functions but at your own speed, namely 1Mbps, and the compiler won't know the difference. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Aug 15, 2008 6:34 pm |
|
|
Quote: | The manual says of the set_uart_speed() function that "baud is a constant 100-115200 representing the number of bits per second"
What am I missing here? | The manual is outdated.
I just tested in both v3.249 and v4.057. With a 16MHz clock the compiler compiles without complaints and the generated code is correct for 1Mbaud.
I've sent a report to CCS. |
|
|
|