AVR timer/counter
-
Upload
mincai-jin -
Category
Documents
-
view
112 -
download
11
description
Transcript of AVR timer/counter
![Page 1: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/1.jpg)
AVR STUDY 2주차
타이머 카운터 인터럽트
![Page 2: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/2.jpg)
INTERRUPT란?
★ CPU 외부/내부의 하드웨어적인 요구에 의해서 프로그램의 실행 순서를 변경하여 보다 시급한 작업을 먼저 수행한 후에 다시 원래의 위치로 복귀하는 작업 ★ ISR = Interrupt Service Routine
![Page 3: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/3.jpg)
왜 인터럽트를 사용하는가?
★ 1초마다 숫자 증가 필요
![Page 4: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/4.jpg)
왜 인터럽트를 사용하는가?
★ 저번 시간에 사용했던 방법은 delay
![Page 5: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/5.jpg)
왜 인터럽트를 사용하는가?
![Page 6: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/6.jpg)
ATMEGA128의 인터럽트
★ 총 4개의 인터럽트 ★ 8비트 타이머/카운터 0,2 0x00 ~ 0xFF ★ 8비트 관련 레지스터 TCNT, TCCR, OCR, ASSR, TIMSK, TIFR, SFIOR ★ 16비트 타이머/카운터 1,3 0x0000 ~ 0xFFFF ★ 16비트 관련 레지스터 TCNT, TCCRnA, TCCRnB, TCCRnC, OCRnA~OCRnC, ICR, TIMSK, ETIMSK, TIFR, ETIFR, SFIOR ★ 인터럽트의 다양한 모드 일반모드, CTC 모드, Fast PWM MODE. PC PWM MOCE
![Page 7: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/7.jpg)
8비트 타이머/카운터0 일반모드
★ 알아야 할 함수 cli() sei() ISR(TIMER0_OVF_vect) ★ 알아야 할 레지스터 TCCR0 TCNT0 TIMSK
![Page 8: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/8.jpg)
cli() & sei() & ISR(TIMER0_OVF_vect)
★ cli() = CLear Interrupt flag 모든 인터럽트를 비활성화시키는 함수 ★ sei() = SEt Interrupt mask. 설정된 인터럽트들을 모두 활성화시키는 함수 ★ ISR(TIMER0_OVF_vect) WinAVR 레퍼런스의 avr/interrupt.h
![Page 9: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/9.jpg)
TCCR0
★ Timer/Counter0 Control Register
★ FOC0 = 0 // 사용 안 하는 bit
![Page 10: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/10.jpg)
TCCR0
![Page 11: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/11.jpg)
TCCR0
★ 타이머/카운터0 분주비(prescaler) ★ TCCR0=0x05 //0000101 CLKtos/128 (from prescaler)
![Page 12: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/12.jpg)
TCNT0
★ Timer/Counter Register
★ Count되는 수치가 저장되는 레지스터
![Page 13: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/13.jpg)
TIMSK
★ Timer/Counter Interrupt Mask Register
★ 출력비교 인터럽트, 오버플로우 인터럽트 등을 결정 ★ TIMSK=0x01;
![Page 14: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/14.jpg)
TCCR0 & TCNT0 & TIMSK
![Page 15: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/15.jpg)
예제
8비트 타이머로는 1초 불가능 16비트 타이머에서 가능
![Page 16: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/16.jpg)
CODE
![Page 17: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/17.jpg)
예제 (1/2)
![Page 18: AVR timer/counter](https://reader035.fdocument.pub/reader035/viewer/2022081716/552ef1ca5503466f768b4aee/html5/thumbnails/18.jpg)
예제 (2/2)