Hello,
I have a strange issue of false interrupt detection.
I have configured p2.0 in interrupt (rising edge)mode and enabled internal pull up. Please see below code. If I connect 1 meter long wire (floating end)at the pin(or if I put my finger on that pin), I am getting interrupt continuously (i.e continuous increment of Dip_Counter as per code). Requirement is to connect only push button(without bypass capacitor) at 2 meter distance. Is it because of noise? Yes, it is noisy environment and 3 phase motor running at distance 2 meter. If it is because of noise then what should I do to overcome it? Well I don't own CRO, hence unable to debug this issue thus need help. I have tried this in two different board, same issue.
code:
#define CHANNEL_A (P3IN & BIT4)>>4 // P3.4
#define CHANNEL_B (P3IN & BIT5)>>5 // P3.5
#define CHA BIT0
#define CHB BIT1
#define TIMER_COUNT 16000 //1.1 ms
#define BREAKDOWN_TIMEOUT 10000
//------------------------------------------------------------------------------
// MCU Init
//------------------------------------------------------------------------------
void Mcu_Init()
{
WDTCTL = WDTPW + WDTHOLD; // WATCHDOG OFF
if (CALBC1_16MHZ==0xFF) // If calibration constant erased
{
while(1); // do not load, trap CPU!!
}
DCOCTL = 0; // Select lowest DCOx and MODx settings
BCSCTL1 = CALBC1_16MHZ; // Set DCO to 16MHz
DCOCTL = CALDCO_16MHZ;
//pin config-----------------------------------------------------
P2SEL=0;
P2DIR=0;
P2OUT=0;
P2IES=0;
P2IE= CHA;
//Timer initialize--------------------------------------------------------------
TACCTL0 = CCIE;
TACCR0 = TIMER_COUNT;
TACTL = TASSEL_2 + MC_1; // SMCLK=1.2mhz, upmode*/
}
//------------------------------------------------------------------------------
// Main Function
//------------------------------------------------------------------------------
void main(void)
{
Mcu_Init();
__bis_SR_register(GIE); // interrupts enabled
while (1)
{
}
}
// Port 2 interrupt service routine
#pragma vector=PORT2_VECTOR
__interrupt void Port_2(void)
{
if(P2IFG & CHA)// If interrupt is because of chA
{
P2IFG&=~CHA; // CLEAR INTERRUPT
Dip_Counter++;
}
}
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
if(TimeOut>0)TimeOut--;
if(DipTimeOut>0)DipTimeOut--;
}