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.

msp430g2553 comparator

Other Parts Discussed in Thread: MSP430G2553

hi,

//******************************************************************************
// MSP430G2x13/G2x53 Demo - Comp_A, Output Reference Voltages on P1.1
//
// Description: Output Comparator_A reference levels on P1.1. Program will
// cycle through the on-chip comparator_A reference voltages with output on
// P1.1. Normal mode is LPM0, TA0_ISR will interrupt LPM0.
// ACLK = n/a, MCLK = SMCLK = default DCO
//
// MSP430G2x13/G2x53
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
// | P1.1/CA1|--> Vref
// | |
//
// D. Dang
// Texas Instruments Inc.
// December 2010
// Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
//******************************************************************************

#include <msp430g2553.h>

//void delay(void); // Software delay

void main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
CACTL2 = P2CA4; // CA1/P1.1 = +comp
CCTL0 = CCIE; // CCR0 interrupt enabled
TACTL = TASSEL_2 + ID_3 + MC_2; // SMCLK/8, cont-mode
_EINT(); // enable interrupts

while (1) // Loop
{
CACTL1 = 0x00; // No reference voltage
_BIS_SR(LPM0_bits); // Enter LPM0
CACTL1 = CAREF0 + CAON; // 0.25*Vcc, Comp. on
_BIS_SR(LPM0_bits); // Enter LPM0
CACTL1 = CAREF1 + CAON; // 0.5*Vcc, Comp. on
_BIS_SR(LPM0_bits); // Enter LPM0
CACTL1 = CAREF1 + CAREF0 + CAON; // 0.55V, Comp. on
_BIS_SR(LPM0_bits); // Enter LPM0
}
}

// Timer A0 interrupt service routine
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A (void)
{
_BIC_SR_IRQ(LPM0_bits); // Clear LPM0 bits from 0(SR)
}

this is the example code from ti for comparator. it says on p1.1 we get the reference voltages: no ref, 0.25*vcc, 0.5*vcc, 0.55v.

that is it should have been: 0v, 0.25*3.6=0.9v, 0.5*3.6=1.8v, 0.55v.

but i get 3.6v, 3.24v,3.36v, 1v respectively on p1.1. so please help me out to solve this ambiguity .

  • GURU MOORTHY said:

    this is the example code from ti for comparator. it says on p1.1 we get the reference voltages: no ref, 0.25*vcc, 0.5*vcc, 0.55v.

    that is it should have been: 0v, 0.25*3.6=0.9v, 0.5*3.6=1.8v, 0.55v.

    but i get 3.6v, 3.24v,3.36v, 1v respectively on p1.1. so please help me out to solve this ambiguity .

    Did you read comparator documentation and study what P2CA4 bit means? If not - then do it.

  • hi,

    i've read it, my friend.

    i know it helps input and not output.

    but question depends on code.

    they have mentioned it and i am not able to get specified output.

    what is the output of this code

  • what does this code do?

  • GURU MOORTHY said:

    they have mentioned it and i am not able to get specified output.

    what is the output of this code

    Particular code does not configure/route comparator output to any pin. So you set some voltage you want to compare on P1.1(CA1) pin, step through code and see comparator output in CAOUT bit of CACTL2 register.

    BTW instead of asking in forum you could just read other source code examples of comparator where you see how to check for comparator output <grin>:

    #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
      }
    }
    

  • thank you my friend

  • GURU MOORTHY said:

    What does that code do?. i don't want about any other alternative code.

    i want to know about the first code that i have discussed.

    Actually I already explained:

    Ilmars said:
    Particular code does not configure/route comparator output to any pin. So you set some voltage you want to compare on P1.1(CA1) pin, step through code and see comparator output in CAOUT bit of CACTL2 register.

    GURU MOORTHY said:
    i want the brief description and analysis. 

    Good! Analyze yourself :)

    If you have any question which is not so broad as "I want you to analyze and explain code for me" - feel free to ask.

**Attention** This is a public forum