Monday, May 4, 2009

Technical 2.4 : (transmitter and receiver)

A experiment is carried out at robocon lab, sktm, ums to test the efficiency of RF (transmitter and receiver). From the analysis above, the result can be concluded when the distance starts to increase the efficiency start to decrease. From 15 m to 19 m, the data receive start to corrupted by surrounding and after 20 m the radio frequency is out of the function.

Technical 2.3 : RF (transmitter and receiver)

Theory and Setting of Asyncronous Mode of USART of Receiver


Circuit diagram of receiver
The 8 led inside the circuit diagram is to make sure that the data receive from transmitter are correct data.
RCSTA is the receive control register for the microcontroller. This register has to be initializing correctly in order to make the receiver work. By referring to the data sheet, the 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.
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. Figure 1.8 shows how the overrun error being detected and how it is solve.




Programming of receiver

Circuit diagram on breadboard

Technical 2.1 : RF (transmitter and receiver)

Interface RF - Module with microcontroller
MPLAB is used as the programming software and c language is used as the programming language. 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. Asynchronous mode will be use in interfacing the RF module with the microcontroller. Table below show the register and flag bit that will be used together with its description.

Sunday, May 3, 2009

Technical 2.2 : RF (transmitter and receiver)

A) Transmitter
Theory and Setting Asynchronous Mode of USART for Transmitter

Circuit diagram for transmitter

In previous post, it is shown that the data pin of the transmitter module is connected to the TX pin of the microcontroller. Seem TX pin normally used as a digital I/O port, to enable the TX port as a serial port, SPEN which is bit 7 in RCSTA have to be set. Bit six in TRISC of PIC16F877A have to be clear in order to make the TX pin as an output pin. TXSTA is the transmit control register for the microcontroller. This register has to be initializing correctly in order to make the transmission work. By referring to the data sheet, the TXSTA is initialized as B'00100000' which mean that it transmit 8bit data in asynchronous low speed mode.


Representation of each bit in TXSTA Register

Next is to set the baud rate of the transmitter. 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 is set to 129 where the rate is 2.4K bit per second. The Baud rate for both transmitter and receiver must be the same in order for the data transmitted to receive in the receiver. The baud rate can be calculated with the formula shown below.

12Desired baud rate= Fosc64/(x+1)/Where, Fosc = frequency of crystal used

X= value that will be set in the SPBRG register

Example:
Taking the desired baud rate = 2.4K
2.4K=20M/64(x+1)
x=129

When a 1 byte 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.
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.



Setup for transmitter

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 6 is always set so that all the data in TSR will be transmit.

The transmitter’s program runs

Programming for transmitter


Circuit diagram on breadboard