Sunday, February 2, 2014

Framing

Recall RS-232 use of start and stop bit for framing the data bits between start and stop bits. The start bit serves to synchronize the receiver with the remaining bits from the sender. The sender and receiver use the same baud rate but, due to clock drift, must resynchronize on each data transmission.
Typically, the receiver tries to sample the signal at the expected middle of each bit. When the transition from 1 to 0 is detected, the receiver counts (typically 16 times the baud rate) 8 times before sampling the start bit, 16 times to the sample at the middle of the first data bit, 16 times to the next, etc.
                                           _      _____
Volts  _______|  |___|        |  |  |   |        |_____________
       1  1  1  1  0  1  1  0  0  1  0  1  0   0   1  1  1  1  1  1  1
      No data    |B|  Data 'S' ASCII code |P | E|    No data          
                                time-->                  
                                   
          B = Start bit (opposite of no data representation).
          P = Parity bit (0 as even number of 1's in ASCII 'S' code).
          E = Stop bit (same as no data representation).
It is important to note that the data link layer of the sender adds the framing information, which is used and removed by the receiver's data link layer. From the network layer view, framing is transparent as the message appears to travel directly from the sender's network layer to the receiver's, since the framing information was added and removed by the corresponding data link layers. The following are common framing methods.
  • Character count -  Has general format of:     Count <Count Characters> Count <Count Characters> ...
    to send the ASCII message "ABCDEFGHI"  in three separate transmissions:  3ABC4DEFG3HI

    The problem is that the message is transmitted in binary as (in hexadecimal):  0341424304344546470348494A
    An error of any type in the Count field (e.g. a single bit error changes 210 = 000000102 to 13010=100000102) can cause the receiver to lose count without hope of recovery.
  • Character stuffing
  • Special start/end characters can be used (e.g. STX to start and ETX to end a frame) but these characters cannot then occur in the message itself, only for framing.
  • Character stuffing uses the special start/end characters for framing and allows those characters in the message also. The method is for the sender to stuff an extra special character whenever the start or end character occurs naturally so that within the message the special character always occurs in pairs. The receiver recognizes the single special character as start/end and removes from the message the first special character from pairs received. Using the special character of <DEL> and <STX> and <ETX> for start/end framing, the message:

                AB<DEL>C<STX><ETX>DE 

    would be sent as (stuffed characters are underlined):
      <STX>AB<DEL><DEL>C<DEL><STX><DEL><ETX>DE<ETX>...<STX>
    If the receiver loses track it can wait for the next <STX> to locate the next frame. <DEL><STX> would be recognized as data since a <DEL> in data is stuffed as <DEL><DEL>. One problem is the dependency on use of the 8-bit ASCII code.
How would the following data be sent using character stuffing?
  • ABC
  • <DEL><STX>A<DEL><ETX>
  • Bit stuffing - Similar to character stuffing except a special bit pattern used to flag framing (e.g. 111111 marks the start of a frame). If that pattern naturally occurs (e.g. the data contains 6 1's, 111111) the sender stuffs in a 0 after natural 5 1's (11111 becomes 111110). To the receiver all 111111 are framing and all 111110 should have the 0 removed to become 11111. As with character stuffing, on a framing error the receiver can wait for the next framing bits to locate the next frame.
How would the following data be sent using bit stuffing as described above using a framing flag of 111111?
  • 0000
  • 1111111111
  • Physical layer coding violations - The message itself is encoded as 0's and 1's. The framing information is some signal that does not correspond to a legal 0 or 1. With Manchester encoding below, 1 is High/Low and 0 is Low/High so framing flag could be Low/Low with no rise or fall, something that cannot occur in the message.

No comments:

Post a Comment