In my previous blog post #5 GPIO read and write , I have faced an issue where my servo is not operating as I want it to. I revised my coding and found out that the problem is probably due to the compare value of the tcpwm1 keep toggling as I'm keep polling the status of the button GPIO input pin.
While I'm finding the solution for this issue, I found this example code:
A GPIO Interrupt might be the solution for my problem.
I created the GPIO_Interrupt Starter application and read through the Readme.md file as well as the code in the main.c to have a brief idea of how will it works.
I then summarized up some of the function that are useful for implementing GPIO interrupt.
/* Configure GPIO interrupt */ cyhal_gpio_register_callback(CYBSP_USER_BTN, gpio_interrupt_handler, NULL); cyhal_gpio_enable_event(CYBSP_USER_BTN, CYHAL_GPIO_IRQ_FALL, GPIO_INTERRUPT_PRIORITY, true);
These two function are both new to me, so I will need to find out how will the functions work.
I found out that in the Quick Panel under Documentation, there is a documentation for Hardware Abstraction Layer (HAL), since both the functions start with cyhal, there is a great chance that they are included in that documentation.
Clicking the link brings me to this documentation page of Cypress Hardware Abstraction Layer.
The interface is similar to the PDL documentation which I have deal with in the previous blog post.
Searching the function in the search box bring me to this page.
To summarize things, for cyhal_gpio_register_callback() function:
the 1st argument will be the pin used for the interrupt,
the second argument will be the event_handler,
the third argument can be input NULL.
For cyhal_gpio_enable_event() function:
the first argument will be the pin used for the interrupt,
the second argument will be the GPIO event,
the third argument will be interrupt priority, etc.: 1u, 2u, 3u... and so-on.
the forth argument should be true if you want to enable the interrupt.
For the second argument, the GPIO event can be choose from the below case:
After learning how to utilize the GPIO interrupt, I will try to resolve the problem of the abnormal behavior of the servo in my next blog post