Showing posts with label IR. Show all posts
Showing posts with label IR. Show all posts

Friday, 22 July 2011

SIRC Part III - Encoding and Decoding


In this post, We examine sample codes for encoding and decoding using Arduino.
Encoding:
     The frequency of the carrier signal to be sent is 40 KHz. Hence, it takes 25 micro-seconds for one cycle. Each cycle consists of ON and OFF time. The duty cycle denotes the ratio between ON time and Time Period. The duty cycle recommended by SIRC protocol is 1/4 or 1/3. Here we use a duty cycle of 25% (1/4). Hence, the number of cycles required to complete each type of bit is listed below:
              Start bit: ( 2400(uS)/25(uS) ) = 96 cycles
               '1' bit : ( 1200/25 ) = 48 cycles
               '0' bit : ( 600/25 ) = 24 cycles
A sample program for encoding the signal is given below:

void setup()
{
           Serial.begin(9600);
           pinMode(14,OUTPUT);      // IR LED is connected to pin14
}
int sum=0;
void transmit(int command)
{
        // Here we dont add the start bit to the array
        //Array arr[] represents just the data bits
        // We create the start pulse manually using pulse(int) function
        // We declare an array containing all the data bits (arr[])
        // i--> index variable
        int arr[12],i=0;
        // Here we convert the decimal value of command to binary value,
        // And store it in the array arr[]
        // From LSB to MSB
        while(command>0){

                    arr[i]=command%2;
                    command/=2;                    
                    i++;
        }
        // Now we have converted the decimal to binary
        // But we need to fill the empty digits to '0'
       for( i ; i<7 ; i++ )

               arr[i]=0;

              //Adding the address bits
              // For testing purpose, we use TV, address for TV is 10000 (5 bit data)
              // Now value of i is 7
              // Which represents the 8th position
              arr[i]=1;
              i++;
             // Now value of i is 8
             // Which represents the 9th position (9,10,11,12)--> 4 iterations

            for( i ; i<12 ; i++ )
                  arr[i]=0;
                  // Last 5 bits now look like 10000 which denotes address of TV
                  //Manually pulsing the start bit (2400 uS)
                  pulse(96);              //96*25=2400;
                 //Pulsing all the data bits
                 for(i=0;i<12;i++) {
                       if(arr[i]) {
                              pulse(48);
                       } else {
                             pulse(24);
                       }
                 }
               //The total time of one set of data (one frame) is 45 mS (ie) 45000 uS                  
               digitalWrite(14,0);
               delayMicroseconds((45000-sum));
}

// The pulse function for pulsing bits
// 25% duty cycle
// followed by 600 uS space
void pulse(int dur)
{
               for(int j=0;j<dur;j++) {

                      digitalWrite(14,1);
                      delayMicroseconds(6);
                      digitalWrite(14,0);
                      delayMicroseconds(19);
               }
              delayMicroseconds(600);
}
void loop()
{
          transmit(21);
          transmit(21);
          transmit(21);
          delay(3000);
}


Decoding:
          Decoding is relatively easier than encoding. A sample coding which is self-explanatory is given below:


void setup()
{
          Serial.begin(9600);       //Setting Baud Rate
          pinMode(15,INPUT);    //IR TSOP receiver is connected to PIN 15                   
}

int remote()
{
            // i--> index variable
            // arr[]--> array that stores digital word
            // val--> stores the decimal format of arr[]
            int i=0,arr[8],val=0;
            //Checking the start bit
            if(pulseIn(15,0)>2000) {
                  //Storing the digital word in arr[]
                  for(i=0; i<7 ; i++,arr[i] = pulseIn(15,0)) ;
                  //Converting digital word into decimal value
                  //Storing it in val
                    for(i=0;i<7;i++) {
                           if(arr[i]>1000) {
                                   val=val+(1<<i);
                           }
                    }
            }
           return val;
}
void loop()
{
            int checkVal=remote();
            if(checkVal);
            Serial.println(checkVal);
}

Coming up next:

          * Practical model

          * Building a project ( An Universal Remote)


SIRC Part II - Arduino

More Parameters:
  Frame Timing:
             The signal to be transmitted is encoded to a form known as a "Frame", which represent 13 bits including start bit. Each bit in the frame is a combination of high and low voltage levels (high followed by low). The pulse-width of each type of bit is listed below:
        Pulse-Width: T = 0.6ms
        Start Bit: (2.4 + 0.6) ms = 3 ms = 5T
        '0' Bit: (0.6 + 0.6) ms = 1.2 ms = 2T
        '1' Bit: (1.2 + 0.6) ms = 1.8 ms = 3T
  Repeat Rate:
            Each frame is repeated atleast 3 times during transmission at an interval of 45 ms.
 What next?
           We have necessary data to start our project. We'll do the following tasks to gain practical experience on this:
                 * Develop an algorithm for encoding the signal to be transmitted.
                 * Produce the encoded signal with the help of a micro-controller.
                 * Transmit the signal through an IR LED in the form of IR.
                 * Recieve the signal using an IR TSOP receiver.
                 * Develop an algorithm for decoding the encoded signal.
                 * Display decoded data on the monitor.


A Platform to Move on: Arduino, a stable, famous and easy-to-understand Platform.  
      What is Arduino?
                   Arduino is a prototyping platform(AVR uC with some generic circuitry) with its own Software Development IDE(Arduino). We dont study much about Arduino here. Instead, We just use it as a tool to test our knowlege. The pictoral representation of Arduino Duemilanove is given below:
         The above figure will give you a good idea about the board. Either Atmega 168 or Atmega 328 can be used along with this board. It has 14(0 - 13) digital pins and 6(14 - 19) analog pins. We use one of those to produce the required signal. We connect an IR LED to that pin and convert the signal into IR form.
To know more about the features of Arduino Duemilanove, Click here.

Arduino IDE:
          Arduino software is one of most user-friendly software built so far. The programs created using this IDE are called as "Sketches". General structure of sketch is

//beggining of sketch
//global declarations goes here
//function definitions also goes here
void setup()
{    
     // here initial settings are done.
     // This function is executed only once
}
void loop()
{
     // here exact set of instructions are written, which will be performed again
     // and again by the controller
}
//end of sketch

All the standard functions to be used can be studied from the following link: Click Here....
Coming up next:
       * Encoding and Decoding codes
       * Practical model
       * Building a project ( An Universal Remote)

Tuesday, 21 June 2011

SIRC Part I

BASICS
  
Wireless infrared communications refers to the use of free-space propagation of light waves in the near infrared band as a transmission medium for communication. Signals sent are encoded using a an encoding algorithm in the transmitter circuitry and is decoded and the essential information is obtained at the receiver part. IR communication is a basic form of wireless communication. It's frequency range is 32-60 KHz. There are several protocols for IR communication. Some are Sony's SIRC, Phillips RC5 protocols.

 SIRC (Sony Infra Red Communication Protocol), is an IR communication protocol for controlling SONY equipment. It consists of three versions based on bit length (12, 15, 20 bit). For convenience, we here discuss about 12 bit version of SIRC. Here Pulse Width Modulation (PWM) is made use of.

  The 13 bits are divided into 12 data bits and 1 start bit. The start bit indicates the start of the information and the following 12 bits indicate the information itself. The data bits are further classified into address and command. The seven bits followed by the start bit represent the command (from LSB to MSB) (ie) in reversed manner. The following 5 bits represent the address in reversed manner. 


What is a command and address?

Command:
    It is more of a self defining term. It consists of a digital word that will server as a command to the receiving system. The following table gives the commands and their digital values in a Sony IR remote.


Command
Function
0
Digit key 1
1
Digit key 2
2
Digit key 3
3
Digit key 4
4
Digit key 5
5
Digit key 6
6
Digit key 7
7
Digit key 8
8
Digit key 9
9
Digit key 0
16
Channel +
17
Channel -
18
Volume +
19
Volume -
20
Mute
21
Power
22
Reset
23
Audio Mode
24
Contrast +
25
Contrast -
26
Colour +
27
Colour -
30
Brightness +
31
Brightness -
38
Balance Left
39
Balance Right
47
Standby



Address:
   It is a digital word that represents the address of the receiving system. Sony has unique address for its products. The following table gives the digital address for various Sony equipment.


AddressDevice
1TV
2VCR 1
3VCR 2
6Laser Disc Unit
12Surround Sound
16Cassette deck / Tuner
17CD Player
18Equalizer


How does a signal to be transmitted look like?

   The following figure gives a rough idea about how the signal looks like:


  The data bits to be transmitted consist of marks and spaces. The marks are the high regions in terms of voltage while spaces are the low regions. Digital high (1) is represented by a mark of 1.2 ms (milli seconds) and digital low (0) is represented by a mark of 0.6 ms ( PWM). The time period of a start bit is 2.4 ms. A space is always represented by 0.6 ms low with respect to voltage.


What is PWM?

       PWM (pulse width modulation) is an encoding process where variation of width of each pulse is used to show the variation in the actual data.


Basic materials for transmission:
      We use an IR LED to transmit PWM signal and an IR receiver to receive the transmitted signal. The receiver always inverts the signal after which the decoding process is done.


 Coming Up :

    * More parameters

    * A platform to move on

    * Encoding and Decoding codes

    * Practical model

    * Building a project ( An Universal Remote)

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More