Microprocessor Control of Manufacturing Systems and Introduction To Mechatronics
Microprocessor Control of Manufacturing Systems and Introduction To Mechatronics
Microprocessor Control of Manufacturing Systems and Introduction To Mechatronics
ME 4447/6405
Microprocessor Control of Manufacturing Systems and Introduction to Mechatronics
ME4447/6405
ME4447/6405
ME4447/6405
Polling
An iterative approach which constantly checks devices for data Inefficient method for checking when input data has come in because no other instructions can be executed during polling process
ME4447/6405
Interrupts
Communication between CPU and I/O devices can be established with issue of interrupt request NOTE: Request can be issued at any time CPU suspends execution of main program until instructions in Interrupt Service Routine (ISR) are completely executed Returns to main program after ISR is completed
ME4447/6405
Types of Interrupts
There are two types of interrupts.
Maskable Non-Maskable
ME4447/6405
Maskable Interrupts
27 Maskable Interrupts
Two types of Masking
Local
I-bit in CCR
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
ME4447/6405
ME4447/6405
ME4447/6405
ME4447/6405
ME4447/6405
Bit 7 PSEL7
Bit 6 PSEL6
Bit 5 PSEL5
Bit 4 PSEL4
Bit 3 PSEL3
Bit 2 PSEL2
Bit 1 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 Bit 0
1
PSEL7
1
PSEL6
0
PSEL5
1
PSEL4
1
PSEL3
1
PSEL2
1
PSEL1 -
ME4447/6405
Non-Maskable Interrupts
6 Non-Maskable Interrupts
Follows a default priority arrangement Interrupts are not subject to global masking
1. 2. 3. 4. POR of RESET pin Clock monitor reset COP watchdog reset Unimplemented instruction trap 5. Software interrupt (SWI) 6. XIRQ interrupt
ME4447/6405
ME4447/6405
ME4447/6405
ME4447/6405
SP
SP-1 SP-2 SP-3 SP-4 SP-5 SP-6 SP-7 SP-8
PCL
PCH IYL IYH IXL IXH ACCA ACCB CCR
ME4447/6405
Interrupt Vectors
Each type of interrupt has associated vector addresses Vector addresses change depending on whether MON12 is in use With MON12 in use, user must use Monitor Interrupt Vector Table
ME4447/6405
MON12 in Use
In this case you must write the address of your Interrupt Service Routine to the vector address found in the Monitor Interrupt Vector Table
ME4447/6405
ME4447/6405
ME4447/6405
ME4447/6405
ME4447/6405
Interrupt Flow
A B Analyze Priority Set (I) or (X) to prohibit another Interrupt
Global Masking
NO YES
ISR instruction
NO
RTI
YES
Local Masking
NO
Complete Current Instruction Store all registers on the Stack Continue Program A
ME4447/6405
Write a routine to interrupt the MC9S12C32 after 10 msec of elapsed time (Assume E= 1 Mhz, Prescaler = 1, MON12 in use)
ORG LDD STD $1000 #$FFFF TC3H OR SEI LDAA STAA STAA STAA LDAB STAB LDX STX #BIT3HI TIOS TFLG1 TIE #$C0 TCTL2 #TC3ISR TC3VEC /*Set I-bit to prevent interrupt service during set-up*/ /* BIT5HI = %0010000*/ /* Select TC3 as an output compare*/ /* Clear TC3 Interrupt Flag*/ /* Enable TC3 Interrupt */ /* PT3 will be high for a successful compare */ /* TC3ISR = $2000, 2 bytes- beginning address of interrupt service routine*/ /* TC3VEC= $0FE8, This will cause the high byte ($20) of the service routine address to be stored in location $0FE8 and the low byte ($00) to be stored in $0FE9 */ /* TCNT=$0044 */ /* DLYIOMS = $2710 = 10000 */ /* IF not done elsewhere */ /* Clear I bit */
/*Delays any TC3 compares*/ /*Set output compare to the longest time so that you would not have output compare occurring when you are initializing*/
ME4447/6405
Write a routine to interrupt the MC9S12C32 after 10 msec of elapsed time (Assume E= 1 Mhz, Prescaler = 1, MON12 in use)
ORG LDD STD $1000 #$FFFF TC3H OR SEI LDAA STAA STAA STAA LDAB STAB LDD ADDD STD CLI . SWI END #BIT3HI TIOS TFLG1 TIE #$C0 TCTL2 TCNT #DLYIOMS TC3 /*Set I-bit to prevent interrupt service during set-up*/ /* BIT3HI = %0003000*/ /* Select TC3 as an output compare*/ /* Clear TC3 Interrupt Flag*/ /* Enable TC3 Interrupt */ /* PT3 will be high for a successful compare */ /* TCNT=$0044 */ /* DLYIOMS = $2710 = 10000 */ /* IF not done elsewhere */ /* Clear I bit */
/*Delays any TC3 compares*/ /*Set output compare to the longest time so that you would not have output compare occurring when you are initializing*/
ORG $0FE8 George W. Woodruff School of Mechanical Engineering, Georgia Tech FDB TC3ISR
ME4447/6405
ORG PROGRAM *Set I-bit to prevent interrupt service during set-up SEI Start timer, turn on TEN LDAA #$80 STAA TSCR2 *TOF Interrupt Enabled STAA TFLG2 *Clears TOF Interrupt Flag LDX #TOVISR *Loads register X with #1500 *Stores content of register X to address Vector incremented STX VECTOR CLR $0001 CLI * Clears I-bit to allow servicing of interrupt
ORG TOVISR LDAA $0001 * Loads address $0001 content INCA *Increment by 1 STAA $0001 *Stores value back to address CMPA #30 *Compares value to decimal 30 BNE A1 *Loads index register X with content of STRING LDX #STRING JSR OUTSTRG CLR $0001 *Clear address
A1 LDAA #$80 *Loads binary 10000000 STAA TFLG2 *Clears local flag RTI
ME4447/6405
Resets
Forces the MCU to: assume set of initial conditions begin executing instructions at predetermined starting address.
ME4447/6405
Resets
Like interrupts, resets share concept of vector fetching to force new starting point for further CPU operations. In contrast to interrupts, resets stop completely execution of set of instructions. As well, they always rest MCU hardware.
ME4447/6405
Sources of Resets
Power on Reset (POR) External Reset (RESET) Computer Operating Properly (COP) Reset Clock Monitor Reset
ME4447/6405
Power-On Resets
Power-On Reset (POR) Used only for power-up conditions to initialize MCU internal circuits. Applying Vdd to MCU triggers POR circuit, initiates reset sequence, and starts internal timing circuit. 4064 clock cycle delay after oscillator becomes active, allows clock generator to stabilize.
George W. Woodruff School of Mechanical Engineering, Georgia Tech
ME4447/6405
External Reset
System reset can also be forced by applying low level to RESET pin. External source must hold pin low for more than 4 cycles. If this happens, pin is further sampled 2 cycles after Low level at sampling instant indicates that reset has been caused by external device.
George W. Woodruff School of Mechanical Engineering, Georgia Tech
ME4447/6405
ME4447/6405
ME4447/6405
If no MCU clock edges are detected within this RC time delay, clock monitor, if set by CME control bit, would generate system reset.
ME4447/6405
If pin is still held low, CPU assumes that external reset has occurred. If pin is high, it indicates that reset was internally initiated.
George W. Woodruff School of Mechanical Engineering, Georgia Tech
ME4447/6405
ME4447/6405
ME4447/6405
Standby Modes
Suspends CPU operation until reset or interrupt occurs Used to reduce power consumption Two standby modes:
WAIT STOP
ME4447/6405
ME4447/6405
ME4447/6405
ME4447/6405
Questions???