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.

MSPM0L1105: Input capture button should be pressed for 10 sec to go to button_handle state.

Part Number: MSPM0L1105

Tool/software:

Hi Forum,

Please support me in this applications.

void GROUP1_IRQHandler(void)
{
switch (DL_Interrupt_getPendingGroup(DL_INTERRUPT_GROUP_1)) {
case GPIO_GRP_0_INT_IRQN:
switch (DL_GPIO_getPendingInterrupt(GPIO_GRP_0_PORT)) {


case GPIO_GRP_0_PIN_HALL_SENSE_IIDX:

----------

------

}

break;

case GPIO_GRP_0_PIN_KEY_IIDX:
/* If SW is high, turn the LED off */
if (DL_GPIO_readPins(
GPIO_GRP_0_PORT, GPIO_GRP_0_PIN_KEY_PIN )) {

button_handler();
DL_GPIO_setPins(GPIO_LEDS_PORT, GPIO_LEDS_GREEN_LED_PIN);
}//}
/* Otherwise, turn the LED on */
else {
DL_GPIO_clearPins(GPIO_LEDS_PORT, GPIO_LEDS_GREEN_LED_PIN);
}
break;
}

In the highlighted code. If this button input pressed for 10sec then only I want to run button_handler() or else it will directly go to else state. Please help me with how do I process this.

  • You should set a flag in the ISR, and in the main loop, use this flag to set a timer. Keep monitoring the switch and see if it is released before the timer is expired.

  • Hello Harshita, 

    So you mean that you want to use a button to control the operating of button_handler (), if the button is pressed for 10sec, MCU will run the button_handler(), right? 

    As mentioned by Keith, setting flags is good method. You can set two kinds of flags. For example, you can set a timer start flag and a timer end flag. When you detected that the button is pressed, you can set the timer start flag and start the 10sec timer to count. And then you can set the timer end flag when the button is released. And in the timer counting interrupt, you can detect the two flags, if the start flag is set but the end flag is not set which means that the button has been pressed for 10sec, then you can do the button_handler() in the timer interrupt. 

    Best Regards,

    Janz Bai