Modular Robotics Essay Response

I applied for a job at Modular Robotics back in January. I discovered them through Brad Feld’s blog, FeldThoughts, which one of my sisters recommended to me. They make Cubelets, which are little modular robots comprising different electronic cubes that perform various actions. They’re kids’ toys, but I think they’re awesome anyway.

Part of the hiring process included essay questions. One of the questions was to design an electronic system, which I put a good amount of time into, so I thought I’d post it. The idea is to have one microcontroller with a single UART communicate with up to four other microcontrollers through single-wire interfaces. I chose to multiplex the UART signal from the first microcontroller. Here is my write-up (with pictures!):

Problem Statement
Devise a system that would allow a microcontroller module with a single UART peripheral to communicate serially with up to 4 other similar microcontroller modules. You are limited to only 2 electrical connections between each microcontroller module.

problemimageInitial Thoughts
In consideration of the star topology suggested by the illustration provided with the problem statement, a “master/slave” relationship seems like a good choice. In this case, the central microcontroller module (Micro 1 in the image) will be called the master, and the four microcontrollers on the periphery will be called the slaves (Micros 2-5).

Assumptions
Now that the topology and some nomenclature have been determined, a couple of assumptions must be made about the functional nature of the system.

First, it is a bit risky to assume that only unidirectional communication is required between the master and the slaves. Therefore, it is assumed that bidirectional communication must be possible.

Additionally, it is assumed that each slave is electrically independent from all other slaves and from the master. In other words, there are no pre-existing electrical connections between any two microcontroller modules. Each microcontroller module has its own independent ground and supply.

Design Requirements
From these assumptions, along with the known restrictions in the problem statement, some design requirements can be developed:

  • One of the two allowed electrical connections should be ground (to allow signaling between electrically independent modules)
  • Only one electrical connection can be used for signal (the other is ground)
  • Bidirectional communication must be half-duplex (only one signal wire is available and full-duplex on a single wire is a bit too fancy)

While the first requirement can be met by simply ensuring that one connection between the master and a slave is a ground connection, the second two requirements require a little more thought.

Single-Wire Halpinsf-Duplex
The trick here is to allow the UART peripheral, which transmits and receives on separate pins (TX and RX), to communicate on a single wire. While there are a few ways to accomplish this, the method chosen consisted of simply tying the TX and RX pins of the UART together and using a pull-up resistor to ensure that both pins idle at Vcc.

This configuration requires the TX pin of the UART to be tri-state, so that it can enter a high-impedance mode to allow the RX pin to receive data. Fortunately, nearly all integrated UART peripherals on microcontrollers use I/O pins as TX and RX. By setting the TX pin to act as an input, it is effectively set to high-impedance and the RX pin is allowed to receive. If, for some reason, this were not possible, it would be necessary to add a tri-state on the TX pin, which would in turn require an additional I/O pin for control.

For this all to happen smoothly, the master must know whether or not it should be listening for data. As such, slaves must be programmed not to attempt to send data unless requested by the master.

Example schematics of the master and slave microcontroller modules are attached. The microcontrollers chosen for the example are PICs, but AVRs would work similarly. In the examples, the master microcontroller only serves to manage the slave microcontrollers. Any data collection or external interaction would happen on the slave modules, as their I/O pins are broken out. Example boards are shown below.

Multiple Slaves
While the configuration above would allow the master microcontroller to communicate bidirectionally with a single slave microcontroller, a little more is required to allow the master to communicate with up to four slaves.

There are a number of ways to permit communication with multiple slaves, using both hardware and software. An example of a software solution might be using in-band signaling on a common signal bus to indicate the source and destination of bits of data. In the end, a hardware solution was chosen because it could be simple (as the problem only required up to four slaves) and provided a great opportunity to brush up on EAGLE schematic and layout.

4052The key to the hardware solution is a multiplexer/demultiplexer (mux/demux) suitable for serial signals. After perusing Sparkfun for a short while, the 74HC4052 was chosen. The 4052 is a dual 4-channel mux/demux, and the Sparkfun info page even mentions that it is ideal for attaching multiple serial devices to one microcontroller. Perfect! Because it’s dual, the 4052 could be used to switch both the TX and RX pins for full-duplex; however, due to the two-connection limitation, only one channel is used. The 4051, an 8-channel mux/demux, could be chosen to allow half-duplex communication with up to eight slaves.

To operate the 4052, two output pins from the master microcontroller are required (in addition to the signal pins). These control pins select which slave the master is talking to. The 4052 simply switches the TX/RX signal from the master microcontroller to one of four possible outputs depending on the states of the two control pins.

In order to transmit data to a specific slave, the two control pins must be set accordingly. Then the master can enter transmit mode, and any data it sends will be properly routed through the mux/demux to the destination slave.

Similarly, to listen for data from a specific slave, the two control pins must be set according to which slave is being listened to. Then the master can enter receive mode, and any data sent by the slave will be received through the mux/demux.

Example schematics of the master and slave microcontroller modules are attached. The microcontrollers chosen for the example are PICs, but AVRs would work similarly. In the examples, the master microcontroller only serves to manage the slave microcontrollers. Any data collection or external interaction would happen on the slave modules, as their I/O pins are broken out. Example boards are shown below.

MightyMuxMaster-v12 MightyMuxSlave-v1.0

 

The pseudocode below demonstrates how the master microcontroller may transmit and receive using the above-described configuration.

masterpseudo

Schematics:

MightyMuxMaster-v12

MightyMuxSlave-v1.0

One thought on “Modular Robotics Essay Response

  1. Pingback: Three years later… | Nev's Things

Comments are closed.