Easy Embedded Programming: How to Program Interrupts

Publié par

The third video introduces interrupts and shows how to program an interrupt to manage complex applications.

In the first video, we made a direct connection between the push button and the pin driving the LED. In a second video, we had to use the CyDelay function to toggle the LED at 1 Hz. Most of the time, these are not an optimized way to use the microcontroller. It’s better to trigger interrupts to perform a given action and then free the microcontroller for more tasks to manage complex applications or put it in low power mode to decrease the average current consumption of the application.

  
 
For this new project the red LED is connected to port 2 pin 6 again and with no hardware connection as pin level to turn on and off the LED will be handled by interrupt and C code.

An input pin to detect the switch is closed. As the switch connects to ground when closed, this pin must be configured with an interrupt on a falling edge, a driving mode as resistive pull up and an initial drive state at high. An interrupt component can then be attached. The interrupt component is named Pin_SW_Int. 

All the information about the available APIs is in the datasheets. To detect an interrupt, the function Pin_SW_Int_StartEx with the name of handler as parameter makes the job. It calls the function CY_ISR where we toggle the red LED and clear the interrupt

 

To automatically toggle the LED, a TCPWM component configured as a timer is connected to an interrupt component. To make math simple, a 32 kHz clock feeds the timer and the period is programmed at 32,000 counts. Hence, an interrupt is triggered every second. 


The C code is very simple again. The timer must be started, then the detection of the interrupt to call the Interrupt Service Routine. The LED is then toggled and the interrupt is cleared.
 
 

Vidéos récentes

Désolé, le filtre sélectionné n’a renvoyé aucun résultat.

Nous avons mis à jour notre politique de confidentialité. Prenez un moment pour lire les changements. En cliquant sur "J'accepte", vous acceptez la clause de confidentialité d'Arrow Electronics ainsi que les conditions d'utilisation.

Notre site Internet place des cookies sur votre appareil pour améliorer votre expérience et pour améliorer notre site. Pour en savoir plus sur les cookies que nous utilisons et la façon de les désactiver, cliquez ici. Des cookies et des technologies de suivi peuvent être utilisés à des fins de marketing. En cliquant sur « Accepter », vous consentez au placement de cookies sur votre appareil et à notre utilisation de technologies de suivi. Cliquez sur « En savoir plus » pour de plus amples informations et instructions sur la façon de désactiver les cookies et les technologies de suivi. Même si l'acceptation des cookies et technologies de suivi est volontaire, leur désactivation peut entraîner un mauvais fonctionnement du site Internet et certaines publicités peuvent être moins pertinentes pour vous. Nous respectons votre confidentialité. Lisez notre politique de confidentialité ici.