Difference between revisions of "Interrupts"
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | |||
''See [[Interrupt Icon Properties]]'' | ''See [[Interrupt Icon Properties]]'' | ||
− | |||
− | |||
Line 8: | Line 5: | ||
Interrupts can be used to temporarily pause the operation of the microcontroller and allow something more urgent to happen before continuing where it left off. | Interrupts can be used to temporarily pause the operation of the microcontroller and allow something more urgent to happen before continuing where it left off. | ||
+ | |||
+ | Lets give a simple example of this in real life. You might be playing a video game (performing the main program function) when the phone rings (the interrupt event) you pause the game and go and answer the phone (interrupt service macro) when the phone call is complete you go back and unpause the game and continue from where you left off. | ||
Line 14: | Line 13: | ||
Timer interrupts are useful for monitoring the passage of time. Whether you want something to happen on a regular tick or simply want to measure how long something has taken a timer interrupt can prove to be very handy tool. | Timer interrupts are useful for monitoring the passage of time. Whether you want something to happen on a regular tick or simply want to measure how long something has taken a timer interrupt can prove to be very handy tool. | ||
+ | |||
+ | ===Software PWM=== | ||
+ | |||
+ | Example program showing how to generate software PWM to drive multiple LEDs. Here we have a knight rider effect using eight LEDs. Each LED has a duty value between 0 (off) and 63 (bright on). | ||
+ | |||
+ | {{Fcfile|SoftPWM.fcfx|Software PWM}} | ||
+ | |||
+ | [[File:SwPWMLEDs.gif]] | ||
===Quadrature Encoder using Timer Based Polling=== | ===Quadrature Encoder using Timer Based Polling=== |
Latest revision as of 09:21, 24 September 2020
Most devices have built in interrupts users can call by using the Interrupt flowchart icon.
Interrupts can be used to temporarily pause the operation of the microcontroller and allow something more urgent to happen before continuing where it left off.
Lets give a simple example of this in real life. You might be playing a video game (performing the main program function) when the phone rings (the interrupt event) you pause the game and go and answer the phone (interrupt service macro) when the phone call is complete you go back and unpause the game and continue from where you left off.
Contents
Timer Interrupts
Timer interrupts are useful for monitoring the passage of time. Whether you want something to happen on a regular tick or simply want to measure how long something has taken a timer interrupt can prove to be very handy tool.
Software PWM
Example program showing how to generate software PWM to drive multiple LEDs. Here we have a knight rider effect using eight LEDs. Each LED has a duty value between 0 (off) and 63 (bright on).
Quadrature Encoder using Timer Based Polling
Example program showing how to use a quadrature encoder component using a polling method via a timer interrupt.
RGB LED Control using Timer
Example program showing how to control a RGB LED using a timer interrupt to set the LED refresh rate, uses three analogue sliders to set the output colour (PWM duty) of the R, G and B LEDs.
INT Single Pin Interrupts
The INT type interrupts allow you to monitor the state of a single port pin.
Normally you can choose if the interrupt macro is called when the port pin state changes on the rising edge or falling edge.
Counting Pulses using INT
Example program showing how to use a single pin interrupt (INT) to count the number of pulses arriving on an input pin.
IOC (Interrupt On Change) Multiple Pin Interrupts
The IOC type interrupts allow you to monitor the state of a number of port pins.
Different chips have different levels of IOC support ranging from a few pins on the chip to all of the pins.
Chips with advanced IOC support allow you to choose the pins you wish to use using the IOC interrupt properties.
If any of the enabled pins change state then the interrupt macro is triggered.
Quadrature Encoder using IOC
Example program showing how to use a quadrature encoder component using a interrupt on pin state change interrupt (IOC).
Counting Multiple Pulses using IOC
Example program showing how to use a interrupt on pin state change interrupt (IOC) to individually count the number of pulses arriving on input pins.
RXINT UART Receive Interrupts
The RXINT interrupt allows the interrupt macro to be called whenever a byte is received by a hardware UART channel.
Communications Bridge Using UART RXINT
Example program to listen for incoming bytes on the UART, any bytes that are received are placed into the circular buffer ready to be processed. In this case forwarded onto a computer using the USB serial connection.