Timers Chapter 10 9S12DP256. Timers The 9S12DP256 Programmable Timer Output Compares Pulse Train Using Interrupts Input Capture Measuring the Period of.

Slides:



Advertisements
Similar presentations
More fun with Timer/Counters
Advertisements

4-1 Timers Timers can be used for  timing  event counting  pulse width measurement  pulse generation  frequency multiplication There are 8 Timers.
10-1 EE 319K Introduction to Microcontrollers Lecture 10: Interrupts, Output Compare Periodic Interrupts Read Book Sections 9.1, 9.2, 9.4, 9.6.1, 9.6.2,
EET 2261 Unit 10 Enhanced Capture Timer  Read Almy, Chapter 20.  Homework #10 and Lab #10 due next week.  Quiz next week.
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Pulse Width Modulation modes
The Serial Communication Interface (SCI) MC9S12-DP256 Chapter 11.
1.  8051 Timers “count up,” incrementing the Timer’s respective “count register” each time there is a triggering clock pulse. 2  When the “count register”
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
ENG3640 Microcomputer Interfacing Week #6 Timing Generation and Measurement.
CHAPTER TIMER PROGRAMMING Timers The 8051 has two timers/counters, they can be used as ◦ Timers to generate a time delay ◦ Event counters.
ECE 371- Unit 11 Timers and Counters (“Stop Watches and Alarm Clocks”)
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
HCS12 Technical Training Module 8 –Enhanced Timer, Slide 1 MOTOROLA and the Stylized M Logo are registered in the US Patent & Trademark Office. All other.
8254 Counter/Timer Counter Each of the three counter has 3 pins associated CLK: input clock frequency- 8 MHz OUT GATE: Enable (high) or disable.
Timer/counter Chapter 12
ARM Timers.
System Clocks.
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Unit 10.2 Timer Examples. Example – Music Generation Channel 6 – Set up as a timer Output to Generate Square Waves Channel 4 – Set up as a timer Output.
Revised: Aug 1, ECE 263 Embedded System Design Lessons 23, 24 - Exceptions - Resets and Interrupts.
ECE 447 Fall 2009 Lecture 10: TI MSP430 Timers and Capture Modes.
Timers.
Senior Project Presentation: Designers: Shreya Prasad & Heather Smith Advisor: Dr. Vinod Prasad May 6th, 2003 Internal Hardware Design of a Microcontroller.
ECE 447: Lecture 8 Timer System (1). ECE 447: 68HC11 Timer System 1.Generating delays - imposing a specific delay between two points in the program by.
Chapter 11: Timer Subsystem Esteban Rodriguez-Marek Eastern Washington University Department of Engineering & Design.
ELE22MIC Lecture 15 Applications of Parallel Input Output (I/O)
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
1 68HC11 Timer Chapter HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
1 68HC11 Timer HC11 or HC12: Chapter HC11 Timer Subsystem  Several timing functions: Basic timing Basic timing Real time interrupts Real time.
Timers and Interrupts Mark Neil - Microprocessor Course.
Real Time Interrupts Section Real-Time Interrupt (RTI) Most operating systems (OS) require an interrupt every T seconds by the RTI RTI interrupts.
#1 of 10 Tutorial Introduction PURPOSE -To explain how to configure and use the Timer Interface Module in common applications OBJECTIVES: -Identify the.
HCS12 TIMER FUNCTIONS Razvan Bogdan Embedded Systems.
George W. Woodruff School of Mechanical Engineering, Georgia Tech ME4447/6405 ME 4447/6405 Microprocessor Control of Manufacturing Systems and Introduction.
1 68HC11 Timer. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output compare.
Timers Presented by: Griffin Reid Rohit Vardhan Freddie Wilson Date: October 25, 2005.
Seth Schwiethale James Crosetto James Ellison.  square pulse of ms, repeats every 20 ms  It is the same for both steering and acceleration 
80C51 Block Diagram 1. 80C51 Memory Memory The data width is 8 bits Registers are 8 bits Addresses are 8 bits – i.e. addresses for only 256.
ELE22MIC Lecture 17 Writing 68HC11 software 68HC11 Main Timer System –Output Compare –What is different about TOC1?
Timers Lecture L4.4. Reference TIM_16B8C Block User Guide S12TIM16B8CV1.pdf.
EET 2261 Unit 13 Enhanced Capture Timer
Why are Timer Functions Important?
Lecture 10: TI MSP430 Timers and Capture Modes
V.V.P. ENGINEERING COLLEGE,RAJKOT
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
ECE 3430 – Intro to Microcomputer Systems
ECE 3430 – Intro to Microcomputer Systems
ELE22MIC Lecture 18 Writing 68HC11 software 68HC11 Main Timer System
Example 19 Measuring Pulse Widths Using Interrupts
AVR Addressing Modes Subject: Microcontoller & Interfacing
BVM Engineering College Electrical Engineering Department : Microprocessor and Microcontroller Interfacing Interrupts of 8051 Prepared by:
Freescale ARM Timer Programming
Timer/Counter Modified from Dr. Lam Phung’s Slides.
ATmega103 Timer0 and Interrupts
8254 Timer and Counter (8254 IC).
Timer.
Programmable Interval timer 8253 / 8254
8-bit Timer/Counter2 with PWM and Asynchronous Operation
Programmable Interval timer 8253 / 8254
Example 18 Pulse Train Using Interrupts
MCO556 Timer System Exercise.
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
Programmable Interval Timer
Presentation transcript:

Timers Chapter 10 9S12DP256

Timers The 9S12DP256 Programmable Timer Output Compares Pulse Train Using Interrupts Input Capture Measuring the Period of a Pulse Train Using Interrupts

PIM_9DP256 Block Diagram

Timer Counter

Timer System Control Register 1

Setting the timer count time

Timers The 9S12DP256 Programmable Timer Output Compares Pulse Train Using Interrupts Input Capture Measuring the Period of a Pulse Train Using Interrupts

\ Delay using 9S12DP256 output compare timer functions. File: OC_DELAY.WHP HEX 0040 CONSTANT TIOS \ Timer Input Cap.\Output Comp. Select 0044 CONSTANT TCNT \ Timer Counter Register 0046 CONSTANT TSCR1 \ Timer System Control Register 1 004D CONSTANT TSCR2 \ Timer System Control Register 2 004E CONSTANT TFLG1 \ Timer Interrupt Flag Register 1 005C CONSTANT TC6 \ Timer Output Compare Register 6 \ Use output compare 6 for a 25 msec delay : TIMER.INIT ( -- ) \ Initialize timer 40 TIOS C! \ select output compare 6 32 TSCR2 C! \ div by 4: 2 MHz timer clock 80 TSCR1 C! ; \ enable timer : C6F.CLR ( -- ) \ Clear C6F - bit 6 - in TFLG1 ) 40 TFLG1 C! ;

DECIMAL : 25.MSEC ( cnt -- cnt' ) \ wait 25 msec \ add to prev cnt DUP TC6 ! \ store in output compare 6 reg C6F.CLR \ clear output compare 6 flag BEGIN \ wait for timeout 6 TFLG1 ?HI UNTIL ; : S.DELAY ( n -- ) \ delay n seconds TIMER.INIT 40 * \ no. of 25.msec delays SWAP \ cnt # FOR 25.MSEC NEXT DROP ;

Pulse Train Example

\ Pulse train using output compares 7 and 6. File: PULSE.WHP HEX 0040 CONSTANT TIOS \ Timer Input Cap.\Output Comp. Select 0042 CONSTANT OC7M \ Output Compare 7 Mask Register 0043 CONSTANT OC7D \ Output Compare 7 Data Register 0044 CONSTANT TCNT \ Timer Counter Register 0046 CONSTANT TSCR1 \ Timer System Control Register CONSTANT TCTL1 \ Timer Control Register 1 004D CONSTANT TSCR2 \ Timer System Control Register 2 004E CONSTANT TFLG1 \ Timer Interrupt Flag Register 1 005C CONSTANT TC6 \ Timer Output Compare Register 6 005E CONSTANT TC7 \ Timer Output Compare Register 7 DECIMAL VARIABLE P_WIDTH 6625 P_WIDTH ! VARIABLE PERIOD PERIOD ! HEX : TINIT ( -- ) C0 TIOS C! \ select output compares 6 & 7 02 TSCR2 C! \ div by 4: 2 MHz timer clock 80 TSCR1 C! \ enable timer DUP TC6 ! TC7 ! \ init cnt in TC6 & TC7 6 OC7M HI \ pulse train out PT6 6 OC7D LO \ PT6 goes low on TC7 match 4 TCTL1 HI 5 TCTL1 HI ; \ set PT6 high on TC6 match

: CLR.C76 ( -- ) \ clear both C7F and C6F C0 TFLG1 C! ; : PULSE ( -- ) TINIT BEGIN CLR.C76 + DUP TC7 ! \ TC7new = TC7old + PERIOD + TC6 ! \ TC6 = TC7new + P_WIDTH BEGIN \ wait for PT6 to go low on 6 TFLG1 ?HI \ TC7 match and the high on UNTIL \ TC6 match AGAIN ; DECIMAL

Timers The 9S12DP256 Programmable Timer Output Compares Pulse Train Using Interrupts Input Capture Measuring the Period of a Pulse Train Using Interrupts

Pulse Train

\ Pulse train using output compares 7 and 6. File: PULSEI.WHP HEX 0040 CONSTANT TIOS \ Timer Input Cap.\Output Comp. Select 0042 CONSTANT OC7M \ Output Compare 7 Mask Register 0043 CONSTANT OC7D \ Output Compare 7 Data Register 0044 CONSTANT TCNT \ Timer Counter Register 0046 CONSTANT TSCR1 \ Timer System Control Register CONSTANT TCTL1 \ Timer Control Register 1 004C CONSTANT TIE \ Timer Interrupt Enable Register 1 004D CONSTANT TSCR2 \ Timer System Control Register 2 004E CONSTANT TFLG1 \ Timer Interrupt Flag Register 1 005C CONSTANT TC6 \ Timer Output Compare Register 6 005E CONSTANT TC7 \ Timer Output Compare Register 7 3FE2 CONSTANT TC6.IVEC \ Timer Channel 6 interrupt vector DECIMAL VARIABLE P_WIDTH 6625 P_WIDTH ! VARIABLE PERIOD PERIOD ! HEX : TINIT ( -- ) C0 TIOS C! \ select output compares 6 & 7 00 TSCR2 C! \ div by 1: 8 MHz timer clock 80 TSCR1 C! \ enable timer DUP TC6 ! TC7 ! \ init cnt in TC6 & TC7 6 OC7M HI \ pulse train out PT6 6 OC7D LO \ PT6 goes low on TC7 match 4 TCTL1 HI 5 TCTL1 HI \ set PT6 high on TC6 match 40 TIE C! ; \ enable TC6 interrupts

: CLR.C76 ( -- ) \ clear both C7F and C6F C0 TFLG1 C! ; INT: TC6.INTSER ( -- ) + DUP TC7 ! \ TC7new = TC7old + PERIOD + TC6 ! \ TC6new = TC7new + P_WIDTH CLR.C76 RTI; : SET.TC6.INTVEC ( -- ) [ ' TC6.INTSER ] LITERAL TC6.IVEC ! ; : PULSEI ( -- ) SEI TINIT SET.TC6.INTVEC CLI ; DECIMAL

Timers The 9S12DP256 Programmable Timer Output Compares Pulse Train Using Interrupts Input Capture Measuring the Period of a Pulse Train Using Interrupts

Input Capture

\ Use input capture to measure width of single pulse. File: PWIDTH.WHP \ Polling mode -- no interrupts \ Use TC2 -- signal on PT2 HEX 0040 CONSTANT TIOS \ Timer Input Cap.\Output Comp. Select 0044 CONSTANT TCNT \ Timer Counter Register 0046 CONSTANT TSCR1 \ Timer System Control Register 1 004B CONSTANT TCTL4 \ Timer Control Register 4 004D CONSTANT TSCR2 \ Timer System Control Register 2 004E CONSTANT TFLG1 \ Timer Interrupt Flag Register CONSTANT TC2 \ Timer Input Capture Register 2 : TIC.INIT ( -- ) 0 TIOS C! \ select all input captures 0 TSCR2 C! \ div by 1: 8 MHz timer clock 80 TSCR1 C! ; \ enable timer

: PULSE.WIDTH ( -- n ) \ Measure width n of pulse TIC.INIT \ initialize timer input capture 5 TCTL4 LO \ capture on rising edge 4 TCTL4 HI 04 TFLG1 C! \ clear C2F flag BEGIN 2 TFLG1 ?HI \ wait for rising edge UNTIL \ t1 04 TFLG1 C! \ clear C2F flag 5 TCTL4 HI \ capture on falling edge 4 TCTL4 LO BEGIN 2 TFLG1 ?HI \ wait for falling edge UNTIL \ t1 t2 04 TFLG1 C! \ clear C2F flag SWAP - ; \ width = (t2 - t1) DECIMAL

Timers The 9S12DP256 Programmable Timer Output Compares Pulse Train Using Interrupts Input Capture Measuring the Period of a Pulse Train Using Interrupts

\Measuring the period of a pulse train. File: PERIOD.WHP HEX 0040 CONSTANT TIOS \ Timer Input Cap.\Output Comp. Select 0044 CONSTANT TCNT \ Timer Counter Register 0046 CONSTANT TSCR1 \ Timer System Control Register 1 004B CONSTANT TCTL4 \ Timer Control Register 4 004C CONSTANT TIE \ Timer Interrupt Enable Register 004D CONSTANT TSCR2 \ Timer System Control Register 2 004E CONSTANT TFLG1 \ Timer Interrupt Flag Register 1 004F CONSTANT TFLG2 \ Timer Interrupt Flag Register CONSTANT TC1 \ Timer Input Capture Register 1 3FEC CONSTANT TC1.IVEC \ Timer Channel 1 interrupt vector 3FDE CONSTANT TOF.IVEC \ Timer overflow flag interrupt vector VARIABLE OVCNT \ timer overflow count VARIABLE OVCNT.OLD \ old timer overflow count VARIABLE TC1.OLD \ old TC1 VARIABLE DPERIOD 2 VALLOT \ double word period dH dL : INIT.IC ( -- ) C0 TIOS C! \ select input capture 1 00 TSCR2 C! \ div by 1: 8 MHz timer clock 80 TSCR1 C! \ enable timer 3 TCTL4 LO 2 TCTL4 HI \ rising edge of TC1 02 TFLG1 C! \ clear any old flags 80 TFLG2 C!\ clear TOI flag 7 TSCR2 HI \ enable TOI interrupt 1 TIE HI ; \ enable TC1 interrupt

\Timer overflow interrupt routine INT: TOF.INTSER ( -- ) 1 OVCNT +! \ inc OVCNT 80 TFLG2 C! \ clear TOF RTI; \Input capture 1 interrupt routine INT: TC1.INTSER ( -- ) \ ic.o ov.o DUP TC1.OLD ! \ ic.o ov.o ic DUP OVCNT.OLD ! \ ic.o ov.o ic ov 2SWAP D- \ spL spH DPERIOD 2! \ store period in DPERIOD 02 TFLG1 C! \ clear C1F RTI; \Set interrupt vectors : SET.TOF.INTVEC ( -- ) [ ' TOF.INTSER ] LITERAL TOF.IVEC ! ; : SET.TC1.INTVEC ( -- ) [ ' TC1.INTSER ] LITERAL TC1.IVEC ! ;

\Main program : MAIN( -- ) SEI\ set interrupt flag SET.TOF.INTVEC\ set interrupt vectors SET.TC1.INTVEC INIT.IC \ init input capture CLI ; \ clear interrupt flag DECIMAL