nrf24lo1程序
This chapter will give a state machine description of the frequency agility protocol for amouse and a keyboard communicating with a dongle at the PC side of the link.APPLICATION NOTEFrequency Ayility Protocol for nRF24XXacknowledgement cycle takes about one millisecond. It is therefore not likely that a frequencyhopping system will cause a change in frequencyIf all three attempts to send a packet fail, the mouse and dongle will change channel accordinto a table. The table is built up to take care of the functionality that avoids disturbance fromthe same source at the new channel. figure 2 shows a typical table with channels used by thefrequency agility protocol. The table is"WLAN weighted, " meaning it will find the nextchannel outside of the assumed Wlan channel that is disturbing the currently used channelIndex channel Frequency MHz240224322470240542435524686240824396524652411102442462Figure 2: Example of a WLAN weighted channel tableAs seen from the Figure 3 the Wlan traffic can be found in three sub-bands in the 2. 4GHzband. Looking at Figure 2 and Figure 3 we'l see that the table in Figure 2 will take care ofmoving the traffic out of a disturbing Wlan channelWLANWLANWLANFigure 3: WLAN channels in the 2. 4GHz bandIf a channel is found to be very noisy, it is desired not to use that channel again. a timing ofhow long a channel has been used before disturbance occurs will tell how noisy the channelis. Channels that are found to be too noisy can be masked out for a period of time masked outchannels will not be used for a whileNordic Semiconductor ASAVestre Rosten 81, N-7075 Tiller, NorwayPhone+4772898900Fax+4772898989Revision: 1.0Page 3 of 2October 2004APPLICATION NOTEFrequency Ayility Protocol for nRF24XXImplementationThis chapter will give a state machine description of the frequency agility protocol for amouse and a keyboard communicating with a dongle at the Pc side of the link4. 1. The mouse implementatiFigure 4 shows the complete state machine of the frequency agility protocol running in themouse. The following text will explain the different statesRSC++十RSC<2Movement orbutton eventIn useto dongleWait for AcKmovementRF updatingTimeoutWait foruser evenendDongle still presentsleep" packetfrcqucncyto dongleUpdate andWait forchannel loootime outFigure 4. State machine diagram of the protocol on the mouse sideIdle. No movement. No rf is the state where the user does not use the mouse. This is thestate where the mouse spends most of its time. In this state, the mouse will only poll formovement. There is no rf communication going on hereAs soon as a user event occurs, the mouse will go into the Idle, In Use, RF updating statethis state, the mouse will send a packet to the dongle by entering the Send Packet to Donglestate every millisecond. The packets are sent with a fixed interval even if no new user data1s presentAfter finishing sending the packet, the mouse moves to the state Wait for ACKacknowledgement. Normally an acknowledgement will be received from the dongle and themouse returns to the Idle, In Use, RF updating state. This loop is the normal communicationNordic Semiconductor ASAVestre Rosten 81, N-7075 Tiller, NorwayPhone+4772898900Fax+4772898989Revision: 1.0Page 4 of 2October 2004APPLICATION NOTEFrequency Ayility Protocol for nRF24XXSometimes, if a packet from the mouse to the dongle gets lost, or an acknowledgement fromthe dongle to the mouse fails to be received a timeout must occur in the Wait for ACK stateWhich state to enter next will then depend on the " Re-Send Counter"(rSC. If it is less thantwo for the current packet, the packet is re-sent by entering the Re-send Packet state. If theRSC equals two, the mouse enters the Change frequency stateIn the Change frequency state it will perform a table look up to find the next channel to useIt will also mask out a channel that is very noisy, preventing use of this channel in closefuture. a background timer telling how long the current channel has been used will give inputto the masking process. If a channel has been used for less than 20ms before a new frequencychange is initiated. it should be masked out The masked out channels should be reset after agiven time periodAfter changing frequency, the mouse enters the wait for dongle to time out state. Since thedongle might has received the packets from the mouse, and it is the acknowledgements thathave been lost that is the reason for the frequency change, the mouse must wait for the dongleto time outThen the mouse will enter the Update and check channel loop counter state where itupdates and check its channel loop counter to determine if the dongle is still present or notThis decision is made from checking how many times the mouse has looped trough thechannel table without contact with the dongle. If the decision is that the dongle is still present,the mouse returns to the send packet to Dongle state if not it returns to the Idle, Nomovement, No RF stateIn the ldle, In Use, RF updating state the mouse will time out if no user evens has notfrom the dongle, the mouse enters the low power state; Idle, No movement, No Re Seme czoccurred in a while. The mouse will then send a"I'm going to sleep"packet to the dongle bentering the send "Go to sleep ?" packet to dongle state. After receiving acknowledgeNordic Semiconductor ASAVestre Rosten 81, N-7075 Tiller, NorwayPhone+4772898900Fax+4772898989Revision: 1.0Page 5 of 2October 2004APPLICATION NOTEFrequency Ayility Protocol for nRF24XX4.2. The keyboard implementationFigure 5 shows the complete state machine of the frequency agility protocol running in thekeyboard. The following text will explain the different statesTimeoutAndPacketRSC<2Key PressedNo rFto DongleWait for AcKACK receivedTimeoutRSC==2Dongle still prefrequenDongle out of rangeUpdate andchannel loopFigure 5: State machine diagram of the protocol on the keyboard sideThe Idle, No rf state is the state where the keyboard is most of its time. In this state it doesnot perform any rf communications. Only when a key press occurs the keyboard enters theSend packet to dongle state.As for the mouse, it will right after sending the packet, enter the state Wait for ACK, where itwaits for an acknowledgement to arrive. Normally it will be received and the keyboard willreturn to the dle. no rf stateIf no acknowledgement is received, the keyboard will perform the same re-send behavior asthe mouse. If acknowledgement still doesnt arrive, the keyboard will change frequency inthe change frequency stateThe keyboard will use a channel table like the mouse, but it will not perform any masking ofchanncls. After changing frequency, the keyboard will also determine if the dongle is presentor not in the Update and check channel loop counter state. If the dongle is still present, itwill return to the Send packet to dongle state where it will try to send the packet to thedongle at the new channel. If the dongle is not present, it will go to the Idle, No RF stateNordic Semiconductor ASAVestre Rosten 81, N-7075 Tiller, NorwayPhone+4772898900Fax+4772898989Revision: 1.0Page 6 of 2October 2004APPLICATION NOTEFrequency Ayility Protocol for nRF24XXAs seen here, the keyboard will follow the mouse and the dongle in frequency. The dongle orthe mouse will not toll the keyboard that a channel change has taken place. The keyboard willtherefore have to run trough its channel table until it finds the dongle, if the mouse and donglehave moved. Since this is a relative rare event, it will not cause any problems for the keyboarduser. The benefit is that the keyboard does not need to receive messages from the donglewhen it rests in the idle state. and will therefore usc minimum of current4.3. The dongle implementationFigure 6 shows the complete state machine of the frequency agility protocol running in thekeyboard. The following text will explain the different statesCheck ifmouseSend ack tomouseRecelvedKeyboard PacketReceivedTimeoutDongle has not received apacket from the mouseSend ack toNokeyboardCheck ifchannelallowedGo to nextYesFigure 6: State machine diagram of the protocol on the dongle sideThe dongle uses the duoCeiver functionality and is able to receive from two differentchannels simultaneously, one for the mouse and one for the keyboardIn the Idle state it checks for received packets from the mouse and the keyboard If two arriveat the same time, it will give priority to the mouse since the mouse requires the highest updaterateNordic Semiconductor ASAVestre Rosten 81, N-7075 Tiller, NorwayPhone+4772898900Fax+4772898989Revision: 1.0Page 7 of 2October 2004APPLICATION NOTEFrequency Ayility Protocol for nRF24XXIf a packet from the mouse is received it will enter the Check if mouse is going to sleep stateand set a flag if the mouse is going to sleep and clear the flag if it is an ordinary packet fromthe mouse. It will then acknowledge the received packet by entering the Send ACK to mousestate and finally return to the Idle stateIf a packet is received from the keyboard, the dongle will acknowledge it by entering theSend ack to keyboard state and then return to the ldle stateIf eight milliseconds elapse without receiving any packets from the mouse, the dongle willenter the Check if channel change is allowed state. If the mouse sleeps the dongle is notallowed to change channel. AlsO, if the dongle has not had communication with the mouse onthe current channel, it is not allowed to change channel. This is done to avoid a" runawaydongleIf the dongle is allowed to change channel it will enter the go to next channel state if not itwill return to the Idle state. In the go to next channel state, the dongle will do the sameexercise as the mouse regarding masking of channels. After an eventual masking the donglewill change its operating channel and return to the Idle state5. Proof of concepta demonstration of this frequency agility protocol exists. Nordic semiconductor hasdeveloped the"nRF24XX Bi-directional mouse/keyboard demo"that runs the frequencygility protocol. This demo can be used to evaluate the protocol running on the nRF24E l inenvironment where WLAN and other 2. 4GHz systems are operatingThe dongle that comes with the"nrF24XX Bi-directional mouse/keyboard demo''can beplugged directly into a USB port. The dongle has a form factor that is very close to a realmouse/keyboard application dongleThe two PS/2 reader boards that comes with the"nRF24XX Bi-directional mouse/keyboarddemo"can be connccted to a PS/2 mouse or a Ps/2 keyboard and then emulate thefunctionality of a wireless mouse and a wireless keyboard Both ps/2 readers can be usedsimultaneously, emulating a real wireless desktop solutionSince the ps/ 2 reader board is not a real mouse or a keyboard it has some limitations Theuser should beware that the "nRF24XX Bi-directional mouse/ keyboard demo? does notinclude the sleep mode for the mouse. Some of the timing constants used by the demo mightalso differ from optimal timing constants in a real mouse/keyboard applicationNordic Semiconductor ASAVestre Rosten 81, N-7075 Tiller, NorwayPhone+4772898900Fax+4772898989Revision: 1.0Page 8 of 2October 2004APPLICATION NOTEFrequency Ayility Protocol for nRF24XX6. Current consumptionThe mouse and the keyboard will have to turn on their receiver while waiting for anacknowledgement to arrive from the dongle. That is the reason why the mouse and thekeyboard will use more current in a bi-directional solution compared to a uni-directionalsolution. In this chapter we'll have a closer look at the current consumption for both themouse and the keyboard6.1. The mouse current consumptionThe calculations shown in Figure 7 give an average current consumption for the rFcommunication when the mouse is usedPacket Length from Mouse to PcP80 bits 8bit preamble, 32 bit address, 24 bit X, Y and ZImovement,8 bit buttons, 8 bit CRCPacket length from Pc to MouseAck56 bits bit preamble, 32 bit address, 8 bit ACK info8 bit crcData rateDR1 MbitnRF24E1 TX current consumption13 mAnRF24E1 RX currnet consumptionIrx19 mAMouse upd ate Rateime in tx modeITime in RX modeTrim300us Long enough to catch a packet, with marginsACK packet is 56 bits long(56us RXstartup time is 202usThis gives 42us spare time to marginsAverage current consumption in TX onlylavgTX0,46mAThis is the average current consumption whenthe mouse is actually usedAverage current consumption in RX onlylavgRX0,71mAhis is the average current consumption whenthe mouse is actually usedAverage current consumption, Two way solution lavg TW1,17|mAhis is the average current consumption whenthe mouse is actually usedFigure 7. Calculation of the average current consumption when the mouse is usedAs seen in Figure 7 the average current consumption for the mouse in use is 1. 17mA. Thecalculation assumes a update rate of onc packet every 8 millisecond. In a real mouseapplication, this will be the current consumption used by the nrF part when the mouse isupdating the dongle. The actual average current consumption will depend on how often themouse is usedNordic Semiconductor ASAVestre Rosten 81, N-7075 Tiller, NorwayPhone+4772898900Fax+4772898989Revision: 1.0Page 9 of 2October 2004APPLICATION NOTEFrequency Ayility Protocol for nRF24XX6. 2. The keyboard current consumptionSince the keyboard does not use the nrf device unless a key is pressed, the average currentconsumption will depend on how often a key is pressed. The calculation in Figure 8 shows thetotal energy used by the nrf device to send a keyboard packet and receive acknowledgementfrom the donglePacket Length from Keyboard to PCP112bits 8bit preamble, 32 bit address, 64 bit payload,bit crcPacket length from PC to KeyboardAck56 bitsabit preamble, 32 bit address, 8 bit ACK8 bit crcData rateDR1 Mbit/snRF24E1 TX current consumptionnRF24E1 RX currnet consumptionTime in TX modeTime in RX moderTT300us Long enough to catch a packet, with marginsAn ACK packet is 56 bits long(56us ) RXstartup time is 202usThis gives 42us spare time to marginsEnergy consumption in TX onlylavgtx 1. 13E-06 mAh Energy used to send the keyboard packetEconsumption in RX onllavgrX 1, 58E-06 mAh Energy used to receive ACkEnergy consumption, Two way solutionlavgTw 2, 72E-06mAh Total energy used pr key pressFigure 8: Calculation of the energy consumption pr key pressThe nrf device uses a total of 2.72 n Ah of energy every time a key is pressedCodeThis chapter shows code examples of the frequency agility protocol It can be used asreference for implementing similar functionality in a real mouse/keyboard applicationThe code will only show the parts needed for the frequency agility protocolHigher level protocol layers must be added by the individual application engineerThe code is written to run on the nrF24E1 8051 coreNordic Semiconductor ASAVestre Rosten 81, N-7075 Tiller, NorwayPhone+4772898900Fax+4772898989Revision: 1.0Page 10 of 22October 2004
暂无评论