Electronics related projects, information, and resources.
PIC Based RS485 Multiplexer

Recently, I had to design a circuit real quick that transmitted 4 parallel TTL data bits over 350m of twisted pair cable. I needed to feed in four parallel data bits at one end, and get 4 parallel data bits out the other end, completely transparent to the transmitting and receiving circuits.

I decided to implement this using a PIC 16F84 for both an encoder and decoder, and use RS-485 drivers (DS26C31 and DS26C32) to drive the 350m cable. I only needed five I/O pins per PIC, so this could have been implemented using the smaller 8pin 12C508 device, but the 16F84 has the advantage of being reprogrammable, and PCB size or cost wasn't an issue anyway.

The design presented here can be easily modified for any number of bits and any desired interface RS-232, Fibre optic, almost anything. In fact, the software is interface independant, you only need to change the interface chips.

Here is the block diagram :

As you can see, there isn't much too it. I have omitted the power pins and XTAL inputs which are also used. The MCLR line must also be tied HIGH on both chips. Port A is not used.

The software is written for an external crystal running at 1MHz, although the actual speed isn't important, but you must have both the encoder and decoder at the same speed. The watchdog has been enabled.

The timing diagram looks like this :

There is a burst of five bits every 100ms. The start bit is 0.5ms, and the data bits are 1ms each. This is assuming a 1MHz crystal clock is used. This gives an update rate of 10Hz, which may not seem very fast, but was more than sufficient for driving the relays in my application. The timing could be easily changed in software.

The decoder simply waits in a loop for the start bit, and then times for 1ms before sampling the first data bit. This sample then occurs exactly in the centre of the data bit to ensure a reliable reading. The subsequent data bits are then read every 1ms as well.

Here is the source code and HEX files written in PIC assembler : picmux.zip

I used the MPLAB development system.

Home - electronics.alternatezone.com


Copyright(c)1995-2003 David L. Jones