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.

how to invert the incoming signal periods..? (i.e) ON & OFF period...

Other Parts Discussed in Thread: MSP430G2211, MSP430F2121, MSP430F2132

hi,

                       i'm using msp430g2211 micro controller in my project... in my application i need to get one ( square/ pwm)  signal from PORT PIN P1.0 .

after that i need to invert that signal  time periods  and give output to PORT PIN P1.3/4....is it possible to do....? i need your feed backs...........

thanks in advance.....

  • Parthiban,

    There can be several ways to do this.

    One simple way that I can think of is, using the interrupt port for sensing the input signal edge and then output the required signal on the ouput port. Here are the steps:

    • Configure the P1.0 as an interrupt port. (Assuming the square/pwm is passed through this port)
    • Initially configure the P1.0 to generate interrupt when there is High to Low transition and note down this information in some global variable.
    • In the P1.0 interrupt handler:
      • Check the global variable (to decide whether to output 1 or 0) and then ouput the signal on P1.3.
      • Check the current edge trigger setting (for e.g. high to low) and then configure the P1.0 the opposite (low to high trigger). Use XOR to do this.
      • Also update the global variable information to check the configuration status in the next interrupt.

    Regards,

    Nag

  • dear sir,

    thanks for your valuable reply.. now i got something.....

  • Parthiban,

    Thanks for your acknowledgement.

    Regards,

    Nag

    (If your question is answered, please click the  Verify Answer  on this post)

  • dear sir,

     with respect to your information i just try out the below coding .. but i'm not get the inverted output.. instead i got the output always HIGH only.... i think some where in interrupt i made a mistake.... can you able to tel what's wrong in this......

    my coding is

    #include  <msp430g2211.h>
    unsigned int count=0;
    void main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
      P1DIR |= 0x01;                            // Set P1.0 to output direction
      P1IE |= 0x08;                             // P1.4 interrupt enabled
      P1IES = 0x08;                            // P1.4 Hi/lo edge
      P1IFG &= ~0x08;                           // P1.4 IFG cleared
      _BIS_SR(LPM4_bits + GIE);                 // Enter LPM4 w/interrupt
    }

    // Port 1 interrupt service routine
    #pragma vector=PORT1_VECTOR
    __interrupt void Port_1(void)
    {
        count=1;                                    //global variable
        if (count==1)
        {
            P1OUT |= 0x01;
            if(P1IES== 0x10)
            {
                P1OUT |=0;
                P1IES |=0;
                count=0;
                P1IFG &=~0x10;
            }
               
        } 
    }                

  • Parthiban,

    Your comments show P1.4 but you are using 0x08 to set/reset the port which will actually work on P1.3. So I hope you are physically checking your signal at P1.3. 

    I have modified your code a little bit and also removed the usage of the global variable to make the program more straight forward. I have not tested or compiled this code, so please check this out.

     

    #include  <msp430g2211.h>

    void main(void)

    {

      WDTCTL = WDTPW + WDTHOLD;  // Stop watchdog timer

      P1DIR |= 0x01;            // Set P1.0 to output direction

      P1IE |= 0x08;               // P1.3 interrupt enabled

      P1IES |= 0x08;             // P1.3 interrupt comes with there is a Hi/lo edge

      P1IFG &= ~0x08;         // P1.3 IFG cleared

      _BIS_SR(LPM4_bits + GIE);  // Enter LPM4 w/interrupt

    }

     

    // Port 1 interrupt service routine

    #pragma vector=PORT1_VECTOR

    __interrupt void Port_1(void)

    {

        if (P1IES & 0x08 == 0x08) 

        {

           //Input signal changed from high to low

           //So we have to make the output signal high

            P1OUT |= 0x01;

        }

        else 

        {

           //Input signal changed from low to high

           //So we have to make the output signal low

            P1OUT &= ~0x01;

        }

        P1IES ^=  0x08; // Inverting the edge trigger setting

        P1IFG &= ~0x10; // Clearing the interrupt flag

    }

    Few more comments:

    - I see  P1SEL register is not updated in the program which is used to select functionality of the pin. You can look into this aspect as well after trying the above code.

    - Have you checked whether the control comes to the ISR. If not, please do so. Also do a step by step debugging to root cause the issue.

     

    Please let me know the results.

     

    Regards,

    Nag

    (If your question is answered, please click the  Verify Answer  on this post)

  • One correction in the above program:

    Change the following line:

    P1IFG &= ~0x10; // Clearing the interrupt flag

    to

    P1IFG &= ~0x08; // Clearing the interrupt flag

    Regards,

    Nag

  • sir,

    we have a doubt in concept of the below application... so we need your sug for this...

    In our project we need to emitt pwm signal using IR EMITTER and receive the same signal using IR DETECTOR...... for this we wrote code for two separate controller.... but my actual application need these two codes on a single controller.... (i.e) we need to emitt and receive the signal using single micro controller.....with MSP430F2121 is it possible to do this... how can i do this... can you give some clue in this.......

    thanks in advance....

  • The MSP430F2121 has a TimerA3, that measn it can be used for one PWM output and at the same time for capturing incoming events. However, the code for analyzing the incoming signal will be a bit more complex than if you had a dedicated timer for this task, as the timer just counts to the PWM frequency (controlled by CCR0), so the ISR that checks the incoming signal event will run on a tight schedule, especially if you have duty cycles near 0% or 100%.
    I'd go for a bigger MSP with at least two timers, e.g. the MSP430F2132. However, it should be doable with the 2121.

**Attention** This is a public forum