O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

14849441 rf-wireless (1)

2.575 visualizações

Publicada em

RF Design

Publicada em: Tecnologia
  • Seja a primeira pessoa a gostar disto

14849441 rf-wireless (1)

  1. 1. TITLE : Implementing Wireless Remote Control Using Radio Frequency Module NAME : Thian Nyuk How Matrix Number : HK2006-3092 DATE : 24 MARCH 2009 Abstract: This application note is about implementing wireless remote control using a Radio Frequency (RF) module interface with microcontroller. Asynchronous mode in Universal Synchronous and Asynchronous Receiver Transmitter (USART) will be introduced in interfacing the RF module with a microcontroller. 1.0 Introduction: Radio frequency (RF) usually refers to oscillations in electrical circuits. It is normally use in wireless communication system to transmit data. By modulating data signals onto the RF carrier signal, data can be transfer from one point to the other point easily. In this application note, a pair of RF module with a frequency of 433 MHz is used. To interface RF module with microcontroller, Universal Synchronous and Asynchronous Receiver and Transmitter (USART) or also known as Serial Communications Interface is used. USART is used for transmit and receive serial data. The operation of USART can be divided into two types which is synchronous and asynchronous. Synchronous mode uses a clock and data line. Asynchronous mode does not use clock accompanying the data.. However in this application note, only asynchronous mode will be use in interfacing the RF module with the microcontroller. 2.0 Objective: Interface a RF module with microcontroller to build a wireless remote control.
  2. 2. 3.0 Hardware: RF Transmitter Module (433MHz) Specifications RF Transmitter Module Operating Voltage 3V to 12 V Operating Current Max: 400mA for 12 V supply Min: 9mA for 3V supply Frequency 433MHz Transfer Rate 10Kbps Antenna Length 18cm Table 1.1 Specification of RF Transmitter Module There are 3 pins to connect in the RF Transmitter module. The DATA pin is connected to the TX pin of the Microcontroller. VCC pin connect to the supply voltage and GND connect to ground. The antenna can extend with any wire but for better result, a 50 Ohm coaxial cable is used. The length of the wire as antenna is about 18cm long. RF Receiver Module (433MHz)
  3. 3. Specifications RF Receiver Module Operating Voltage 5.0V ± 0.5V Operating Current ≤5.5mA for 5.0V supply Frequency 433MHz Transfer Rate 10Kbps Antenna Length 18cm Table 1.2 Specifications of RF Receiver Module There are 5 pin to connect for the RF receiver module. The DATA pin of the RF Receiver Module is connecting to the RX pin of microcontroller. The VCC pin connects to the 5v supply and the GND pin to ground. The ANT is the antenna of the receiver and can be extend with any wire. The length of the wire is 18cm for better result. 4.0Interface RF Transmitter and Receiver with Microcontroller: 4.1 Register and Flag bit Description which will be used : Register Name Description TXSTA Transmit Status and Control RCSTA Receive Status and Control TXREG Write Transmit Data Register RCREG Write Receive Data Register SPBRG Setting Baud Rate PIR1 Peripheral Interrupt Flag Register PIE1 Peripheral Interrupt Enable Registers Table 1.3 Register and Description which will be used Flag Bit Name Description TXIF Located in PIR1 (bit 4) which is use to check whether TXREG is Full or Empty RCIF Located in PIR1 (bit 5) which is use to check whether RCREG is Full or Empty OERR To test over run error for the RCREG Register TXEN Transmit Enable of Disable bit Table 1.4 Description of flag bit that will be used
  4. 4. 4.2Interfacing Transmitter with Microcontroller PIC16F628A: Figure 1.1 Remote Control (Transmitter circuit) In the schematic of the remote control show in Figure 1.1, the microcontroller used is PIC16F628A. To connect a RF transmitter module with PIC16F628A, the data pin of the transmitter need to connect to the TX pin of the PIC which is pin 8 for PIC16F628A. TX pin is for the use of serial communication interface which will transfer 8 bit data to the transmitter to be transmit. To enable the TX port as a serial port, SPEN which is bit 7 in RCSTA have to be set. Bit two in TRISB of PIC16f628A have two be clear in order to make the TX pin as an output pin. TXSTA is the transmit control register for the PIC. This register has to be initializing correctly in order to make the transmitter work. By referring to the data sheet, the source code in this application note, the TXSTA is initialized as B'00100000' which mean that it transmit 8bit data in asynchronous low speed mode. Figure 1.2 shows the representation of each bit of the TXSTA register. Next is to set the baud rate of the transmitter.
  5. 5. Figure 1.2 Representation of Each Bit in TXSTA Register Baud rate refers to the speed at which the serial data is transferred, in bits per second. In Asynchronous mode, the baud rate generator sets the baud rate using the value in the SPBRG register. The BRGH bit in TXSTA selects between high and low speed options for greater flexibility in setting the baud rate. From the initialization of TXSTA shown above, the BRGH is clear which mean that the baud rate is in low speed and the SPBRG register in this application note’s source code is set to 255. The Baud rate for both transmitter and receiver must be the same in order for the data transmitted to receive in the receiver. When a digital data is being transmitted, it is transmit from the less significant bit to the most significant bit. This means that the transmitter transmits digital data bit by bit to the receiver. Figure 1.3 show how the signal is transfer in asynchronous mode. Figure 1.3 Signal Transfer in Asynchronous mode
  6. 6. From Figure 1.3 the signal is high when no transmission (or reception) is in progress and goes low when the transmission starts. The receiving device uses this low-going transition to determine the timing for the bits that follow. The signal stays low for the duration of the START bit, and is followed by the data bits, Least Significant bit first. The USART can transmit and receive either eight or nine data bits. The STOP bit follows the last data bit and is always high. The transmission therefore ends with the pin high. After the STOP bit has completed, the START bit of the next transmission can occur as shown by the dotted lines. During transmitting data, the heart of the transmitter is the Transmit Shift Register (TSR). This register obtain the data from the transmit buffer, TXREG. Hence, to transmit a data to the receiver, first is to move the desire transmit data to the TXREG then it will load to TSR to be transmitted. To check whether the data in TXREG had been move to TSR, the flag bit TXIF which located in the PIR1 is checked. If TXREG is empty (means the data already load to TSR) the flag bit TXIF will be set. Hence new data can be load to TXREG to be transmitted next. The Bit TXEN in TXSTA show in Figure 1.2 is always set so that all the data in TSR will be transmit. Appendix 8.1 shows the sample code of transmit a data. Check TXIF False True Move Digit 9 to TXREG to be transmitted Figure 1.4 Block Diagram Showing the transmitter’s program runs
  7. 7. 4.3 Interfacing RF Receiver Module with microcontroller: Figure 1.5 A Testing Receiver Circuit (Receiver Circuit) In the schematic of the receiver circuit show in Figure 1.5, the microcontroller used is PIC16F877A. To connect the RF Receiver Module to PIC16F877A, the data pin of the receiver is connected to the RX pin which is pin 26 for PIC16F877A. RX pin is for the use of serial communication interface which will receive the 8 bit data from the transmitter for further process. Before the receiver able to receive any data from the transmitter and provide to the PIC for further process, initialization for the PIC is needed. RCSTA is the receive control register for the PIC. This register has to be initializing correctly in order to make the receiver work. By referring to the data sheet, for the source code of this application note, RCSTA is initialized as B'10010000' which mean that it continuously receive 8 bit data, asynchronous mode. The SPEN Flag bit in RCSTA have to be set to enable the serial port. The baud rate for the receiver has to be the same with the transmitter. Figure 1.6 shows the representation of each bit of the RCSTA register.
  8. 8. Figure 1.6 Representation of Each Bit in RCSTA Register. When receiving data from the transmitter, the data is first stall in Receive Shift Register (RSR). After that the received data is transferred to the RCREG register when it is empty. Once the transferring process from the RSR to RCREG is complete, the flag bit RCIF will be set. The RCREG is a double- buffered register which mean that it can store two byte of data. When the 2nd data come in but the 1st data have not been read yet, the data will store in the second slot of the RCREG. When the 1st data is read, the 2nd data will move to the 1st slot and new data can be move into RCREG. However, when the RCREG is full and the 3rd data is store in the RSR, the flag bit OERR will be set and the data in RSR will lost. In addition, all the receive process will be stop. Hence it is a must to clear the flag bit OERR in order to retrieve the receiving process. Flag bit OERR can be clear by first clear the CREN and then set it again. Appendix 8.2 shows the sample code to receive date from receiver.
  9. 9. The test receiver circuit show in schematic is connected with two LED which is used to test whether the receiver receive data from the transmitter. If it receive the correct data from the transmitter, will either on or off based on the desire of user to program it. False Move data from Check RCIF TRUE Identify the data receive RCREG to a file True False Activate Dog Collar Figure 1.7 Block diagram showing the receiver’s program runs 5.0 Result: A brief experiment is conducted to test the range of the RF remote control range. Condition Outcome Without Antenna Receive Range less than 5 meters With antenna in closed surrounding Receive range about 25 meters With Antenna in open surrounding Receive range about 35 meters Table 1.5 experimental result of the range of the RF remote control in different condition Another experiment is conducted to test the interference upon the RF module with RF module of different frequency. It is proved that the RF module will not be interfering by the RF module of different frequency. However when two same frequency of transmitter is transmitting data, the receiver will receive error signal which is not the exact signal from both transmitter. 6.0 Conclusion: The RF module perform a satisfy range as a wireless remote control and able to transfer signal through obstacles. Interfacing the RF module with microcontroller through USART shows a stable performance from both the transmitter and receiver.
  10. 10. 7.0 References: 1. Microcontroller Programming, The Microchip PIC, Juliao Sanchez, Maria P.Canton (e-book) 2. Data Sheet Microchip PIC16F877A 3. Data Sheet Microchip PIC16F628A 8.0 Appendix: 8.1 Sample Assembly code of transmit a digit 9 continuously Transmit ; to transmit a digit 9 BANKSEL PIR1 BTFSS PIR1, TXIF ;check flag bit TXIF GOTO Transmit MOVLW D'9' ; move digit 9 to TXREG BANKSEL TXREG MOVWF TXREG GOTO Transmit 8.2 Sample code of Reciever Receiving Data 9 from Transmitter Receive MOVLW D'9' MOVWF H1 ; move digit 9 to file H1 BANKSEL PIR1 BTFSS PIR1,RCIF ; check if RCIF is set GOTO $-1 BANKSEL RCREG ; receive complete MOVF RCREG,W MOVWF D1 ; move receive data to D1 MOVF D1,W SUBWF H1,0 ; check receive data BTFSC STATUS,Z GOTO Receive ; wrong data re-loop GOTO On_LED