Hello,
I understand that you want to set a specific exit condiion for your hardware interupt ,you can follow the following steps:
1.Configure the GPIO4 as XINT1 and set it to trigger on the falling edge, as you mentioned. This will ensure that the interrupt is triggered when the push switch is pressed.
2.In the interrupt service routine (ISR) for XINT1, you can implement the logic to turn on LED10 (GPIO39) and set a timer to turn it off after a specific duration.
Start a timer for 5 seconds when the push switch is pressed. You can use a timer peripheral available on your microcontroller (e.g., Timer1).
Inside the ISR, set a flag to indicate that the push switch is pressed.
In the main program loop, check the flag status. If the flag is set, check if the timer has expired. If the timer has expired, turn off LED10.
3.To turn off the LED when the push switch is released, you can use another interrupt, such as XINT2, triggered on the rising edge of GPIO4.
Configure GPIO4 as XINT2 and set it to trigger on the rising edge.
In the XINT2 ISR, clear the flag indicating that the push switch is pressed and turn off LED10.
For a general outline,the general implementation may vary depending on the specific hardware
Make sure to refer the documentation and examples provided by TI 28069M launchpad and Embedded Coder Support Pcakge/Simlink to adapt the code :Embedded Coder Support Package for Texas Instruments C2000 Processors - File Exchange - MATLAB Central (mathworks.com)
Hope this helps!
// Global variables
volatile bool switchPressed = false; // Flag to track switch state
// Interrupt Service Routine for XINT1
interrupt void xint1_isr(void)
{
// Clear the interrupt flag
// ...
// Check the state of the switch
if (GPIO4 == 0) // Assuming GPIO4 is the input pin connected to the switch
{
switchPressed = true;
// Turn on the LED
// ...
}
else
{
switchPressed = false;
// Turn off the LED
// ...
}
}
// Main function
int main(void)
{
// Initialize GPIO and other peripherals
// ...
// Configure XINT1 interrupt
// ...
// Enable global interrupts
// ...
while (1)
{
if (switchPressed)
{
// Handle LED behavior based on the switch state
// ...
}
else
{
// Handle LED behavior when the switch is not pressed
// ...
}
}
}