UART Overview | RF Controller Overview | Power Up and Receive States | Transmit States | Code

The UART RF Controller

Author : Nicholas Hutniak

Overview of UART

The basic idea behind a UART connection protocol is that communication can occur without the use of RTS (Request to Send) and CTS (Clear to Send) signals. In fact, no syncronization is required at all ideally for a UART connection. The RX (Receive) and TX (Transmit) lines operate on a high-low basis where '1' represents high and '0' represents low.


- The TX line remains high normally - idles in this mode. This means that any device connected to it can assume a continual high signal means no data is being transmitted.

- When data wants to be transmitted, the transmitting device will bring the TX line low for one clock cycle. This start bit tells receiving devices that the next bit sent will be valid data.

- The next clock cycle the transmitting device can start sending data serially. Data transmission is usually sent 7 or 8 bits at a time. Ideally transmission could be more or less bits but sending 8 bits in one transmission is standard practice. It is long enough to hold a significant amount of data and it allows for easy error checking using a parity bit. The complexity of detecting errors becomes larger with an increase in the transmission size. We will not go into error correction here, but the simplest form is a XOR of all the bits being sent in a grouping. The error bit (commonly known as the parity bit) is sent along with the packet.

- Some implementations of UART can have an associated stop bit with data transmission. This bit is normally high and immediately preceeds the 8 bits sent (and any parity bits sent along with the data).


Overview of the RF Controller

The MAIDEN implementation of the RF controller uses the above outlined UART protocol. Transmission occurs with only a start bit, followed by 8 data bits, no stop bit, and no parity bit. The stop bit for our implementation is repetitive for our purposes since idle transmission is high (which is equivalent to the stop bit).

There are a couple important notes to mention regarding this particular implementation of a RF Controller. It uses the TR-916-SC-PA-ND RF Transceiver from www.digikey.ca, which is produced by Linx Technologies. Careful examination of the data sheet reveals important information.

  1. Transmission up to 33,600bps
  2. Input range of 2.7 to 13 VDC; Required 10-19 mA current requirement.
  3. Operates as half-duplex
Important Timing Issues:


Power Up and Receive States

The image to the left shows the progression of the RF Controller state machine.

One implementation of the RF Controller (to eliminate slowing down to 33,600 kbps) would be to create a clock multiplier that would make a new clock to operate at this speed. This is bad practice since other devices may be hooked up to this same clock and cause major problems. Thus, values must be held using a counter (while in a given state).

Handling of the power-up time variation occurs using a custom made 'largecounter'. This variation of a counter was implemented since the amount of hardware increases with the size of the counter. The code is found here as part of the RF controller package. The counter expects two input numbers which form the expression N = (input1*input2)-1 where N is the value to count up to. The inputs are given as std_logic_vectors.

  • timeoutDone referred to in the diagram is the signal put out by the largecounter when N is reached.
  • Idle state for this device is the receive state (waitRX and waitRX0).

    It idles while the shifter s2p gets a value of "11111111". This is how the UART protocol is detected. The exit condition for waitRX0 is when s2p gets "11111110" signifying the detection of an incoming transmission (due to the appearance of a start bit).

    If at any time while in the idle states a Request to Transfer occurs (signified by the two arrows pointed right) then the controller switches to the Transmit State. If waitRX enters its state with CurrentMode set to '0' then it proceeds to the waitRXtopowerup state. This means the device has just finished transmitting and must return to the idle states. Thorough explanation of both of these operations follows.

    After receiving a start bit, the RF controller must begin sampling the input signal for data. Due to the analog nature of any RF device there will be a transition time associated with the rise and fall of a signal. Therefore, the best time to sample a given data bit is in the middle of transmission. This time is approximately known since transmission occurs at a baud rate already established (I say approximately since the detection of the start bit could have occurred during the transition time). The following picture illustrates this idea of sampling. As you can see there is a short period where values may be interpreted as either 1 or 0. This is the period we want to avoid.

    The RXstateStart1 and RXstateStart2 states cause a delay in the sampling of Half the Baud Rate to achieve the best sampling. The reason for the extra states (1 vs. 2) is described below

    Now the controller can start receiving valid data bytes in the RXstate1 and RXstate2 states. It remains in the RXstate2 for a Full Baud Rate. It then checks to see how many bits it has received and cycles through RXstate1 -> RXstate2 until 8 bits are received from the input data line.

    All data is received MSB first. Once 8 bits are received the controller proceeds back to the waitRX state.



    Transmit States



    Entrance to the waitTX state is accomplished by the condition that the device is not currently receiving a message and there has been a request to transfer data. For interest sake, a request to transmit is accomplished by setting RequestTX high - the controller checks the first bit of the D storage buffer (from CPU) to see if there is 'valid data' (i.e. a one).

    It is important to note here that the waitTX and power_upTX1 states are the same. The rationale for designing the controller this way is for ease of future modifications and reusability. The waitTX state allows one to modify the idle state to transmit if such a need occured. Mirroring the receive and transmit states in this fashion allows for easier modification. It is not considered a waste of a state since one clock cycle in the grand scheme of things is insignificant.

    Just as the power up time is a factor, the switching time from RX to TX must be handled. Here that is done by the power_upTX1 and power_upTX2 states.



    To establish the UART protocol correctly the next step is to pull the transmit line low for the Baud Rate. This is done in the TXzerobit1 and TXzerobit2 states. (Up until this point, the transmit line is forced to output high to ensure that no values get interpreted as valid data.)

    Data transmission occurs upon entering TXstate1 and TXstate2. Bits get shifted out one by one MSB first. The states continue to cycle when 8 bits have not been sent out. The value of each bit is still held for the Full Baud Rate.

    The bottom line signifies leaving the TXstate2 and re-entering the waitRX state. This is where CurrentMode comes into play.


    CurrentMode

    When exiting TXstate2, CurrentMode is set to '0' to tell the Receiver side of the controller that it must switch back to Receive Mode (and thus power up its mode). This is another feature that makes the code reusable. If a similar format for implementing the transmit side as the receiver side (for CurrentMode), then multiple transmits may occur without needing to go back to the Receiver mode in the controller. The MAIDEN system took Receiving information as a strong priority, so it was designed in this fashion instead.



    Second State Names

    It seems on first glance that a number of states are un-needlessly wasted when implementing the RF controller. However, due to the resetting nature of the largecounter this must be done.

    There are a number of cascading states that make use of the ability of the counter to reach large values. This must occur every time the device switches modes, needs to count for Half the Baud Rate, or count for a Full Baud Rate.

    Early simulations (without double the states) indicated that the counter did not get reset fast enough for the timeoutDone value of '1' to get pulled back down low. This caused the state machine to cycle through states without ever reseting the value in the counter.



    Code Reference

    The code can be found here. Feel free to contact me with questions.

  • The code has been compiled sucessfully with Quartus II.
  • It has been simulated sucessfully with Quartus II.
  • It has been simulated with the hardware mentioned above resulting in correct operation.
  • rf_hwtest.vhd has two devices already connected correctly.

    Note: due to debouncing the current simulation in hardware only operates as expected when data is continually transfered (i.e. hold the push button). Hardware tests in later versions confirm that the debouncing causes invalid data output.


    Group: Wireless Instant Messenger
    Kevin Ogden
    Nick Hutniak
    James Ding
    Boldwin Li
    Horace Chan
    Brian Tsang

    Acknowledgements:
    Thanks to Dr. Elliott for help understanding the concepts and suggestions for solutions.

    Nicholas Hutniak - March, 2003
    Questions/Comments? ironchest01@hotmail.com