V G wrote: > Hi all, > > I'm currently working on a project for the university which involves > interfacing several PIC microcontrollers (dsPIC33FJ128GP802) to a PC > via MODBUS RTU over RS485. Since the microcontrollers will be > controlling temperature and humidity, they will be subject to > temperature and humidity fluctuations. I would imagine that a quartz > crystal would be advantageous in this case due to it's stability. > > I am thinking of running the RS485 line at 9600 bits/s. I am > interested in maintaining a *stable* bus, it doesn't need to be > particularity fast. Reliability is the highest priority. > > I used a simple program that calculates PIC UART configuration > register values based on the clock frequency and desired bit rate. I > selected various common frequencies such as 16 MHz, 20 MHz, and so on, > but all of them resulted in the program calculating a non-zero error > percentage value (0.16% at 20 MHz and 9600 bits/s). A screenshot of > the program can be viewed here: > http://img249.imageshack.us/img249/8761/screenshotno.png > > Is this non-zero error value acceptable? Will it cause reliability > issues? Does it need to be avoided, and if so, how? The pic will try to sample in the middle of each bit period. The transmitter and receiver resynronise every byte and a byte is roughly 10 bits (exactly how many depends on your exact setup). To be less than half a clock cycle out after 10 bits the receiver clock must be less than 5% different from the transmitter clock. In reality you want things a bit better than that to allow for things like inaccracies in the synchronisation (due to their nature of being locked to potentially out of step source clocks they can never synchronise perfectly) 0.16% is more than good enough. As bob has pointed out if you really want spot on serial baud rates you can get crystals that are designed to be nice multiples of standard serial baud rates. The downside is they tend to not be nice multiples of anything else ;) > The second question is, does anyone know of a good MODBUS stack for > the PIC? I will most likely be using the C30 compiler for the > dsPIC33FJ128GP802. I would also like to use UART RX interrupts to > handle the protocol, but DMA is a possibility too. > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist