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 ?