BL4S200 setExtInterrupt question

Hello,

I’m trying to detect rising edge with one handler and falling edge with another handler. Is it possible with the BL4S200 API?

With the code next, only the photocell_up_isr() is called on falling edge!

// Rising handler
root void photocell_up_isr()
{
photocell_up_count++;

// Turn off all interrupt flags serviced by this handler
RSB_CLEAR_ALL_IRQ(photocell_up_handle);
}

// Falling handler
root void photocell_down_isr()
{
photocell_down_count++;

// Turn off all interrupt flags serviced by this handler
RSB_CLEAR_ALL_IRQ(photocell_down_handle);
}

void photocell_init()
{
int result;

photocell_up_count = 0;
photocell_down_count = 0;

photocell_up_handle = addISR(PHOTOCELL_1, BL_INPUT_BLOCK, 0, photocell_up_isr);
photocell_down_handle = addISR(PHOTOCELL_1, BL_INPUT_BLOCK, 0, photocell_down_isr);

result = setExtInterrupt(PHOTOCELL_1, BL_IRQ_RISE, photocell_up_handle);
result = setExtInterrupt(PHOTOCELL_1, BL_IRQ_FALL, photocell_down_handle);

result = enableISR(photocell_up_handle, 1);
result = enableISR(photocell_down_handle, 1);
}

Thank you for your comment.

Jean-Yves

You are trying to setup 2 different external interrupts on a single pin. This is not possible with the setExtInterrupt function. To make this work properly you need to use something that sets up individual rising and falling edge events on a single pin. The external ISR allows detecting of both edges, but doesn’t allow distinguishing between rise or fall as they are considered a unified event.

It is possible to setup what you want by using a different function. If you setup a capture function on the pin, you can directly control the edges for both BEGIN and END events. This allows you to setup separate ISR’s for rising and falling edges. Granted, you are telling the RIO to capture BEGIN and END ‘timestamps’ that you may not need, but it does give you the individual interrupts you’re after.


void photocell_init()
{
int result;

photocell_up_count = 0;
photocell_down_count = 0;

photocell_up_handle = addISR(PHOTOCELL_1, BL_INPUT_BLOCK, BL_IER_IIB,
                           photocell_up_isr);   // Add ISR for BEGIN event
photocell_down_handle = addISR(PHOTOCELL_1, BL_INPUT_BLOCK, BL_IER_DQE, 
                           photocell_down_isr);   // Add ISR for END event

// Setup BEGIN event on rising edge, END event on falling edge
result = setCapture(PHOTOCELL_1, BL_CNT_BEGIN_END, BL_EVENT_RISE,
                           BL_SAME_CHANNEL | BL_EVENT_FALL);    

result = enableISR(photocell_up_handle, 1);
result = enableISR(photocell_down_handle, 1);
}


It is possible to get the RIO to do what you want without setting up a capture function, but this would require low level setup of the RIO to enable the edge detection. This is much more complicated to do so I’m showing you the easy way to get what you’re after.

Hi Bill,

Thank you for your answer. I have studied the RIO chip and I know it’s capabilities. Where it’s more ambiguous is all the libraries to drive the card. For example, I need to use match register with quadrature decoder and the API does not have this capability, but programming directly the RIO it works well.

It’s a good idea to use capture to do that! Thank you.

Jean-Yves