A common scenario is to have a PC that sends commands to a microcontroller via RS232. My PC program is sending commands (each of which are composed of multiple bytes) as fast as it can to a small robot. The microcontroller on the robot is a Parallax Propellor.
I have noticed that if I don't process bytes quickly enough on the microcontroller side of things, it can very quickly overflow the default buffers in the popular serial port drivers that are available for the Propellor. (The buffers are generally anywhere from 16 to 256 bytes). I can arbitrarily increase these buffers or create my own larger circular buffer, but I would like to have a more methodical approach to determining appropriate size requirements and/or the minimal amount of time I can wait before pulling bytes out of the serial port driver buffer.
At 1st glance:
- 115200 == 115.2 bits per millisecond == ~12.8 bytes per millisecond (assuming 1 stop bit)
1) Is that a valid way to calculate timing for serial transmissions?
Also, given my specific setup:
- PC Program <--> Bluetooth Serial Profile Driver <--> Bluetooth Transceiver <-*-> BlueSMIRF Wireless Modem <--> Parallax Propellor Program
2) What is the maximum amount of data I can send for a given period of time consistently without eventually running in to problems?
Maybe I'm over complicating things, but it seems like there are potentially multiple buffers involved in the transmission chain above. How do others commonly deal with this? Do they throttle the PC sending to a known safe rate? Implement flow control? If implementing flow control, how does that affect bandwidth and response times?
(If it matters, my experiment is to use a joystick on the PC to control multiple servos with instant reaction to the joystick movements. So every small movement of the joystick results in multiple commands being sent to the microcontroller. The commands are not just simple positional commands though, they also involve acceleration/deacceleration of servos over time and this is the reason that the microcontroller spends a significant amount of clock cycles before processing new bytes.)