Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 4 CRC, PDR vs. distance, preamble sampling Thomas Watteyne EE290Q – Spring 2010

Similar presentations


Presentation on theme: "Lab 4 CRC, PDR vs. distance, preamble sampling Thomas Watteyne EE290Q – Spring 2010"— Presentation transcript:

1 Lab 4 CRC, PDR vs. distance, preamble sampling Thomas Watteyne EE290Q – Spring 2010 http://wsn.eecs.berkeley.edu/290Q

2 2 CRC: Cyclic Redundancy Check If PKTCTRL0.CRC_EN=1: – At Tx, data is hashed and result append to the packet as a 2-byte field – At Rx, data is hashed and result compared to CRC field, packet dropped if fails How CRC works – Calculate the remainder of a (binary) division – In CC2500, CRC-16-IBM (x 16 + x 15 + x 2 + 1) Single bit errors100% Double-bit errors100% Odd-Numbered errors100% Burst Errors Shorter than 16 bits100% Burst Errors of exactly 17 bits99.9969% All other burst errors99.9984%

3 3 CRC: Cyclic Redundancy Check 11010011101100 1011 01100011101100 1011 0111011101100 1011 010111101100 1011 00001101100 1011 0001101100 1011 001101100 1011 01101100 1011 0110100 1011 011000 1011 01110 1011 0101 Pick a CRC length – e.g. 3 bits Pick a polynom – e.g. x 4 +x+1 (1011) – (Always a leftmost 1!) While bits in data – Write under leftmost data bits – iif leftmost data bit is 1, XOR (leftmost bit always turns to 0) – Shift right one place Collect 3-bit CRC

4 4 The Importance of CRC [1/3] lab4_crc #include "radios/family1/mrfi_spi.h" #include "mrfi.h" mrfiPacket_t packetToSend; int main(void) { BSP_Init(); P1REN |= 0x04; P1IE |= 0x04; MRFI_Init(); mrfiSpiWriteReg(PATABLE,0xBB); mrfiSpiWriteReg(PKTCTRL0,0x41); P3SEL |= 0x30; UCA0CTL1 = UCSSEL_2; UCA0BR0 = 0x41; UCA0BR1 = 0x3; UCA0MCTL = UCBRS_2; UCA0CTL1 &= ~UCSWRST; MRFI_WakeUp(); MRFI_RxOn(); __bis_SR_register(GIE+LPM4_bits); } Enable UART reduce the Tx Power for more frequent errors disable CRC

5 5 The Importance of CRC [2/3] void MRFI_RxCompleteISR() { uint8_t i; P1OUT ^= 0x02; mrfiPacket_t packet; MRFI_Receive(&packet); char output[] = {" \r\n"}; for (i=9;i<packet.frame[0];i++) { output[i-9]=packet.frame[i]; } TXString(output, (sizeof output)); } when receiving a packet Copy RXFIFO to “packet” format string send string over serial lab4_crc

6 6 The Importance of CRC [3/3] #pragma vector=PORT1_VECTOR __interrupt void Port_1 (void) { P1IFG &= ~0x04; char character = 'a'; uint8_t index; mrfiPacket_t packet; for (index=9;index<30;index++) { packet.frame[index]=character++; } packet.frame[0]=++index; MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); P1OUT ^= 0x01; } when button is pressed comment out for continuous Tx Fill frame with ‘abcdef…’ Copy to TXFIFO and send lab4_crc

7 7 Channel Success Probability Receiver listens When button pressed sender sends a burst of packets – 100 packets with counter from 1 to 100 – 20 packets with counter to 101 When receiving a packet – If packet counter <101, increment a counter and store the RSSI – For the first packet with counter==101, display “average RSSI – channel success probability”

8 8 Channel Success Probability [1/4] #include "mrfi.h" uint8_t counter, num_received, bool_counting; int16_t cumulative_rssi; mrfiPacket_t packet; void print_probability(int16_t cumulative_rssi, uint8_t number) { char output[] = {" 000 0.00\n"}; if (cumulative_rssi<0) { output[0]='-'; cumulative_rssi=-cumulative_rssi; } output[1] = '0'+((cumulative_rssi/100)%10); output[2] = '0'+((cumulative_rssi/10)%10); output[3] = '0'+ (cumulative_rssi%10); output[5] = '0'+((number/100)%10); output[7] = '0'+((number/10)%10); output[8] = '0'+ (number%10); TXString(output, (sizeof output)-1); } e.g. “-55 0.75” Prepare string transmit string over serial lab4_pdr

9 9 Channel Success Probability [2/4] int main(void) { BSP_Init(); P1REN |= 0x04; P1IE |= 0x04; MRFI_Init(); mrfiSpiWriteReg(PATABLE,0x50); P3SEL |= 0x30; UCA0CTL1 = UCSSEL_2; UCA0BR0 = 0x41; UCA0BR1 = 0x3; UCA0MCTL = UCBRS_2; UCA0CTL1 &= ~UCSWRST; MRFI_WakeUp(); MRFI_RxOn(); __bis_SR_register(GIE+LPM4_bits); } when button is pressed enable serial communication Wait for interrupts in low power mode lab4_pdr

10 10 Channel Success Probability [3/4] void MRFI_RxCompleteISR() { P1OUT ^= 0x02; MRFI_Receive(&packet); counter = packet.frame[9]; if (counter==101) { if (bool_counting == 1) { print_probability(cumulative_rssi/num_received,num_received); } bool_counting=0; num_received=0; cumulative_rssi=0; } else { bool_counting=1; num_received++; cumulative_rssi+=(int8_t) packet.rxMetrics[0]; } When I receive a packet lab4_pdr

11 11 Channel Success Probability [4/4] #pragma vector=PORT1_VECTOR __interrupt void interrupt_button (void) { P1IFG &= ~0x04; P1OUT ^= 0x01; mrfiPacket_t packet; packet.frame[0]=8+3; for (counter=1;counter<101;counter++){ packet.frame[9]=counter; MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); } for (counter=0;counter<20;counter++){ packet.frame[9]=101; MRFI_Transmit(&packet, MRFI_TX_TYPE_FORCED); } when button is pressed lab4_pdr


Download ppt "Lab 4 CRC, PDR vs. distance, preamble sampling Thomas Watteyne EE290Q – Spring 2010"

Similar presentations


Ads by Google