Beruflich Dokumente
Kultur Dokumente
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.
2.0 Objective:
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.
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.
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.
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.
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.
True
Move Digit 9
to TXREG to be
transmitted
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.
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.
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
True
False
Activate
Dog Collar
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.
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
BANKSEL PIR1
GOTO Transmit
BANKSEL TXREG
MOVWF TXREG
GOTO Transmit
BANKSEL PIR1
GOTO $-1
MOVF RCREG,W
MOVF D1,W
BTFSC STATUS,Z
GOTO On_LED