Resources
- Microcontrollers: From Assembly Language to C Using the
PIC24 Family, chapter 9
- Pages 317-332, seriously
- Pages 337-348, Periodic Timer Interrupts, creatively
- Pages 354-356, A Rotary Encoder Interface & A Keypad Interface, inquisitively
- Mississippi State ECE 3724 notes
- Mississippi State ECE 3724 video lectures
- Microchip documents
- PIC32MX1XX/2XX datasheet, Chapters 7, 12 and 13 (pp. 87-94, 151-158)
- PIC12F1572 datasheet, Chapters 7, 18, 19 and 20 (pp. 65-77, 143-159)
- PIC32 Family Reference Manual (Documentation → Reference Manual)
- PIC32 Family Reference Manual, Sect. 8 Interrupts
- PIC32 Family Reference Manual, Sect. 14 Timers
- PIC32 Family Reference Manual, Sect. 16 Output Compare
- MPLABĀ® XC32 C/C++ Compiler User’s Guide, Chapter 13 (pp. 187-198)
“Interrupts” you may have encountered
Processing has several event-driven functions that are a bit like interrupts.
draw
— timer-drivenkeyTyped
mousePressed
JavaScript, with its many callback function is also event-driven.
Arduino programmers sometimes use and overuse interrupts to make their program behave more predictably. Arduino PWM also uses timers.
The Unix signal is a bit like an interrupt. The Unix command kill can deliver a signal to a process.
Interrupts
Properties of the PIC32 interrupt hardware
INTCON
— number and size of vectorsPRISS
— shadow registers will be usedIFSx
— interrupt has been requestedIECx
— interrupt is enabledIPCx
— priority of interrupt
The PIC32 has a special set of
CP0
registers that are used for operating systems
functions such as interrupt handling.
Notes from UC-Davis
and UC-Berkeley
provide detailed descriptions of how the MIPS32 architecture
handles exceptions and interrupts.
The best thing to do when handling an interrupt
Defer.
The worse thing to do when handling an interrupt
Delay.
The ISR
- ECE 3724 notes on Interrupts (pp. 11-14)
- MPLABĀ® XC32 C/C++ Compiler
User’s Guide, Chapter 13 (pp. 187-198)
__attribute__((interrupt(IPL3))) myISR(void) ;
__ISR(vector, IPL) myISR(void) ;
void __ISR (_TIMER_1_VECTOR, IPL7SRS) Timer1Handler (void);
Code generated by the compiler will save and restore registers.
This includes the various callee-saved
registers such as $tn
.
Most PIC32 interrupt service routines are fairly simple.
Connecting interrupts to actions on pins
- On an embedded system
- ECE 3724 notes on Interrupts (pp. 15-16, 20-21)
- UMassAmherstM5 interrupt example
- On a multi-user operating system
- userspace —
GPIO
Sysfs interface or
How to use GPIO signals
- Open /sys/class/gpio/export
- Write pinNum to export file
- Open /sys/class/gpio/gpiopinNum/direction
- Write
in
to direction file - Open /sys/class/gpio/gpiopinNum/edge
- Write
both
to edge file descriptor - Open /sys/class/gpio/gpiopinNum/value
- Perform poll
for
POLLPRI
event on value file descriptor - Perform lseek on value file descriptor
- Perform read on value file descriptor
- Close files as needed
- Unexport as needed
- kernelspace driver
- userspace —
GPIO
Sysfs interface or
How to use GPIO signals
Interesting things to do with interrupts
Timers
- ECE 3724 notes on Timers (pp. 22-28)
- PWM Arduino