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.

Problem with interrupt response to input from magnetic sensor



Hi,

I have interfaced a G2553 with a magnetic sensor on the P2.0 port. Whenever I single step and bring a magnet in close proximity to the magnetic sensor the port 2 ISR executes perfectly.

But when I run the program and bring the magnet close to the magnetic sensor the program does enter the ISR at all.

void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

P1DIR |= BIT6;
P1OUT &= ~BIT6;
LCD_init();
P2DIR=0xFE;
P2OUT=0x00;

P2REN|=BIT0;

LCD_clearScreen();
for(i=0;i<2;i++)
{
LCD_clearScreen();
__delay_cycles(1000000);
LCD_setCursorPosition(0,5);
LCD_printStr("SASTRA");
LCD_setCursorPosition(1,2);
LCD_printStr("Racing");
LCD_setCursorPosition(1,9);
LCD_printStr("Team");
__delay_cycles(1000000);
}

LCD_clearScreen();
LCD_setCursorPosition(0,0);
LCD_printStr("Initializing");
for(i=0;i<20;i++)
{
LCD_printStr(".");
__delay_cycles(100000);
if(i==3)
LCD_setCursorPosition(1,0);
}
LCD_clearScreen();

//******************ADC setup***************
ADC10CTL0 |= ADC10ON; //switching on ADC
ADC10CTL1 |= INCH_7|ADC10DIV0|ADC10SSEL_1|CONSEQ_0; //assigning P1.0 to ADC
ADC10AE0 |= BIT7 ; //enabling analog channel A0
ADC10CTL0 |= ENC|ADC10SC; //enabling conversion and starting

//******************Timer setup*************
TA1CCTL0 = CCIE;
TA1CTL = TASSEL_2|ID_3|MC_1; //selecting a presclar of 8 to get 125kHz clock
TA1CCR0 = 0xFFFF; //loading a count value of 62500 which when run two time will produce a delay of 1s

P2IE|=BIT0; //enabling port pin interrupt for resetting the odometer count
P2IES=1;
P2IFG &= ~BIT0;

__enable_interrupt();

while(1)
{
LCD_clearScreen();
ADC10CTL0 |= ENC|ADC10SC; //enabling conversion and starting
temperature=(ADC10MEM*35)/100;
__no_operation();
LCD_setCursorPosition(0,0); //forcing cursor to the 1,1
LCD_printStr("Temp:");
convert_temperature(temperature);
temperature=0;
LCD_setCursorPosition(0,10);
convert_distance(distance);
LCD_setCursorPosition(1,0);
LCD_printStr("Speed:");
convert_speed(speed);
__delay_cycles(505000);
}
}

#pragma vector=PORT2_VECTOR
__interrupt void reed_switch(void)
{
LCD_clearScreen();
LCD_printStr("success");
__delay_cycles(100000);
P2IFG &= ~BIT0;
}

Kindly help me 

Thank You

  • > TA1CCTL0 = CCIE;

    This enables the TIMER1_A0_VECTOR interrupt, but I don't see an ISR anywhere.

    As it is, your program will crash about one-half second after it starts. My guess is that it takes you slightly longer than that to pick up your magnet and move it towards the sensor.

    If you run the program in single-step, you slow it down considerably, since the timer is stopped while your program is stopped in the debugger. This gives you enough (human) time to pick up the magnet and move it near the sensor.

  • thanks a lot Bruce. I totally forgot about the ISR ! it works perfectly now.

**Attention** This is a public forum