- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am probably making a rather silly mistake but this scenario has got me stumped.
I have two input pins which each have an interrupt attached.
I have created logic that has one pin interrupt enabled when the other is disabled and then it swaps upon button press. A green and a red LED to indicate the different button presses. Now this works fine if each button is pressed once. However, if I press one of the buttons twice and then when I press the second button it still shows the first button sequence after this second button, as in it has in memory the 2nd press of the 1st button. Why is this?
Sequence is:
Press Button_1 once. isr_ResetBtn_Enable(); and isr_StartBtn_Disable(); LEDgreen ON then OFF
Now Press Button_2 once. Then isr_StartBtn_Enable(); and isr_ResetBtn_Disable(); LEDred ON then OFF.
Press Button_1 TWICE. isr_ResetBtn_Enable(); and isr_StartBtn_Disable(); LEDgreen ON then OFF
Now Press Button_2 once. isr_StartBtn_Enable(); and isr_ResetBtn_Disable(); LEDred ON then OFF.... then LEDgreen ON then OFF ????
How do I ignore or "clear" that second button_1 press?
Here is code snippet within main()
/* Enable the start pin interrupt */
CyGlobalIntEnable;
isr_StartBtn_Disable();
isr_ResetBtn_Disable();
/* Start the TCPWM Component */
//Timer_Start();
for(;;)
{
if (Started) {
/* Handle the Period of Play Logic */
if (StartButtonIntEnabled) {
StartButtonIntEnabled = false;
/* Turn On the Red LED */
LED_TimeOutReq_Write(LIGHT_ON);
CyDelay(500u);
LED_TimeOutReq_Write(LIGHT_OFF);
isr_StartBtn_Disable();
isr_ResetBtn_Enable();
}
}
else {
if (!StartButtonIntEnabled) {
StartButtonIntEnabled = true;
/* Turn On the Red LED */
LED_TimeOutON_Write(LIGHT_ON);
CyDelay(500u);
LED_TimeOutON_Write(LIGHT_OFF);
isr_ResetBtn_Disable();
isr_StartBtn_Enable();
}
}
}
CY_ISR(isr_StartBtnHandler)
{
/* Clear pending Interrupt */
isr_StartBtn_ClearPending();
/* Clear pin Interrupt */
Pin_Start_ClearInterrupt();
Pin_Reset_Read();
/* Set the Start flag to true */
Started = true;
}
CY_ISR(isr_ResetBtnHandler)
{
/* Clear pending Interrupt */
isr_ResetBtn_ClearPending();
/* Clear pin Interrupt */
Pin_Reset_ClearInterrupt();
Pin_Start_Read();
/* Set the Start flag to false */
Started = false;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I have found the answer in the pin component. I assume this relates to the "input buffer enabled" tickbox.
Out of curiosity, are there any functions that I can use to flush the input buffer in my code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It appears that this behaviour is linked to the Interrupt Enable and Disable functions. If I keep both Interrupts enabled and handle pin logic within the code I do not see this same behaviour.
So I am wondering if it is linked to the initial pin state, or what else would cause this "memory" effect when enabling a pin interrupt again etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think I have found the answer in the pin component. I assume this relates to the "input buffer enabled" tickbox.
Out of curiosity, are there any functions that I can use to flush the input buffer in my code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"Out of curiosity, are there any functions that I can use to flush the input buffer in my code"
The input buffer reflects the actual state of the signal. This is coming from the outer world and as such cannot be "flushed".
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aha, of course. I had tried a pin read() to read the actual pin state, thinking this would be a way to clear the buffer, but this did not work.