Introducing the 68HC12

Download Report

Transcript Introducing the 68HC12

Example 18
Pulse Train Using Interrupts
Lecture L8.2
PIM_9DP256
Block Diagram
Timer module
Timer Pins
PT0 – PT7
Pins 9,10,11,12,
15,16,17,18
Timer Pins
PT0 – PT7
Pins 9,10,11,12,
15,16,17,18
PT6 = Pin 17
Pulse train
TC6 match
period
pwidth
TC7 match
Output Compare
16-bit free-running counter, TCNT
Table 18.1 C Function calls for generating a pulse train
Function
Description
void ptrain6_init(void);
initialize pulse train interrupts on PT6
timer clock = 1.5 MHz
void ptrain6(int period, int pwidth); update TC6 and TC7 in timer 6 interrupt routine
TC6 match
period
TC7 match
pwidth
MC9S12DP256B Interrupt Vectors
Vector
Number
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Interrupt Source
Reset
Clock Monitor Fail Reset
COP Failure Reset
Unimplemented Instruction Trap
SWI
XIRQ
IRQ
Real-Time Interrupt
Timer Channel 0
Timer Channel 1
Timer Channel 2
Timer Channel 3
Timer Channel 4
Timer Channel 5
Timer Channel 6
Timer Channel 7
Timer Overflow
Vector Address
$FFFE-$FFFF
$FFFC-$FFFD
$FFFA-$FFFB
$FFF8-$FFF9
$FFF6-$FFF7
$FFF4-$FFF5
$FFF2-$FFF3
$FFF0-$FFF1
$FFEE-$FFEF
$FFEC-$FFED
$FFEA-$FFEB
$FFE8-$FFE9
$FFE6-$FFE7
$FFE4-$FFE5
$FFE2-$FFE3
$FFE0-$FFE1
$FFDE-$FFDF
// Example 18: Interrupt-Driven Pulse Train
#include <hidef.h>
/* common defines and macros */
#include <mc9s12dp256.h>
/* derivative information */
#include "main_asm.h" /* interface to the assembly module */
#pragma LINK_INFO DERIVATIVE "mc9s12dp256b"
int period;
int pwidth;
// period of pulse train
// high pulse width of pulse train
// Timer channel 6 interrupt service routine
void interrupt 14 handler(){
ptrain6(period, pwidth);
}
void main(void) {
PLL_init();
ptrain6_init();
period = 0x4567;
pwidth = 0x1234;
while(1) {
}
// set system clock frequency to 24 MHz
// do nothing while generating pulse train