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.

Comparator in msp430g2553

Other Parts Discussed in Thread: MSP430G2553

I tried using the comparator in g2553 to compare two voltages one connected to the -V (i.e. Vref @ 0.5Vcc internally connected) and the +V gets the signal externally from pin P1.1. Heres the code ( its basically from mspsci blog where he gives us really nice tutorials) :

/*
* comparator.cpp
*
* Created on: Jun 25, 2013
* Author: Niranjan
*/

#include<msp430g2553.h>
#include "pins.h"

char comp = 0;

void main (void)
{
WDTCTL = WDTPW + WDTHOLD;
P1OUT = 0;
P1SEL |= BIT1;                          <---- Tried this, but no change in behavior
P1SEL2 |= BIT1;
P1DIR |= (RED);

CACTL1 = CAREF_1 + CARSEL + CAIE;
CACTL2 = P2CA4 + CAF;
CAPD = BUFFER;                                      <---------- After this part the CAOUT goes high even without any signal given to P1.1, I checked for the wiring and it seems right

TACCR0 = 62500 - 1;
TACCTL0 = CCIE;
TACTL = TASSEL_2 + ID_3 + MC_1 + TACLR;

CACTL1 |= CAON;                                     <------- Sets the interrupt flag and goes to the interrupt which should not be possible because not signal at P1.1 
_BIS_SR(LPM0_bits + GIE);

}

#pragma vector = TIMER0_A0_VECTOR
__interrupt void TIMER_A0(void)
{
P1OUT ^= comp;
}

#pragma vector = COMPARATORA_VECTOR
__interrupt void CM (void)
{
if((CACTL2&CAOUT) == 0x01)
{
CACTL1 |= CAIES;
comp = RED;

}
else
{
CACTL1 &= ~CAIES;
comp = 0;
P1OUT=0;
}
}

Can anyone please explain why this is happening ?? is there a way to fix it ?

  • Niranjan Manoharan said:
    because not signal at P1.1 

    What you mean saying "not signal at P1.1? Is it connected to ground?

  • I'm sorry that was a typo. What I'm trying to say is there is no signal at P1.1, no its not connected to the ground, it's open. The interrupt flag is supposed to set only when the voltage at P1.1 is greater than Vref-. But here it sets even when there is no input at P1.1.

  • Niranjan Manoharan said:
    it's open.

    Then please connect it to ground, check results and report back.

  • Connected it to the ground and it works. I'm yet to test it with a potentiometer..... Can you explain why this is happening ??, so the voltage on the pin is "high" without any connection ? I checked the   other pins using a multimeter they were all "low".

  • Niranjan Manoharan said:
    Connected it to the ground and it works. I'm yet to test it with a potentiometer..... Can you explain why this is happening ??, so the voltage on the pin is "high" without any connection ?

    Not necessarily. Consider it's just undefined, depends on pin input impedance, isolation quality, surrounding EMI or DC/static potential level. For example on high impedance input pin especially if it is connected to PCB trace, you easily can receive nearby switching PSU noise or other EMI, or just your VCC can leak into pin/trace through conducting dirt on PCB. Check datasheet for input pin leakage current of your chip and you will see that not much input current is needed for pin: 50 nA.

    You shall _never_ ever leave input pins floating. It's one of the basic electronics rules. Well of course there are exceptions like touch sense.

**Attention** This is a public forum