MSP430G2253: eCOMP usage with multiple sensors

Part Number: MSP430G2253

Tool/software:

Hi!

I want to use two comparators for two different sensors. How can I use the comparator channels?

I searched on resource explorer, and found nothing about.

Maybe I don't paid enough attention for the snippets...

  • Hello Italo,

    You can start with a simple comparator example from the TI Developer Zone. 

    I'll copy here for convenience.

    //******************************************************************************
    //   MSP430G2x13/G2x53 Demo - Comp_A, Detect Threshold, Set P1.0 if P1.1 > 0.25*Vcc
    //
    //   Description: Use Comparator_A to detect a voltage threshold.
    //   Using an external potentiometer, an unknown voltage is applied to P1.1.
    //   Comparator_A compares the unknown voltage to an internal reference
    //   voltage, in this example 0.25*VCC. If the unknown voltage is higher
    //   than 0.25*VCC, P1.0 is set, if not, P1.0 is reset.
    //   ACLK = n/a, MCLK = SMCLK = default DCO
    //
    //          MSP430G2x13/G2x53
    //       -----------------
    //   /|\ |            XIN|-
    //    |  |               |
    //    ---|RST        XOUT|-
    //    |  |               |
    //    R<-|P1.1/CA1   P1.0|-->LED
    //    |  |               |
    //    ---|VSS
    //
    //  D. Dang
    //  Texas Instruments Inc.
    //  December 2010
    //   Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
    //******************************************************************************
    
    #include <msp430.h>
    
    int main (void)
    {
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      P1DIR |= 0x01;                            // P1.0 output
      CACTL1 = CARSEL + CAREF0 + CAON;          // 0.25 Vcc = -comp, on
      CACTL2 = P2CA4;                           // P1.1/CA1 = +comp
    
      while (1)                                 // Test comparator_A output
      {
        if ((CAOUT & CACTL2))
          P1OUT |= 0x01;                        // if CAOUT set, set P1.0
        else P1OUT &= ~0x01;                    // else reset
      }
    }
    
    

    Since you have two sensors, you will need to switch back and forth between the two sensor channels.

  • Hi!

    Can I use any port pins as comparator? If no, where can I find this information?

  • Hi Italo,

    No.  You will have to look at the datasheet, pg6.  This table shows the functionality of each pin.  The comparator has 8 input channels [CA0...CA7], and a CA_OUT pin.  I don't know which package you are using so these show up on different pin #s.

  • Thanks for the reference, the datasheet I had consulting does not has the Port/comp mapping.

    As I'm searching and conding, I verified that I must enable one channel at a time. Is that right?

  • Yes, you can only select one comparator channel at a time using the P2CA bits.

    I'm curious about your application. Can you share what you are attempting to do with the comparator?

  • Hi!

    Well, I'm trying to use independently two channels for two sensors. My idea was toggling P2CA0 to use each channel at a time, but no results.

    Using the setup of a code snippet on developer zone, I did something like:

    while(1)
    {
        __delay(500000);
        CACTL2 ^= P2CA0;
    }
    
    #pragma vector = COMPARATORA_VECTOR
    __interrupt void COMPA_ISR()
    {
      if(!(CACTL2 & CAOUT))                      // Test comparator_A output
      {
        if(CACTL2 & P2CA0)
        {
            P1OUT |= BIT0;
        }
        else
        {
            P1OUT |= BIT6;
        }
      }
      else
      {
        P1OUT &= ~(BIT0 | BIT6);                         
      }
    }
    

  • Hi Italo,

    I think the issue maybe in the while(1).  I'm not sure if you are attempting to toggle between "no connection" (P2CA0 = 0) and "CA0" (P2CA0 = 1), OR are you attempting to toggle between "CA0" and "CA1" (P2CA0 = 2)?  

  • Hello, Dennis!

    According to the datasheet, P2CA bits is just 1 bit long, so I don't know if it would store more than 1. Also, the datasheet states that it is used together with P2CA4, and in my code it is always set. Here is the description:

  • Yes, you are correct.  I was thinking something different - sorry.

    If you set a breakpoint on line #4 ->  CACTL2 ^= P2CA0 and then add CACTL2 to the Expressions window, run the debugger and each time it stops on line #4, what are the values you see in CACTL2?

**Attention** This is a public forum