Kaiki Kweb

Interrupt Handling (pushbuttons)

Discussion created by Kaiki Kweb on Feb 21, 2006
Latest reply on Feb 26, 2006 by Barry Gordon
I have a circuit built around the HCS08 and I need to handle 3 specific events.
The first 2 are push events from 2 pushbuttons connected to Port A (pins 6 and 7)
and the third is an interrupt from an external chip that signals the micro that its done its work.

Here's how I initalize the registers :

// Enable interrupt on KBI (portA)
KBI1SC_KBI1E = ENABLED;

// enable pullups
PTAPE_PTAPE4 = ENABLED;
PTAPE_PTAPE6 = ENABLED;
PTAPE_PTAPE7 = ENABLED;

// Direction in (0)
PTAPE_PTAPE4 = IN;
PTAPE_PTAPE6 = IN;
PTAPE_PTAPE7 = IN;

// enable int on 3 pins
KBI1PE_KBI1PE4=ENABLED;
KBI1PE_KBI1PE6=ENABLED;
KBI1PE_KBI1PE7=ENABLED;

The vector table is set like so :
kbd_isr, /* vector 22: KBI */

// here is the interrupt handler
interrupt void kbd_isr (void)
{
// if its really a KBI event
if (KBI1SC_KBF)
{
// don't allow more kbi interrupts
KBI1SC_KBI1E = DISABLED;

// clear interrupt flag
KBI1SC_KBACK = 1;

// make sure everyone knows theres a KBI event
SETBIT(KBI_EventFlag, KBI_EVENT_PENDING);
}
}

basically in the ISR I'm only setting a flag asking the app to take it from there.
In the app I'm expecting that the specific pin that fired the event should have a 1 on its data line and so if I check PTAD_PTAD{4,6,7} i should know if the interrupt happened. But I don't get anything on the data line.
Question 1 : Should I get data on this pin everytime an interrupt is fired?

as a temporary workaround I use this code (right now I pretty much know when which event is going to fire)


void HandleKBIEvent(void)
{
// make sure it was a valid call
if(GETBIT(KBI_EventFlag, KBI_EVENT_PENDING))
{
// chip shouldn't have a debounce period
if (CHIP_INT_INT == ENABLED)
SETBIT(KBI_EventFlag,KBI_EVENT_CHIP);
else
{
// debounce for switches
delay_ms(500);
if(BUTTON1_INT == ENABLED)
SETBIT(KBI_EventFlag,KBI_EVENT_BTN1);
else if(BUTTON2_INT == ENABLED)
SETBIT(KBI_EventFlag,KBI_EVENT_BTN2);
}

// clear event
CLRBIT(KBI_EventFlag, KBI_EVENT_PENDING);
// we took care of this
SETBIT(KBI_EventFlag,KBI_EVENT_HANDLED);

// reenable interrupts
KBI1SC_KBI1E = ENABLED;
}
}

Question 2: The interrupts on the pushbutton lines don't always fire. Although I can see with an analyzer that the line does go low. Any idea why this might happen?

Thanks,
K

Outcomes