This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

read IR PULSE for msp430g2211

Other Parts Discussed in Thread: MSP430G2211, MSP430G2553, MSP430G2231, DRV8313EVM, DRV8313, MSP430F5438

i am  using  msp430g2211  .. actually i having problem in read IR PULSE  .how to read pulse how to get address value and data  for this controller  pls can any one solve this issue..

if possible pls send me a sample code for doing this...

thanks in advance

  • thanks for giving example code . i understand your code .but i am using TSOP2138 ir receiver what i will change that program and how to get correct address bit and data bit using tsop2138  ir

    thanks and regard

    parthiban

  • PARTHIBAN V said:
    thanks for giving example code . i understand your code .but i am using TSOP2138 ir receiver what i will change that program and how to get correct address bit and data bit using tsop2138  ir

    Code is not mine. I guess you have to change nothing. TSOP2138 works same way as many other TV IR remote receivers.

    Notice that IR receivers usually are 5V devices but msp430 supply voltage usually is around 3.3V. So you need voltage level translator between IR receiver and msp430.

  • thanks for reply  how to i design voltage level translator between IR receiver and msp430. pls help me 

  • The family to which TSOP2138 belongs accepts a supply voltage in the range 2.5-5.5 V, so you don't need any voltage translator as far as you power the MSP430 in the range 2.5-3.6 V.

    As TSOP2138 supply current is below 1mA, you could also power it from a GPIO output: doing so, if you are powering from batteries, you could stay in LPM3, enabling the IR receiver periodically with a low duty cycle until an optical signal is detected, then switch to an high duty cycle to decode the signal, until there is no activity for some time and you can go back to low d.c.

    Regards,

    Peppe

  • thanks for reply  .i connect the ir power in msp430 launchpad . i run that sample program  but i got output data=15616,command =0,address=20,toggle =1(all value for decimal ) i check output in put break point its correct way to check output .its wrong means sent correct way to get output ....

    thanks and regard

    parthiban

  • Are you getting same data when press same remote button repeatedly? Does data changes when you press different remote buttons?

  • thanks for reply .i use same remote but press different buttons .i got  same output only .command bit  always in zero.

    how to i get correct output ,where i  put break point and check output  plz help me 

    thanks and regards

    parthiban

  • PARTHIBAN V said:
    where i  put break point

    Try this line:
     switch (command) { // do whatever we want to do with the incoming commands
  • thanks for reply how much time taken to decode the ir signal(TSOP2138) its have 6cycles/burst,am using a sample code for(TSOP38238) its have 10cycles/burst.Kindly help me how  to change the time,i workout the sample code without change i got the same output of (Address = 28;command = 53) in decimal for various buttons.

    thanks and regards 

    parthiban

  • You shall check IR signal using DSO (digital storage oscilloscope), look how exactly it is decoded and find where's problem.

  • thanks for reply .i check the ir signal using DSO . i press the remote buttons i got set of pulse . i press different buttons got set of pulse . but i dont know what the different  for pulse in different buttons.  and i press one buttons repeatedly command bit  not in constant. how to i got correct output in your programs pls help me

    thanks and regards

    parthiban 

  • First thing for you to do: check which IR remote protocol used. Is it RC-5 or not?

    http://en.wikipedia.org/wiki/RC-5

    PARTHIBAN V said:
    buttons repeatedly command bit  not in constant. how to i got correct output

    Analyze input, check decode output, and THINK why you are not getting expected results.

  • thanks for reply Am using NEC protocol ,getting output like this 

    http://wiki.altium.com/display/ADOH/NEC+Infrared+Transmission+Protocol

    For that how can i read this signal? what are things i need to do in the sample program

    thanks and regards 

    parthiban 

  • PARTHIBAN V said:
    For that how can i read this signal? what are things i need to do in the sample program

    1) search internet in hope that someone did it and posted code online

    2) redesign decoder to NEC IR protocol

    3) change your remote to RC-5

  • thank you 

    thanks and regards

    parthiban

  • Hi IImars,

    I am  using  msp430g2553  .. actually i having problem in read IR PULSE  .how to read pulse how to get address value and data  for this controller  pls can any one solve this issue..

    I am using HT6220a encoder for IR Remote and uses NEC-IR protocol, Please send me sample source code if possible......

    please find out the attachment for HT6220a encoder pdf file.

    thanks in advance

    622xAv120.pdf
  • ramesh yerramella said:

    ...  actually i having problem in read IR PULSE  ....

    please find out the attachment for HT6220a encoder pdf file. ...

    HT6220a can be used to generate IR pulses. You cannot uses it to "read IR PULSE".

  • Hi old_cow_yellow,

                   Thank you so much for your immediate response, you are posted that code is really helpful which is working. Thanks a lot for your help. I have been working with this issue over a week. I done it with your help thankyou........!

  • Hi old_cow_yellow,

                     I am having a problem with IR data receiving with msp430 launchpad using NEC protocol. You send me a source code using timers but Now i need to know whether is it possible to read the IR data using UART with msp430g2553 microcontroller. Please send me a source code if it possible.

                    And also iam trying to read the IR data using timer1 in msp430g2553 i made a changes to that code but the code is not working. I attached that code kindly find out in attachments. What are the things i has to be change. Please help me...!

    Thanks in advance.

  • Why do you need to use UART instead of timer? And stop asking source code! Our job is to give advice if we like to respond, not to write code for you. It's your job to write code.

    ramesh yerramella said:
    i made a changes

    What changes?

    ramesh yerramella said:
    but the code is not working.

    To say "it's not working" is the same as to say nothing. Nobody here will build copy of your IR receiver to test your code for you. Please tell how do you test, what is working and what's not. Do you have scope or logic analyzer?

    ramesh yerramella said:
    What are the things i has to be change.

    You have to find yourself - debug your code,check which parts of your code are working and which are not.

  • Hi ilmars,

    I am sorry I posted a wrong document in my last post, I am trying to receive the IR data by using timer1 (P2.1) . I am successfully receive the IR data on Timer0 but problem comes with timer 1. Here is the code for Timer1

    #include <msp430g2231.h>

    // IR pulse timing constants in microseconds

    #define HP_MIN      8500    // Header pulse minimum duration
    #define HP_MAX      9500    // Header pulse maximum duration
    #define HPL_MIN     4100    // Header pulse low minimum duration
    #define HPL_MAX     4800    // Header pulse low maximum duration
    #define RPT_MIN     1900    // Repeat pulse minimum duration
    #define RPT_MAX     2500    // Repeat pulse minimum duration
    #define BP_MIN      450     // Bit pulse minimum duration
    #define BP_MAX      650     // Bit pulse maximum duration
    #define ONE_MIN     2000    // Logical one minumum duration
    #define ONE_MAX     2500    // Logical one maxumum duration
    #define ZERO_MIN    1000    // Logical zero minumum duration
    #define ZERO_MAX    1300    // Logical zero maxumum duration

    #define FALSE 0
    #define TRUE (!FALSE)
    #define IR_REPEAT 0xFF00    // Special repeat code
    #define MAX_DATA_BITS 32    // NEC protocol provides for 32 bits of data

    #define PIN_IR      BIT1    // This must be TA0.1
    #define PIN_LED1    BIT0    // LED1 on the Launchpad

    #define BUTTON_POWER    0x00FD00FF    // This is a code for the button to toggle the LED

    static volatile unsigned long data;

    void ir_init(void)
    {
        _disable_interrupts();
        BCSCTL1 = CALBC1_1MHZ;                  // Set DCO to 1MHz to measure pulses in microseconds
        DCOCTL = CALDCO_1MHZ;
        P2DIR &= ~PIN_IR;                       // Set IR detector pin to input
        P2OUT |= PIN_IR;                        // Set resistor to pull-up
        P2REN |= PIN_IR;                        // Enable resistor
        P2SEL = PIN_IR;                         // set IR detector pin to peripheral function
        TA1CTL = TASSEL_2 | ID_0 | MC_2;         // SMCLK, Continuous mode, Input divider /1
        TA1CCTL1 = CM_3 |  CCIS_0 | CAP | CCIE;  // Capture on both edges, Capture Input Select CCI0A, Capture mode, Capture interrupt enable
        _enable_interrupts();
    }

    void main(void)
    {
        WDTCTL = WDTPW | WDTHOLD;       // Stop the Watchdog timer
        P1DIR = PIN_LED1;               // LED1 to output
        ir_init();                      // Initialize IR detection
        for (;<img src='http://forum.43oh.com/public/style_emoticons/<#EMO_DIR#>/icon_e_wink.gif' class='bbc_emoticon' alt=';)' />                        // Loop forever
        {
            _low_power_mode_0();        // Wait in LPM0 until the IR remote code is received
            // Set a breakpoint on the next line and add a watch for the data variable to see the IR code received
            if (data == BUTTON_POWER)   // If remote power button is pressed
                P1OUT ^= PIN_LED1;      // Toggle LED1
        }
    }
    #pragma vector=TIMER1_A1_VECTOR
    __interrupt void Timer_A1(void)
    {
        static unsigned char hp, hr;                    //header pulse received, header received
        static unsigned char br;                        // bits received
        static unsigned char pulse=FALSE;               // pulse in progress
        static volatile unsigned char ready = FALSE;    // data ready
        static unsigned int pw=0, bw=0;                 // pulse width, bit width
        unsigned int i = TAIV;                          // Read TAIV to clear CCIFG

        // Is this the beginning or the end of the pulse?
        if (!pulse)
        // start of the pulse
        {
            bw=TA1CCR1;
            // reset Timer
            TA1CTL |= TACLR;
            pulse=TRUE;
            // Has the header pulse just been received?
            if (hp)
            {
                // Is the header duration in range?
                if (bw>HPL_MIN && bw<HPL_MAX)
                {
                    hr=TRUE;
                    br=0;
                    data=0;
                    ready=FALSE;
                }
                // is it a repeat code?
                else if (bw>RPT_MIN && bw<RPT_MAX)
                {
                    data=IR_REPEAT;
                    hr=FALSE;
                    ready=TRUE;
                }
            }
            // Was there a bit pulse before, and also has the header been received?
            if(hr && pw>BP_MIN && pw<BP_MAX)
            {
                if (bw>ONE_MIN && bw<ONE_MAX)
                {
                    data<<=1;
                    data++;
                    br++;
                }
                else if (bw>ZERO_MIN && bw<ZERO_MAX)
                {
                    data<<=1;
                    br++;
                }
                if (br==MAX_DATA_BITS)
                {
                    hr=FALSE;
                    ready=TRUE;
                }
            }
            hp=FALSE;
        }
        else
        // end of the pulse
        {
            pw=TA1CCR1;
            pulse=FALSE;
            // Is this a header pulse?
            if (pw>HP_MIN && pw<HP_MAX)
            {
                // set Header Pulse Received flag
                hp=TRUE;
                // Reset timer
                TA1CTL |= TACLR;
            }
            else
            {
                hp=FALSE;
            }
        }
        if (ready)
        {
            ready = FALSE;
            _low_power_mode_off_on_exit();  // Return from LPM
        }
    }

    In this code the probelm is  

    if (pw>HP_MIN && pw<HP_MAX)       this condition is not evaluating and 'hp' is always 'FALSE' .

    Am I need to change anything else in this code. Please suggest me.

    And I am doing work on DRV8313EVM to drive the motor using IR remote, Timers are already used in DRV8313 Firmware so Thats why iam trying to use UART to receive ir data. Is this possible to receive IR data using UART with NEC protocol? Please help me....

  • I think there are 4 problems with the code you posted Oct 9.

    (1) You are using TAIV instead of TA1IV. (TAIV is an alias for TA0IV.)

    (2) You are using #include <msp430g2231.h> instead of g2553.

    (3) There is a mess in the line for (;;)

    (4) The logic in the original code is not on solid ground. It is not reliable.

    UART is not suitable to decode NEC IR remote code. (It maybe possible, but veru difficult.) g2553 has two Timers each with three Capture/Compare channels. Depends on how the motor control program is using them, you may be able to use one of the six CC channels to do the IR decoding.

  • Hi old_cow_yellow, I wrote that code from scratch some time ago. I found this forum thread by accident :) What makes you think that my code is not on solid ground and not reliable? I commented it extensively so it should be pretty easy to understand. What changes would you suggest?
  • Could you please tell the way to get the ir data.
    i am using msp430f5438 and tsop38438 ir receiver
    and how to set the baud rate i am very new to embedded please help me

**Attention** This is a public forum