Documente Academic
Documente Profesional
Documente Cultură
Polling
Polling iteratively checks a device or
registers for data.
This method of implementing request
checking is cumbersome as it requires
the MC to frequently suspend
operations to check for new data from
devices or registers.
Interrupts
Nothing is done until a Request is
issued
Once issued, the CPU suspends
execution of the main program until
instructions in the Interrupt Service
Routine (ISR) are executed
More efficient than constantly scanning
devices or registers for new Data
Hardware Interrupt
Complete
Current
Instruction
YES
Maskable
Mask Set
NO
Complete
Current
Instruction
YES
Wait For Interrupt (WAI)
Maskable
NO
Is the
Mask Set?
SP -5
Condition Code
Register
Accumulator B
SP -4
Accumulator A
SP -3
SP -2
SP -1
SP
NO
YES
1
Stack Pointer
SP -6
Condition Code
Register
Begin Interrupt
Program (ISR)
Clear Mask (CCR4) (set to 0)
Back to
Main Program
Interrupts: Flow
Interrupt
Vector
CPU Registers
SP
PCL
SP-1
PCH
SP-2
IYL
SP-3
IYH
SP-4
IXL
SP-5
IXH
SP-6
ACCA
SP-7
ACCB
SP-8
CCR
Last value to be
pulled from
stack
Hardware Interrupt
Software Interrupt (SWI)
Complete
Current
Instruction
YES
Maskable
Mask Set
NO
Wait For Interrupt (WAI)
2.
NO
YES
1
Mask Set
3.
4.
YES
NO
Maskable
1.
Complete
Current
Instruction
Store MPU Registers to SP
Hardware Interrupt
5.
6.
7.
0
Load Interrupt Vector into PC
Begin Interrupt
Program (ISR)
Clear Mask (CCR4) (set to 0)
8.
Back to
Main Program
9.
Interrupt Types
2 Types :
Maskable
27 Maskable Interrupts
Split into Local and Global Types
Lower Priority than Non-Maskable
Priority between Maskable Interrupts can be
adjusted via the HPRIO
Non-Maskable
6 Non-Maskable Interrupts
Default Priority between Non-Maskable
Interrupts that cannot be adjusted
Maskable Interrupts
Global
I-bit in the CCR
Local
Interrupt enable bit
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
IRQ
Real-Time Interrupt
Standard Timer Channel 0
Standard Timer Channel 1
Standard Timer Channel 2
Standard Timer Channel 3
Standard Timer Channel 4
Standard Timer Channel 5
Standard Timer Channel 6
Standard Timer Channel 7
Standard Timer Overflow
Pulse Accumulator A Overflow
Pulse Accumulator Input Edge
SPI transfer Complete
SCI system
ATD
Port J
CRG PLL Lock
CRG Self Clock Mode
Flash
CAN Wakeup
CAN Errors
CAN Receive
CAN Transmit
Port P
PWM Emergency Shutdown
VREG LVI
Address: $001F
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
PSEL7
PSEL6
PSEL5
PSEL4
PSEL3
PSEL2
PSEL1
Bit 0
Write the low byte of the maskable interrupt vector to HPRIO to elevate
that maskable interrupt to the highest priority
Ex: writing $DE to HPRIO elevates the Standard Timer Overflow to highest
priority (Standard Timer Overflow vector = $FFDE)
Bit 7
Bit 6
Bit 5
Bit 4
Bit 3
Bit 2
Bit 1
PSEL7
PSEL6
PSEL5
PSEL4
PSEL3
PSEL2
PSEL1
Bit 0
Non-Maskable Interrupts
6 Non-Maskable
Interrupts
Follows a default priority
arrangement
Interrupts are not subject
to global masking
Except XIRQ
Global mask is X in CCR
1.
2.
3.
4.
Non-Maskable Interrupts:
Unimplemented instruction trap
Non-Maskable Interrupts:
Software Interrupt-SWI
Software instruction, thus cannot be
interrupted until completed
Uninhibited by global mask bits in the CCR
Similar to other interrupts, sets I-bit upon
servicing
Non-Maskable Interrupts:
XIRQ
Enabled by TAP (Transfer accumulator A to CCR)
which, while being unable to transfer the X-bit
from 0->1 will convert the X-bit from 1->0
After it is cleared, software cannot set X-bit
(only set by the XIRQ or during Reset), thus
XIRQ is non-maskable
Higher priority than any source maskable by Ibit
Both X and I bits are both automatically set by
Reset or recognition of XIRQ interrupt
RTI restores X and I bit to pre-interrupt states
Interrupt Vectors
Points to the memory address where the
Interrupt Subroutine is stored
Vector addresses can change depending
on whether MON12 is in use or not
Resets
Forces MCU to:
Sources of Resets
Power on Reset (POR)
Sources of Resets
Computer Operating Properly (COP) Reset
Standby Modes
Suspends CPU operation until reset or
interrupt occurs
Used to reduce power consumption
Two standby modes:
WAIT
STOP
Opcode (WAI)
Suspends CPU processing
CPU registers are stacked
On-chip crystal oscillator remains active
Example
Problem: 1ms
Write a routine to interrupt the MC9S12C32 after 1msec of elapsed time.
interrupt
1: Assign
values
to labels
2: Delay
unwanted
interrupts
3: Set
timer
registers
4: Store
ISR
5: Set delay
& unmask
Example
Problem: 1ms
interrupt
TC3HI
EQU $0056 /* IOC3 output compare register*/
TIOS EQU $0040 /* Input capture/output compare select*/
TIE EQU $004C /* Timer interrupt enable register*/
TFLG1 EQU $004E /* Timer interrupt flag register 2 */
TCTL2 EQU $0049 /* Timer control register 2*/
TCNTEQU $0044 /* Timer count register*/
IOC3ISR EQU $2000 /* Location of IOC3 ISR*/
IOC3VEC EQU $0FE8 /* Location of IOC3 interrupt vector*/
BIT3HI EQU %00001000/* Bit 3 set HIGH, all others LOW*/
DLYIOMSEQU 8000 /* 8000 cycles = 1ms*/
Example
Problem: 1ms
Step 2: Delay unwanted interrupts
interrupt
ORG
SEI
$1000
/* Set I bit in CCR to mask interrupts */
/* Clear I bit at the end of our routine */
Alternatively,
ORG
LDD
STD
$1000
#$FFFF/* Set output compare reference to
maximum */
TC3HI /* Store output compare reference */
Example
Problem: 1ms
interrupt
#BIT3HI
/* BIT3HI = %00001000 */
TIOS /* Configure IOC3 as output compare
(IOS3)*/
TIE /* Enable IOC3 Interrupt bit (C3I)*/
TFLG1 /* Clear IOC3 Interrupt Flag bit (C3F)
*/
#$C0 /* #$C0 = #%11000000 */
TCTL2 /* Successful compare will set PT3
high */
TIOS
IOS7IOS6
IOS5IOS4IOS3IOS2IOS1
IOS0
7
6 settings
5
4
3
2the 1timer
0
Configure
desired
using
registers
TIE
C7I
C6I
C5I
C4I
C3I
C2I
C1I
C0I
7
6
5
4
3
2
1
0
$0040
$004C
TFLG1
C7F
C6F
C5F
C4F
C3F
C2F
C1F
C0F
7
6
5
4
3
2
1
0
$004E
TCTL2
$0049
Example
Problem: 1ms
interrupt
#IOC3ISR /* IOC3ISR = $2000, starting
address of ISR*/
IOC3VEC /* IOC3VEC = $0FE8,
high byte ($20) stored in $0FE8 and
low byte ($00) stored in $0FE9 */
Example
Problem: 1ms
interrupt
PHOTOTRANSISTORS*,
OPTO-ISOLATORS*,
TRIACS, AND
THERMISTORS
* = USED IN ME 4447/6405
Phototransistors
Behave like regular
transistors, but:
Use light-sensitive
collector-base junction
to control collectoremitter current (ICE)
Base often unconnected,
otherwise biased to
adjust sensitivity to light
Small collector-emitter leakage current when
no light is incident, called dark current
Phototransistor Application:
Obstacle Detection
Phototransistors: Additional
Notes
Must be properly biased (as with regular
transistors)
Used in linear and saturation/cut-off
regions
Sensitive to temperature changes
Must be protected against moisture
Hermetic packaging more expensive, but
more tolerant of severe environments than
plastic packaging
Optoisolators
Relay
Optoisolator Structure
Glass dielectric separates input from
output
Planar
Silicon dome
Optoisolator Application
Transmitting analog or digital signals
between circuits, esp. with mismatched
voltages, noise issues, inductive loads
Arduino isolated from relay drivers:
To Arduino
To Arduino
http://arduino-info.wikispaces.c
om/RelayIsolation
Triac
Triac Structure
Triac Applications
High Power TRIACS
Switching for AC circuits, allowing the control of
very large power flows with milliampere-scale
control currents
Can eliminate mechanical wear in a relay
Cons:
Cannot open switch with gate; must reduce
current through the device below its holding
current to turn off
Relevant parameters:
Thermistors
V or R
Thermocouple voltage
(versatile)
Thermistor Characteristics
Extremely non-linear (high process
dependency)
An individual thermistor curve can be very
closely approximated by using the
T = Degrees Kelvin
Steinhart-Hart equation:
1
3
R = Resistance of
= A B ln( R) C ln( R)
the thermistor
T
A,B,C = Curve-fitting
constants
Thermistor Characteristics
Wheatstone bridge with selector switch to
measure temperature at several locations
References
Interrupt program example: 1ms interrupt
Timer module register details from TIM_16B8C Block User Guide
Phototransistors
http://www.radio-electronics.com/info/data/semicond/phototransistor/photo_t
ransistor.php
Optoisolators
http://arduino-info.wikispaces.com/RelayIsolation
http://yourduino.com/sunshop2/index.php?l=product_detail&p=218
Triacs
http://www.radio-electronics.com/info/data/semicond/triac/what-is-a-triac-basi
cs-tutorial.php
http://www.digikey.com/us/en/techzone/lighting/resources/articles/DimmingLEDs-with-Traditional-TRIAC-Dimmers.html
http://www.circuitstoday.com/diac-applications
Thermistors
http://www.radio-electronics.com/info/data/resistor/thermistor/thermistor.php
Previous student lectures
Interrupts, Thermistors, Opto-isolators and Phototransistors Fall 2009 Kipp
Schoenwald, Stephen Hunte, Joseph Storey
DACs and Triacs Fall 2009 Wye-Chi Chok
Questions?