SmallBot
reconn's
reconn's
world
world
.com



Serial Multiplexer Project

Design:

serial multiplexer design

The design is pretty simple really, connect the RX and TX lines of each sonar unit to the PIC. In code, the PIC reads the data off each TX line and then sends the read data through the voltage level converter (MAX232 chip) to the host PC.

Implementation:

I used MPLAB v7.0 to write the code, and I compiled it with the CCS PCH compiler. The sonar module's output is an inverted RS-232 signal -- so in order to read data from them you have to invert them. This can be done either with an inverter (with input: sonar TX; output: PIC RX), or you can automatically invert the signal in code. I tested the inverter method to make sure it worked -- it did, but in the end I did the inversion in code, so I wouldn't have to wire up another chip.

According to the datasheet, the sonar modules only output data when their RX pin is high (+5v). They output the sonar reading, in one inch increments every 49mS. I read the data from the sonar modules in round-robin style:
  1. command the sonar to take a measurement
  2. read the data
  3. command the sonar to stop measurements
  4. send the data to the host computer
  5. move on to the next module, repeat steps 1-5
In this board, I connected the two sonar modules as follows:
Sonar Pin
PIC Pin
Sonar 1: RXRA2
Sonar 1: TXRA3
Sonar 2: RXRA0
Sonar 2: TXRA1

Sample Output

Example output of a single sonar module:
R006
R006
R010
R012
R035
R035
R035

Example output of the Serial Multiplexer:
Sonar MUX v.1
Author: Andrew Wilson 5/2006
reconnsworld.com
sonar1: 025
sonar2: 006
sonar1: 025
sonar2: 006
sonar1: 025
sonar2: 006
sonar1: 025
sonar2: 006
sonar1: 025
sonar2: 006

Code and HEX File

To see the source code, follow this link
For the 18F1320 hex file, click here

Final Words

This project works pretty well. However it may be a good idea to implement time-outs in the program. Right now, if one sonar module is broken the program will be stuck waiting for data that never comes. This will keep the program from ever moving forward.



project added: 6/11/2006


Site by Andrew Wilson. Copyright 1997-2006 All Rights Reserved unless otherwise noted.
Schematics in Schematics Depot were found on the internet and assumed to be in public domain. Contact webmaster if the copyright holder wants them pulled for any reason.