Hi to every one......
I'm trying to capture the incoming frequency from the inbuilt comparator output.If capture input signal is within the given band means, some outputs will be enable.
If not in the band means, some output will come.
Now my problem is, i always give the continuous signal to the comparator input & output also come at right condition.But the routine will get in to else condition often .
But i expected is different. Only when signal absent only it will get in to else condition.
this is my problem.Why it get into Else condition often.
Can anyone help in this..?
Here i attached my coding.
#include <msp430G2152.h>
unsigned int Msec1Reg,ShortReg,Msec5Reg,Msec4Reg;
unsigned int OldCaptureValue,NewCaptureValue,CaptureValue;
unsigned int NewReceiverFreqCount,ReceiverFreqCount;
void PowerOnHardwareInit(void);
void PowerOnRegInit(void);
void main(void)
{
PowerOnHardwareInit();
PowerOnRegInit();
while(1)
{
}
}
void PowerOnHardwareInit()
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
BCSCTL1 = CALBC1_1MHZ; // Set range
DCOCTL = CALDCO_1MHZ; // Set DCO step + modulation
P1SEL=0x0C; // Timer and Comparator Function Selection
P1SEL2 = 0X08;
P1DIR= 0xF8; // P1.1,P1.2 as Input
P1REN =0x06; // Pull Up Enable
P2SEL=0x00;
P2SEL2=0x00;
P2DIR= 0x0F; // P2.0, P2.1,P2.2, P2.3 Pins are Output
P2IE=0x90; //PortChange Interrupt Activation
P2IES=0x90; //Edge Select
P2IFG &= ~0x90;
P2IE|=0x60; //PortChange Interrupt Activation
P2IES|=0x00; //Edge Select
P2IFG &= ~0x60;
TACCR0=250; // Timer interrupt Value
TACCTL0=CCIE; // Capture Compare interrupt Enable
TACTL = TASSEL_2 + MC_2; // SMCLK, contmode, interrupt
TACCTL1=CM_1+CCIS_1+SCS+CAP+CCIE; // Rising Edge Capture,Timer A int.,Capture mode enable
CACTL1=CAEX+CAON;
CACTL2=P2CA1+P2CA0+CAF+CAOUT;
_BIS_SR(GIE); // Global interrupt Enable
}
void PowerOnRegInit()
{
OldCaptureValue=0;
NewCaptureValue=0;
CaptureValue=0;
ReceiverFreqCount=0;
Msec1Reg=2;
Msec4Reg=16;
ShortReg=0;
NewReceiverFreqCount=0;
}
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
TACCR0+=250; // Increment timer value
if(ShortReg==0)
{
if(--Msec1Reg==0)
{
Msec1Reg=2;
if(CaptureValue>=202 && CaptureValue<=285) // Check For Actual pulse
{
P2OUT &=~0x06;
__delay_cycles(20);
P2OUT |= 0x09; // P2.0, P2.1 as Output
P1OUT|=0x70; // P1.4, P1.5, P1.6, as Output
}
else
{
P1OUT = 0x10;
P2OUT &=~0x09;
__delay_cycles(20);
P2OUT=0x06;
}
CaptureValue=0;
}
}
if(ShortReg==1)
{
if(--Msec4Reg==0)
{
ShortReg=0;
P1OUT=0x10;
Msec4Reg=16;
}
}
}
#pragma vector=TIMER0_A1_VECTOR
__interrupt void TA1_ISR(void)
{
switch(TAIV)
{
case 2:
NewCaptureValue=TACCR1; // Capture Value
if(NewCaptureValue < OldCaptureValue)
{
CaptureValue = ((0xFFFF - OldCaptureValue) + NewCaptureValue);
}
else
{
CaptureValue=NewCaptureValue-OldCaptureValue; //Difference calculaions
}
OldCaptureValue=NewCaptureValue;
break;
case 3:break;
case 10:break;
}
}
/*********************************************
* Port Change Interrupt
* *******************************************/
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
{
ShortReg=1;
P1OUT=0x00;
P2OUT=0x00;
P2IFG &= ~0xF0;
Msec4Reg=16;
}