Difference between revisions of "IR communication between PICs"

From Mech
Jump to navigationJump to search
Line 13: Line 13:
[[Image:IR_circuit.jpg|thumb|600px|Circuit Diagram]]
[[Image:IR_circuit.jpg|thumb|600px|Circuit Diagram]]


===Electrical Characteristics===
''µController (PIC18F4520)''
''µController (PIC18F4520)''
*V<sub>DD</sub> = 5.0V
*V<sub>DD</sub> = 5.0V

Revision as of 03:58, 6 February 2008

Overview

Using serial communication, two PICs can easily communicate with one another. A basic extension, IR communication can easily be set up for a microcontroller (PIC) by using an IR Encoder/Decoder (Endec) and an IR Transceiver. The endec and transceiver used in this example support Serial IR (SIR) data rate, ranging from 9.6 kpbs - 115.2 kpbs. The typical range of the transceiver is nominally between 2in to 2ft, extending upwards of 12ft. The UART, endec, and transceiver used all support bidirectional use. However, due to the fact that when a transceiver is transmitting, it essentially blinds its receiver and therefore cannot attain true full-duplex communication, only half-duplex, taking turns transmitting and receiving.

When transmitting, the PIC sends the serial format data to the endec, who receives this serial data and encodes (or modulates) it bit by bit. This encoded data is then output as electrical pulses to the transceiver. The transceiver will then convert these electrical pulses to IR light pulses. On the receiving side, the transceiver receives IR light pulses (data), which are outputted as electrical pulses. The endec decodes (or demodulates) these electrical pulses, with the data then being transmitted by the endec UART back to the receiving PIC. This modulation/demodulation method is performed in accordance with the IrDA standard.

Copper-Clad Board

Both the PIC and the endec used in this example were DIP packages, making them easy to prototype and inspect. The transceiver, however, was a surface mount chip with an uncommon pin configuration (.95 mm pitch), requiring a different approach. We initially attempted to etch a copper-clad board for our circuit (see image). Another possible solution for our transceiver is to use a SchmartBoard. These boards are more general and prefabricated for use with surface mount ICs (with a particular pitch or pin seperation). Both solutions will allow for connections to a solderless breadboard.

Circuit

The Circuit Diagram shows the layout of the PIC, Encoder/Decoder, and IR Transceiver combination. Two of these set-ups are needed in order to have two independent circuits: one to transmit and one to receive data. The specifications of the circuit are as follows:

Circuit Diagram

Electrical Characteristics

µController (PIC18F4520)

  • VDD = 5.0V
  • C1 = 1µF
    • Pin 11 or 32 can be used for VDD
    • Pin 12 or 31 can be used for GND

IR Encoder/Decoder (MCP2122-E/P)

  • VDD = 5.0V (1.8V-5.5V)
  • CBYP = 0.01µF

IR Transceiver (TFDU4300-TR1)

  • Vcc1 = 5.0V (2.4V-5.5V)
  • Vcc2 = 5.0V (-0.3V-6.0V)
  • Vlogic = 5.0V (1.5V-5.5V)
  • R2 = 47Ω
  • C2 = 0.1µF


The links to the data sheets for the Encoder/Decoder and the IR Transceiver can be found in the External Links sections.

  • PIC interfaces serially with EnDec
  • EnDec connected to transceiver through a transmit pin, a receive pin, and a Vlogic pin?
  • Transceiver manufactured by Vishay Semiconductors
    • Part # TFDU4300
  • EnDec manufactured by Microchip
    • Part # MCP2122

Surface Mount Prototyping

  • Transceiver lead pitch = 1.2mm/0.95mm/0.50mm/0.45mm?
  • Multiple options for installation
    • Schmart board
    • Digikey board (need to find)
    • Copper-clad board etching
    • Funky pin adapter thing Prof. Peshkin gave us
    • Funky adapter thing #2 Prof. Peshkin gave us

Limitations

  • Transceiver cannot simultaneously transmit and receive

Code

Example code for a simple IR communication circuit w/o the use of a transceiver:

/*
  ircomm.c Jennifer Breger, Brian Lesperance, Dan Pinkawa 2008-02-05
  Using the PIC's built-in UART, a counter continually is sent to one IR encoder/decoder.  Then
  the first IR encoder/decoder feeds its TXIR to the RXIR of a second IR encoder/decoder.  The 
  second IR encoder/decoder then transmits back to the PIC what it is receiving.  When the
  transceiver circuit is properly mount and inserted into the circuit, this code can be adapted
  for half-duplex communication w/ another IR communications circuit.
*/

#include <18f4520.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay (clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, stream=com_a) // Initializes the UART to 9600 bps 
                                                             // (up to 115,200 bps)

// timed_getc() checks whether data is ready to be read.  If it's not the function returns a null
// character.  If you simply use getc(), the PIC might get slowed up if the data isn't ready right
// away.
char timed_getc(void){
   long timeout;
   int timeout_error = FALSE;
   timeout = 0;
   while(!kbhit() && (++timeout<50000))
      delay_us(10);
   if (kbhit())
      return(getc());
   else {
      timeout_error = TRUE;
      return(0);
   }
}

// Main program
void main(void){
   int i;
   char rx;

   setup_timer_2(T2_DIV_BY_1, 32, 16); // Provides a 151.3 kHz clock for the Encoder/Decoder, in   
   setup_ccp1(CCP_PWM);                // order for it to know the baud rate of the UART. Should be 
   set_pwm1_duty(16);                  // closer to 16 * 9600 = 153.6 kHz but the error is tolerable

   while(TRUE){
      for(i=0;i<16;i++){      // Counts up from 0 to 15 and transmits to the first Encoder/Decoder.
         putc(i);             // Listens to the second Encoder/Decoder, which is simply the original
         rx = timed_getc();   // message from the PIC, and displays the value on the LEDs/Port D.
         output_d((int8) rx);
         delay_ms(1000);
      }
   }
}

External Links and Further Reading

Relevant Technical Articles