Jump to content
Matjaz

binding isr to comparator event - isr never executes

Recommended Posts

Dear all,

 

I'm using CCS on Win7 and Launchpad 430g2 with a 2452 chip.

I cannot get the ISR to execute when I externally drive comparator input voltage up and down. Minimal code is here. I think it should toggle LED whenever I go up. (Other code examples are reading P1.1 comparator correctly in same setup and also LED is connected correctly as tested with other code.)

 

Any idea? Any obvious fault in code? Thanks!

Matjaz

#include <msp430.h>

int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timeractivate comp

    P1OUT = 0;
    P1DIR = BIT0;

    CACTL1 = CAREF1 + CARSEL + CAIE; // 0.5 Vcc ref on - pin, enable interrupts on rising edge.
    CACTL2 = P2CA4;      // Input CA1 on + pin
    CACTL1 = CAON;		// activate comparator


    for (; {
    }
}

#pragma vector=COMPARATORA_VECTOR
__interrupt void my_isr (void) {
	P1OUT ^= BIT0;
}
// EOF

Share this post


Link to post
Share on other sites

Dear all,

 

I'm using CCS on Win7 and Launchpad 430g2 with a 2452 chip.

I cannot get the ISR to execute when I externally drive comparator input voltage up and down. Minimal code is here. I think it should toggle LED whenever I go up. (Other code examples are reading P1.1 comparator correctly in same setup and also LED is connected correctly as tested with other code.)

 

Any idea? Any obvious fault in code? Thanks!

 

You haven't set the GIE bit anywhere, so all (maskable) interrupts are disabled. That includes your comparator interrupt.

 

Add a "__bis_SR_register(GIE);" before the infinite loop, that should make the ISR work.

Share this post


Link to post
Share on other sites

Ha! Got it.

 

line "CACTL1 = CAON;" should have been "CACTL1 |= CAON;" of course. :blush: My bad.

Thanks again, @@tripwire, because that extra piece of info was crucial, too!

 

Adding here full working code for later reference. This now does work:

#include <msp430.h>

int main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog
    P1DIR = BIT0;	// config P1.0 as output to drive LED

    CACTL1 = CAREF1 + CARSEL + CAIE; // 0.5 Vcc ref on - pin, enable interrupts on rising edge.
//    CACTL1 = CAREF_2 + CARSEL + CAIE; // equivalent - CAREF1 and CAREF_2 are both 0x20 in the .h file
    CACTL2 = P2CA4 + CAF;      // Input CA1 on + pin and add some filtering
    CACTL1 |= CAON;		// activate comparator

    __bis_SR_register(GIE);	// general enable of maskable interrupts
//    _BIS_SR(LPM0_bits + GIE); // alternative to above
//    __enable_interrupt(); // yet another alternative

    for (; { }	// await eternity here
}

#pragma vector=COMPARATORA_VECTOR
__interrupt void my_isr (void) {
	P1OUT ^= BIT0;  // flip red LED state
}
// EOF

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×