Sending data through an 802.15.4 network latency timing.

Information

Problem Resolution

How long does it take to send data through an 802.15.4 network?

Digi's XBee Series 1 radio modules run 802.15.4 firmware, which allows them to transmit data in a point-to-point, peer-to-peer or point-to-multipoint (star) network architecture. The time it takes to transmit a data packet is a sum of the Time on Air and Time for CSMA-CA and Retries, as outlined below.

The 802.15.4 PHY layer allows a maximum 127 bytes per packet, including payload. Due to the size of the packet header, XBee Series 1 modules can send a maximum payload of 100 bytes. XBee Series 2 modules, which utilize more header bytes for ZigBee mesh networking, can send a maximum payload of 72 bytes.

At 2.4 GHz the 802.15.4 PHY layer specifies an RF baud rate of 250 Kbps, which is a 4 us bit time or 32 us byte time. This gives us enough information to compute the "T_air(B)," the actual time on the air taken to send B payload bytes.

The above calculation is assuming 64-bit addressing. It is probably more common to use only 16-bit addressing (modules running ZigBee firmware use this option), which allows us to use a 13-byte header instead of a 25-byte header (subtract 48 bits from 64 bits in both source and destination addressing to reduce a total of 96 bits or 12 bytes). Using 16-bit addressing (non-encrypted-encryption will have to be covered in another article):

T_air(1) = (13 + 1) * 32 us = 0.448 ms

T_air(72) = (13 + 72) * 32 us = 2.720 ms

T_air(100) = (13 + 100) * 32 us = 3.616 ms

T_air(B) = 0.416 + 0.032B ms

Time for CSMA-CA and Retries

The above calculations are the "on-air" time only. The total time it takes to transmit an 802.15.4 packet includes the time for CSMA-CA and retries, where applicable.

CSMA-CA stands for Carrier Sense Multiple Access - Collision Avoidance. This basically means that before a radio actually begins transmitting on the air it senses the carrier channel to make sure the air waves are clear (called CCA-Clear Channel Assessment). If it senses strong enough activity on the channel, it will perform a random delay (backoff/wait time) and then try again with another CCA.

For a diagram of the CSMA-CA algorithm, see page 172 of the IEEE 802.15.4-2006 spec. For easier reference we provide an outline of the basic steps here:

Perform random delay.

Perform CCA.

Transmit if CCA is clear. If channel is not clear, then repeat steps 1-3 up to 4 more times.

Done if broadcast (no acknowledgment/retry). If unicast:

Wait for ACK (acknowledgment of packet received) from destination node.

Done if ACK is received. Repeat steps 1-4 up to 3 more times.

Following are the computations for the above steps:

Perform random delay. The random delay function is (0 : 2^BE - 1) * 0.320 ms, where BE starts at RN and increments each time (up to max value of 5) through the loop until step 3 is cleared. (RN is default 0; it is a user-settable parameter for random delay on the XBee 802.15.4). The "0 : à" means it chooses a random number between 0 and...

Perform CCA. This step always takes 0.128 ms.

No computation on this step.

Wait for ACK. This step takes up to 0.864 ms.

No computation on this step.

Total Transmit Time

Let''s do some examples to compute "T_total(B)," the total time taken to send B payload bytes.

Best case:

Broadcast 1 byte, RN = 0

Random Delay = (0 : 2^0 - 1) * 0.320 = 0 ms

CCA = 0.128 ms

T_air(1) = 0.448 ms

T_total(1) = 0 + 0.128 + 0.448 = 0.576 ms

(Note: We assumed CCA was clear for "best case." Then we used the T_air(B) formula from the first section above to calculate the transmit time. Broadcasts use 16-bit addressing.)

To generalize this "best case" timing calculation (works for both broadcast and unicast since "best case" assumes no time spent waiting on the ACK in step 4.a):

16-bit: T_total(B) = 0.544 + 0.032B ms

Similarly, we can compute the "best case" timing for a 64-bit addressed unicast packet, assuming ~0 time spent waiting on the ACK:

To generalize this "worst case" timing calculation for a broadcast message:

T_total(B) = 9.376 + 0.032B ms

[Keep in mind it is highly unlikely that the largest number would be chosen from the random number function every time. Perhaps a more likely scenario would be to choose the middle value (e.g. (0 : 15) would yield 7.5, on average).]

Worst case:

Example: 16-bit Unicast 72 bytes, RN = 0

Worst case CSMA-CA section: 8.96 ms

T_air(72) = 2.72 ms

Wait for ACK = 0.864 ms [Assume ACK failed.]

(Retry #1)

Worst case CSMA-CA section: 8.96 ms

T_air(72) = 2.72 ms

Wait for ACK = 0.864 ms [Assume ACK failed.]

(Retry #2)

Worst case CSMA-CA section: 8.96 ms

T_air(72) = 2.72 ms

Wait for ACK = 0.864 ms [Assume ACK failed.]

(Retry #3)

Worst case CSMA-CA section: 8.96 ms

T_air(72) = 2.72 ms

[Success on final attempt! Assume ~0 time was spent waiting on ACK.]

T_total(72) = ((8.96 + 2.72 + 0.864) * 4) - 0.864 = 49.312 ms

To generalize this "worst case" timing calculation for a 16-bit unicast message:

T_total(B) = ((8.96 + 0.416 + 0.032B + 0.864) * 4) - 0.864 ms

T_total(B) = 40.096 + 0.128B ms

The final case that could be calculated here is the "worst case" timing for a 64-bit unicast message. This calculation is left for the reader to perform.