728x90
반응형
SMALL
# 타이머0 오버플로우 인터럽트 1msec
# X-TAL클럭 / TCCR0분주비 / TCNT0타이머값 = 주파수, 역수를 취하면 시간
# 16000000Hz/128/125=1000Hz, (256-125)=131
TCCR0=5; TCNT0=131; TIMSK=1;
# 타이머0 오버플로우 인터럽트 5msec
# 16000000Hz/1024/78=200.32Hz, (256-78)=178
TCCR0=7; TCNT0=178; TIMSK=1;
# 타이머0 오버플로우 인터럽트 10msec
# 16000000Hz/1024/156=100.16Hz, (256-156)=100
TCCR0=7; TCNT0=100; TIMSK=1;
1msec는 분주비 128을 사용해서 정확한 1msec를 만들었지만 8비트 타이머로는 더 긴 시간을 만들 수 없으므로 오차가 있더라도 1024를 사용한다. 8비트 타이머0로 만들 수 있는 시간 범위는 10msec까지이며 더 긴 50msec와 100msec는 타이머 인터럽트 함수 내에서 사용자 변수로 처리하면 된다.
타이머0 오버플로우 인터럽트
TCCR0=3; TCNT0=156; TIMSK=1; //16000000/ 32/100=5000Hz=200us,(256-100)=156
TCCR0=4; TCNT0=6; TIMSK=1; //16000000/ 64/250=1000Hz=1ms, (256-250)=6
TCCR0=5; TCNT0=131; TIMSK=1; //16000000/ 128/125=1000Hz=1ms, (256-125)=131
TCCR0=5; TCNT0=6; TIMSK=1; //16000000/ 128/250= 500Hz=2ms, (256-250)=6
TCCR0=6; TCNT0=6; TIMSK=1; //16000000/ 256/250= 250Hz=4ms, (256-250)=6
TCCR0=7; TCNT0=100; TIMSK=1; //16000000/1024/156=100.16Hz=9.84ms, (256-156)=100
TCCR0=7; TCNT0=6; TIMSK=1; //16000000/1024/250=62.5Hz=16ms, (256-250)=6
타이머0 매치 인터럽트
TCCR0=0x09; OCR0= 28; TIMSK=2; //16000000/ 1/(1+159)=100000Hz=10us
TCCR0=0x0B; OCR0= 28; TIMSK=2; //16000000/ 32/(1+ 28)=17241.37931Hz=58us
TCCR0=0x0B; OCR0= 49; TIMSK=2; //16000000/ 32/(1+ 49)=10000Hz=100us
TCCR0=0x0B; OCR0= 99; TIMSK=2; //16000000/ 32/(1+ 99)= 5000Hz=200us
TCCR0=0x0C; OCR0= 74; TIMSK=2; //16000000/ 64/(1+ 74)= 3333.3Hz=300us
TCCR0=0x0C; OCR0=124; TIMSK=2; //16000000/ 64/(1+124)= 2000Hz=500us
TCCR0=0x0C; OCR0=249; TIMSK=2; //16000000/ 64/(1+249)= 1000Hz=1ms
TCCR0=0x0D; OCR0=124; TIMSK=2; //16000000/ 128/(1+124)= 1000Hz=1ms
TCCR0=0x0D; OCR0=249; TIMSK=2; //16000000/ 128/(1+249)= 500Hz=2ms
TCCR0=0x0E; OCR0=249; TIMSK=2; //16000000/ 256/(1+249)= 250Hz=4ms
TCCR0=0x0F; OCR0= 71; TIMSK=2; //14745600/1024/(1+ 71)= 200Hz=5ms
TCCR0=0x0F; OCR0=155; TIMSK=2; //16000000/1024/(1+155)= 100.16..Hz=9.984ms
TCCR0=0x0F; OCR0=233; TIMSK=2; //16000000/1024/(1+233)= 66.773504273504273504273504273504Hz=14.976ms
TCCR0=0x0F; OCR0=249; TIMSK=2; //16000000/1024/(1+249)= 62.5Hz=16ms
타이머1 오버플로우 인터럽트
TCCR1B=1; TCNT1=49536; TIMSK=4; //16000000/ 1/16000=1000Hz=1ms, (65536-16000)=49536
TCCR1B=1; TCNT1=33536; TIMSK=4; //16000000/ 1/32000= 500Hz=2ms, (65536-32000)=33536
TCCR1B=2; TCNT1=63536; TIMSK=4; //16000000/ 8/ 2000=1000Hz=1ms, (65536- 2000)=63536
TCCR1B=2; TCNT1=61536; TIMSK=4; //16000000/ 8/ 4000= 500Hz=2ms, (65536- 4000)=61536
TCCR1B=2; TCNT1=45536; TIMSK=4; //16000000/ 8/10000= 200Hz=5ms, (65536-10000)=45536
TCCR1B=2; TCNT1=35536; TIMSK=4; //16000000/ 8/20000= 100Hz=10ms, (65536-20000)=35536
TCCR1B=3; TCNT1=65286; TIMSK=4; //16000000/ 64/ 250=1000Hz=1ms, (65536- 250)=65286
TCCR1B=4; TCNT1=59286; TIMSK=4; //16000000/256/ 6250= 10Hz=100ms,(65536- 6250)=59286
TCCR1B=4; TCNT1=34286; TIMSK=4; //16000000/256/31250= 2Hz=500ms,(65536-31250)=34286
TCCR1B=4; TCNT1= 3036; TIMSK=4; //16000000/256/62500= 1Hz=1sec, (65536-62500)= 3036
타이머1 A매치 인터럽트
TCCR1B=0x09; OCR1A= 1474; TIMSK=0x10; //14745600/ 1/(1+ 1474)=9997.01695Hz=100.02984us
TCCR1B=0x09; OCR1A= 14745;TIMSK=0x10; //14745600/ 1/(1+14745)=999.973Hz=1.0000271267361ms
TCCR1B=0x09; OCR1A= 1599; TIMSK=0x10; //16000000/ 1/(1+ 1599)=10KHz=100us
TCCR1B=0x09;OCR1A= 3999; TIMSK=0x10; //16000000/ 1/(1+ 3999)= 4KHz=250us
TCCR1B=0x09; OCR1A=15999; TIMSK=0x10; //16000000/ 1/(1+15999)=1000Hz=1ms
TCCR1B=0x09; OCR1A=31999; TIMSK=0x10; //16000000/ 1/(1+31999)= 500Hz=2ms
TCCR1B=0x0A; OCR1A= 1999; TIMSK=0x10; //16000000/ 8/(1+ 1999)=1000Hz=1ms
TCCR1B=0x0A; OCR1A= 3999; TIMSK=0x10; //16000000/ 8/(1+ 3999)= 500Hz=2ms
TCCR1B=0x0A; OCR1A= 4999; TIMSK=0x10; //16000000/ 8/(1+ 4999)= 400Hz=2.5ms
TCCR1B=0x0A; OCR1A= 9999; TIMSK=0x10; //16000000/ 8/(1+ 9999)= 200Hz=5ms
TCCR1B=0x0A; OCR1A=19999; TIMSK=0x10; //16000000/ 8/(1+19999)= 100Hz=10ms
TCCR1B=0x0A; OCR1A=18431; TIMSK=0x10; //14745600/ 8/(1+18431)= 100Hz=10ms
TCCR1B=0x0A; OCR1A=39999; TIMSK=0x10; //16000000/ 8/(1+39999)= 50Hz=20ms
TCCR1B=0x0A; OCR1A=49999; TIMSK=0x10; //16000000/ 8/(1+49999)= 40Hz=25ms
TCCR1B=0x0A; OCR1A=59999; TIMSK=0x10; //16000000/ 8/(1+59999)= 33.33Hz=30ms
TCCR1B=0x0B; OCR1A= 249; TIMSK=0x10; //16000000/ 64/(1+ 249)=1000Hz=1ms
TCCR1B=0x0C; OCR1A= 3124; TIMSK=0x10; //16000000/256/(1+ 3124)= 20Hz=50ms
TCCR1B=0x0C; OCR1A= 6249; TIMSK=0x10; //16000000/256/(1+ 6249)= 10Hz=100ms
TCCR1B=0x0C; OCR1A=12499; TIMSK=0x10; //16000000/256/(1+12499)= 5Hz=200ms
TCCR1B=0x0C; OCR1A=18749; TIMSK=0x10; //16000000/256/(1+18749)=3.33Hz=300ms
TCCR1B=0x0C; OCR1A=31249; TIMSK=0x10; //16000000/256/(1+31249)= 2Hz=500ms
TCCR1B=0x0C; OCR1A=28799; TIMSK=0x10; //14745600/256/(1+28799)= 2Hz=500ms
TCCR1B=0x0C; OCR1A=62499; TIMSK=0x10; //16000000/256/(1+62499)=1Hz=1sec
TCCR1B=0x0D; OCR1A=15624; TIMSK=0x10; //16000000/1024/(1+15624)=1Hz=1sec
TCCR1B=0x0D; OCR1A=31249; TIMSK=0x10; //16000000/1024/(1+31249)=0.5Hz=2sec
TCCR1B=0x0D; OCR1A=62499; TIMSK=0x10; //16000000/1024/(1+62499)=0.25Hz=4sec
타이머2 매치 인터럽트
TCCR2=0x0B; OCR2= 24; TIMSK=0x80; //16000000/64/(1+ 24)=10000Hz=100us
TCCR2=0x0B; OCR2=249; TIMSK=0x80; //16000000/64/(1+249)=1000Hz=1ms
타이머3 A매치 인터럽트
TCCR3B=0x09; OCR3AH= 1474>>8; OCR3AL= 1474&0xFF; ETIMSK=0x10; //14745600/ 1/(1+ 1474)=9997.01695Hz=100.02984us
TCCR3B=0x09; OCR3AH= 1599>>8; OCR3AL= 1599&0xFF; ETIMSK=0x10; //16000000/ 1/(1+ 1999)=10KHz=100us
TCCR3B=0x09; OCR3AH=15999>>8; OCR3AL=15999&0xFF; ETIMSK=0x10; //16000000/ 1/(1+15999)=1000Hz=1ms
TCCR3B=0x09; OCR3AH=31999>>8; OCR3AL=31999&0xFF; ETIMSK=0x10; //16000000/ 1/(1+31999)= 500Hz=2ms
TCCR3B=0x0A; OCR3AH= 1999>>8; OCR3AL= 1999&0xFF; ETIMSK=0x10; //16000000/ 8/(1+ 1999)=1000Hz=1ms
TCCR3B=0x0A; OCR3AH= 3999>>8; OCR3AL= 3999&0xFF; ETIMSK=0x10; //16000000/ 8/(1+ 3999)= 500Hz=2ms
TCCR3B=0x0A; OCR3AH= 9999>>8; OCR3AL= 9999&0xFF; ETIMSK=0x10; //16000000/ 8/(1+ 9999)= 200Hz=5ms
TCCR3B=0x0A; OCR3AH=19999>>8; OCR3AL=19999&0xFF; ETIMSK=0x10; //16000000/ 8/(1+19999)= 100Hz=10ms
TCCR3B=0x0C; OCR3AH= 6249>>8; OCR3AL= 6249&0xFF; ETIMSK=0x10; //16000000/256/(1+ 6249)= 10Hz=100ms
TCCR3B=0x0C; OCR3AH=31249>>8; OCR3AL=31249&0xFF; ETIMSK=0x10; //16000000/256/(1+31249)= 2Hz=500ms
TCCR3B=0x0C; OCR3AH=62499>>8; OCR3AL=62499&0xFF; ETIMSK=0x10; //16000000/256/(1+62499)=1Hz=1sec
TCCR3B=0x0C; OCR3AH=28799>>8; OCR3AL=28799&0xFF; ETIMSK=0x10; //14745600/1024/(1+28799)=0.5Hz=2sec
728x90
반응형
LIST
'Embedded System > AVR' 카테고리의 다른 글
[AVR] 터미널 (Terminal Window) (0) | 2022.07.19 |
---|---|
[AVR] USART 통신 (0) | 2022.07.15 |
[AVR] 스위치 (Switch) (0) | 2022.06.23 |
[AVR] 부저 (Buzzer) (0) | 2022.06.14 |
[AVR] FND (Flexible Numeric Device) (0) | 2022.06.14 |