Atmega128 Timer/Counter의 이용 분야

Slides:



Advertisements
Similar presentations
More fun with Timer/Counters
Advertisements

Lecture 8 Digital waveform generator using u-controller 2007/11/09 Prof. C.M. Kyung.
Kuliah Mikrokontroler AVR Comparator AVR Eru©September 2009 PENS.
Analog to Digital Converter
COMP3221: Microprocessors and Embedded Systems Lecture 16: Interrupts II Lecturer: Hui Wu Session 2, 2005.
Serial I/O Communication
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.
ATtiny2313 Timers/Counters CS-423 Dick Steflik. What Do You Use Timers For? Timing of events (internal or external)‏ Scheduling Events Measuring the width.
5-1 Timer/Counters In many microprocessor systems we need to:  count logic pulses  measure the frequency of signals  measure the period of pulses 
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Pulse Width Modulation modes
KyungHee Univ. 2-0 Parallel Port LCD Interface with the HD44780 Controller.
The Use of Microcontrollers
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
Slides created by: Professor Ian G. Harris Interrupts  Embedded systems often perform some tasks which are infrequent and possibly unpredictable Hang.
Timer/counter Chapter 12
ARM Timers.
A Few Words From Dilbert
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.
MCU: Interrupts and Timers Ganesh Pitchiah. What’s an MCU ?
인터럽트의 개요 Interrupt의 처리 과정
전자의료시스템 및 실습 PWM 구 환 경희대학교 전자정보대학 동서의료공학과. PWM Description - PWM(Pulse Width Modulation) - 일정한 전압에 일정한 주기를 갖는 펄스 열에서 High 레벨의 펄스 폭 이 사용자가 지정한 값으로 바뀌는.
ELE22MIC Lecture 18 The AVR Sleep Modes The ATMEGA128’s Timer System
Counter/Timer/PWM. incoming Lab. Counter counter is a device which stores the number of times a particular event or process has occurred synchronous/asynchronous.
Atmel Atmega128 Overview ALU Particulars RISC Architecture 133, Mostly single cycle instructions 2 Address instructions (opcode, Rs, Rd, offset) 32x8 Register.
CCP MODULES  The CCP module (Capture/Compare/PWM) is a peripheral which allows the user to time and control different events.  Capture Mode provides.
AVR Programming: Timers October 8, What is a timer? A register that keeps track of a current value This value is updated at a certain frequency.
1 68HC11 Timer Chapter HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output.
Timers and Interrupts Anurag Dwivedi. Let Us Revise.
CS-280 Dr. Mark L. Hornick 1 Atmel Timer/Counter System Most microcontrollers include some type of timer system Facilitates real-time monitoring and control.
Application of Interrupt and Timer : Measurement of Motor Speed.
1 68HC11 Timer HC11 or HC12: Chapter HC11 Timer Subsystem  Several timing functions: Basic timing Basic timing Real time interrupts Real time.
Interrupts  An interrupt is any service request that causes the CPU to stop its current execution stream and to execute an instruction stream that services.
Timers and Interrupts Mark Neil - Microprocessor Course.
Timers and Scheduled Interrupts
TIMERS AND INTERRUPTS AVI SINGH KEVIN JOSE PIYUSH AWASTHI.
KyungHee Univ. 1-0 Parallel Input/Output Controller (PIO)
The AVR microcontroller and embedded systems using assembly and c AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi.
충북인력개발원 전자과 공학박사 강원찬 3. Timer & Counter &PWM. uP AVR (Atmega128) PWM1=OC1A(PB5) PWM2=OC1B(PB6) T0=T1(PD6) T1=T2(PD7)
System Control & Clock UNIT 08 로봇 SW 교육원 조용수. 학습 목표 System Control Register System Clock CMSIS CMSIS Project 2.
#1 of 10 Tutorial Introduction PURPOSE -To explain how to configure and use the Timer Interface Module in common applications OBJECTIVES: -Identify the.
Mark Neil - Microprocessor Course 1 Timers and Interrupts.
Timer 1 and 2 operation, PWM Principles. Timer 1 Operation.
INSTITUTE: INSTITUTE:PARUL INSTITUTE OF TECHNOLOGY BRANCH : BRANCH :B.E. E.C.5 TH SEM. SUBJECT:MICROCONTROLLER & INTERFACING TOPIC:AVR INTTRUPT TOPIC:AVR.
16-Bit Timer/Counter 1 and 3
Timers and Scheduled Interrupts
Why are Timer Functions Important?
V.V.P. ENGINEERING COLLEGE,RAJKOT
BITS EDU. CAMPUS , VARNAMA
AVR Addressing Modes Subject: Microcontoller & Interfacing
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
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.
Timer/Counter Modified from Dr. Lam Phung’s Slides.
16-bit Timer/Counter1 Features
8-bit Timer/Counter0 with PWM
ATmega103 Timer0 and Interrupts
Pugazhendhi.M 11/12/2018 TIMERS 11/12/2018 CCET CCET.
Atmel ARM Timer Programming
DC motor and PWM.
8-bit Timer/Counter2 with PWM and Asynchronous Operation
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
Wave Generation and Input Capturing
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
COMP3221: Microprocessors and Embedded Systems
Presentation transcript:

ATmega128 Timer/Counter KyungHee Univ.

Atmega128 Timer/Counter의 이용 분야 일정 주기의 Clock 신호를 Counting 일정한 시간 주기를 갖는 펄스의 발생. 주파수(주기) 제어 펄스 폭 제어 Counter 속도 측정 : 외부 핀을 통해서 들어오는 Event를 일정 시간 동안 Count(Edge Detector) 한다. Input Capture (Timer1, Timer3) 시간 측정(펄스 폭 측정) : 일정한 주기 마다 Timer/Counter Register의 값을 Capture 하여 시간(펄스 폭) 등을 측정 한다. 펄스폭 측정 예: Timer/Counter에 일정 주기 신호를 가하고, Input Capture Pin에 피 측정 신호를 가 한다. KyungHee Univ.

ATmega128의 Timer/Counter Clock(내부 또는 외부)를 이용 하여 일정한 시간 주기 또는 일정 시간 후에 Event(Interrupt)를 발생 시킨다. Counter 외부 핀(TOSC1, TOSC2, T1, T2, T3)을 통해서 들어오는 Event를 Count(Edge Detector) 한다. ATmega128의 Timer/Counter 4개의 범용 타이머/카운트로 구성되어있다. Timer/Counter0(8비트) Timer/Counter1(16비트) Timer/Counter2(8비트) Timer/Counter3(16비트) KyungHee Univ.

Timer/Counter (8-bit 0,2 16-bit 1,3) 기본 기능 Clear Timer on Compare Match (Auto Reload) Pulse width Modulator (PWM) Frequency Generator 10-bit Clock Prescaler Overflow and Compare Match Interrupt Sources (TOV2 and OCF2) Allows Clocking from External 32 kHz Watch Crystal Independent of the I/O Clock (Timer0) External Event Counter (Timer1,2,3) Input Capture (Timer1, 3) KyungHee Univ.

Timer/Counter0과 2는 8비트 구조로서 유사한 OVERFOLW, PWM 기능과 제어방식을 갖는다. Counter : 8비트(0x00 ~ 0xff) Prescaler : 10비트, 8종류 Clock 주기 선택 가능 Interrupt : Overflow, Output Compare Match Timer/Counter0, 2의 Clock 입력 Clock의 Pre scale 기능을 사용 하여 Counter의 Clock 주기를 다양하게 선택 할 수 있다. Timer/Counter0 : 32.768kHz(2**15 = 32,768)의 크리스탈을 접속하는 TOSC1 및 TOSC2 단자를 가지고 있어서 RTC의 기능을 갖도록 할 수 있다. KyungHee Univ.

Timer/Counter0 Block Diagram 외부 Clock 내부 Clock Asn:0 내부 Clock(동기) Asn:1 외부 Clock(비 동기) KyungHee Univ.

Timer/Counter1,3 Block Diagram KyungHee Univ.

Timer/Counter0 Counter Unit Block Diagram KyungHee Univ.

Timer/Counter2 Counter Unit Block Diagram Event Input KyungHee Univ.

Timer/Counter0 Output Compare Unit, Block Diagram KyungHee Univ.

Timer/Counter0 Compare Match Output Unit KyungHee Univ.

TCCR0 - Timer/Counter Control Register 동작모드설정/분주비 설정 Bit 7 : FOC0(Force Output Compare) Non-PWM mode 에서만 동작 이 Bit에 1을 Write 하면 OC0 단자에 TCNT0 와 OCR0 Rg 가 Compare Match 가 발생 한 것과 같은 신호를 출력 한다. 새로운 Compare Match 가 발생 하면 OC0단자는 Update 된다. Bit 3,6 : WGM01,WGM00(Waveform Generation Mode) Bit 5,4 : COM01, COM00(Compare Match Output Mode) Bit 2,1,0 : CS02~CS00(Clock Select) KyungHee Univ.

Waveform Generation Mode Bit Description CTC: Clear Timer on Compare Match Compare Output Mode, non-PWM Mode KyungHee Univ.

Timer/Counter 0의 Operation Mode Normal Mode Overflow Interrupt 가 필요한 경우 사용 항상 Up Counter로 동작 0x00~0xff 범위를 반복 하여 Counting 한다. Count 도중 Clear 없음 MAX = 0xff 일 때 Overflow Interrupt 이 발생 Out Compare (COMP) Interrupt는 이 Mode에서 추천 하지 않음 KyungHee Univ.

Timer/Counter 0의 Operation Mode CTC Mode(Clear Timer on Compare Match Mode) 일정한 주기 또는 주파수 발생 Up Counter 0x00~OCR0 구간을 반복 Counting OCR0값과 TCNT0값이 같으면 카운트 도중 Clear TCNT0 = OCR0 일 때 Output Compare Match Interrupt 발생 오버프로우(OVF) 인터럽트 (MAX=OCR0값일 때 발생, COMP인터럽트와 동일하게 작동되기 때문에 추천하지 않음) KyungHee Univ.

Timer/Counter 0의 Operation Mode CTC Mode, Timing Diagram KyungHee Univ.

Compare Output Mode, Fast PWM Mode Compare Output Mode, Phase Correct PWM Mode KyungHee Univ.

Timer/Counter 0의 Operation Mode FAST PWM 높은 주파수의 PWM 파형발생이 필요할 때 사용 상향카운터 (Single-Slope Operation) 0x00~0xFF 계수 동작 반복 TCNT0과 OCR0의 Compare Match되면 OC0에 LOW출력(COM0 1:0 = 2) 0xFF → 0x00 : Overflow 발생 시 OC0에 HIGH출력(COM 1:0 = 2) KyungHee Univ.

Timer/Counter 0의 Operation Mode Fast PWM Mode, Timing Diagram KyungHee Univ.

Timer/Counter 0의 Operation Mode Phase Correct PWM 높은 분해능의 PWM출력 파형을 발생하는데 사용 상향카운터 0x00 → 0xFF 하향카운터 0xFF → 0x00 0x00 ~ 0xFF ~ 0x00 계수 동작 반복 상향카운터 Compare Match >> OC0 = 0출력(COM1:0=2) 하향카운터 Compare Match >> OC0 = 1출력(COM1:0=2) KyungHee Univ.

Timer/Counter 0의 Operation Mode Phase Correct PWM Mode, Timing Diagram KyungHee Univ.

Clock Select Bit Description KyungHee Univ.

Prescaler for Timer/Counter0 KyungHee Univ.

TCNT0 - Timer/Counter Register Timer/Counter 0의 8비트 Count 값을 저장하고 있는 Register OCR0 - Output Compare Register Timer/Counter 0의 8비트 Counter TCNT0과 비교하여 OC0 단자에 출력신호를 발생하기 위한 8비트 값을 저장하고 있는 Register KyungHee Univ.

ASSR - Asynchronous Status Register Bit 3 – AS0: Asynchronous Timer/Counter0 AS0 = 0 : 내부클럭 (clkI/O) 동기모드 AS0 = 1 : 외부클럭 (TOSC1) 비 동기모드 Bit 2 – TCN0UB: Timer/Counter0 Update Busy Bit 1 – OCR0UB: Output Compare Register0 Update Busy Bit 0 – TCR0UB: Timer/Counter Control Register0 Update Busy KyungHee Univ.

TIMSK - Timer/Counter Interrupt Mask Register Bit 1 – OCIE0: Timer/Counter0 Output Compare Match Interrupt Enable OCIE0를 Set시키면 Output Compare Match Interrupt가 활성화 된다. Bit 0 – TOIE0: Timer/Counter0 Overflow Interrupt Enable TOIE0를 Set시키면 Overflow Interrupt가 활성화된다. 인터럽트를 사용하려면 SREG의 I Bit 가 1인 상태여야 한다. KyungHee Univ.

TIFR - Timer/Counter Interrupt Flag Register Bit 1 – OCF0: Output Compare Flag 0 TCNT0값과 OCR0값을 비교하여 이것이 같으면 이 비트가 1로 Set되면서, Output Compare Interrupt가 요청된다. 이 비트는 인터럽트 처리의 시작과 함께 0으로 Clear된다. Bit 0 – TOV0: Timer/Counter0 Overflow Flag 타이머/카운트에서 Overflow가 발생되면 이 비트가 1로 Set되면서 Output Compare Interrupt가 요청된다. 이 비트는 인터럽트 처리의 시작과 함께 0으로 Clear된다. 위 Bits의 위치에 0를 Write 하면 해당 Flag 가 Clear 된다. KyungHee Univ.

SFIOR - Special Function IO Register Bit 7 – TSM: Timer/Counter Synchronization Mode 이 Bit 에 1 이 Writing 되면 Timer/Counter는 Synchronization 설정 Mode 가 된다. 이 Mode가 설정 되면 PSR0, PSR321(Prescaler Reset ) 상태가 유지 된다. 이 상태에서 대응하는 Timer/Counter는 멈추어서 안전하게 새로운 설정을 할 수 있게 된다. 이 Bit에 0가 Write 되면 PSR0, PSR321가 Hardware에 의하여 Clear 되고 Timer/Counter는 Counting을 시작 하게 된다. Bit 1 – PSR0: Prescaler Reset Timer/Counter0 이 Bit 에 1이 Writing 되면 Timer/Counter Prescaler 가 Reset 된다. 그리고 이 Bit는 Hardware에 의하여 Clear 된다. (TSM Bit가 Set 된 경우에는 Clear 되지 않는다.) KyungHee Univ.

Timer 응용 프로그램 예 cho_timer1_int_clock_gen cho_key_debounce_timer1 cho_keypad_basic_soft_timer2_delay cho_input_capture_pulse_width_measure cho_led_PWM_bright_control KyungHee Univ.