Modes of Operation

Normal Mode
The simplest mode of operation is the normal mode (WGM01:0 = 0). In this mode the counting direction is always up (incrementing), and no counter clear is performed. The counter simply overruns when it passes its maximum 8-bit value (TOP = 0xFF) and then restarts from the bottom (0x00). In normal operation the Timer/Counter overflow flag (TOV0) will be set in the same timer clock cycle as the TCNT0 becomes zero. The TOV0 flag in this case behaves like a ninth bit, except that it is only set, not cleared. However, combined with the timer overflow interrupt that automatically clears the TOV0 flag, the timer resolution can be increased by software. There are no special cases to consider in the normal mode, a new counter value can be written anytime.
The output compare unit can be used to generate interrupts at some given time. Using the output compare to generate waveforms in normal mode is not recommended, since this will occupy too much of the CPU time.
가장 단순한 작동은 노말모드 입니다 (WGM01:0 =0). 이 모드에서는 카운팅 방향은 항상 위쪽이며(증가), 카운터 클리어가 수행되지 않습니다. 카운터는 8bit 최대값을 넘어설때 (0xFF) 단순히 초과해 버리며 바닥(0x00) 부터 재시작 합니다. 


Clear Timer on Compare Match (CTC) Mode
In Clear Timer on Compare or CTC mode (WGM01:0 = 2), the OCR0 Register is used to manipulate the counter resolution. In CTC mode the counter is cleared to zero when the counter value(TCNT0) matches the OCR0. The OCR0 defines the top value for the counter, hence also its resolution. This mode allows greater control of the compare match output frequency. It also simplifies the operation of counting external events. The timing diagram for the CTC mode is shown in Figure 38. The counter value (TCNT0) increases until a compare match occurs between TCNT0 and OCR0, and then counter (TCNT0) is cleared. 
CTC 모드에서 OCR0 레지스터는 카운터 해상도를 조작하는데 사용됩니다. CTC 모드에서 카운터는 카운터 값(TCNT0)가 OCR0와 일치할때 0으로 초기화 됩니다. OCR0는 상한값과 해상도를 정의합니다. 이 모드는 compare match 출력 주파수의 더 나은 제어를 제공합니다. 그것은 또한 외부 이벤트의 카운팅 작업을 단순화 시킵니다. CTC 모드를 위한 타이밍 다이너그램은 Figure 38에 있습니다. 카운터 값(TCNT0)는 TCNT0와 OCR0 값이 일치하는 순간때까지 증가하며 카운터는(TCNT0) 초기화 됩니다.


Fast PWM Mode
The fast Pulse Width Modulation or fast PWM mode (WGM01:0 = 3) provides a high frequency PWM waveform generation option. The fast PWM differs from the other PWM option by its single-slope operation. The counter counts from BOTTOM to MAX then restarts from BOTTOM. In non-inverting Compare Output mode, the output compare (OC0) is cleared on the compare match between TCNT0 and OCR0, and set at BOTTOM. In inverting Compare Output mode, the output is set on compare match and cleared at BOTTOM. Due to the single-slope operation, the operating frequency of the fast PWM mode can be twice as high as the phase correct PWM mode that uses dual-slope operation. This high frequency makes the fast PWM mode well suited for power regulation, rectification, and DAC applications. High frequency allows physically small sized external components (coils, capacitors), and therefore reduces total system cost. In fast PWM mode, the counter is incremented until the counter value matches the MAX value. The counter is then cleared at the following timer clock cycle. The timing diagram for the fast PWM mode is shown in Figure 39. The TCNT0 value is in the timing diagram shown as a histogram for illustrating the single-slope operation. The diagram includes non-inverted and inverted PWM outputs. The small horizontal line marks on the TCNT0 slopes represent compare matches between OCR0 and TCNT0.
빠른 PWM 모드는 고주파 PWM 파형을 생성하는 옵션을 제공합니다. 빠른 PWM은 다른 PWM 옵션들에 비해 single-slope 작동으로 인해 차이점이 존재합니다. 카운터는 바닥에서 최대값으로 세고 바닥에서 다시 시작합니다(0 -> 0xFF / 증가).
non-inverting 비교 출력 모드에서는 출력비교(OC0)는 TCNT0와 OCR0가 일치할때 초기화 되고, 바닥(0x00)에서 설정됩니다.
inverting 비교 출력 모드에서는 일치할때 설정되고 바닥에서 초기화 됩니다. single-slope 작동으로 인해 빠른 PWM 모드의 작동 주파수는 dual-slope 작동을 사용하는 phase correct PWM의 2배 이상을 낼 수 있습니다. 이러한 높은 주파수로 인해 fast PWM 모드는 전력제어, 정류 그리고 DAC 어플리케이션에 매우 적절합니다. 고주파는 물리적으로 작은 크기의 외부 부품(코일, 캐패시터)를 사용할수 있도록 해주고, 전체 시스템의 비용을 낮출수 있습니다. 빠른 PWM 모드에서 카운터는 카운터 값이 최대값과 일치할때 까지 증가합니다. 카운터는 따라오는 타이머 클럭 사이클에 초기화 됩니다. 



Phase Correct PWM Mode
The phase correct PWM mode (WGM01:0 = 1) provides a high resolution phase correct PWM waveform generation option. The phase correct PWM mode is based on a dual-slope operation. The counter counts repeatedly from BOTTOM to MAX and then from MAX to BOTTOM. In non-inverting Compare Output mode, the output compare (OC0) is cleared on the compare match between TCNT0 and OCR0 while counting up, and set on the compare match while downcounting. In inverting Output Compare mode, the operation is inverted. The dual-slope operation has lower maximum operation frequency than single slope operation. However, due to the symmetric feature of the dual-slope PWM modes, these modes are preferred for motor control applications. 
phase correct PWM 모드는 고해상도의 
phase correct PWM 파형을 생성하는 옵션을 제공합니다. phase correct PWM 는 dual-slope 작동에 기반합니다. 카운터는 바닥과 최대값으로 그리고 최대에서 바닥으로 반복적으로 세어지게 됩니다. non-inverting비교 출력 모드에서는 출력 바교(OC0)는 숫자가 세어 올라가는(증가) 중 TCNT0와 OCR0이 일치하는 순간에 초기화 되고, 아래로 세어지는 도중(감소) 비교가 일치할 경우 설정됩니다. inverting  출력 비교 모드에서는 작동이 반대로 됩니다. dual-slope 작동은 single slope 작동보다 낮은 작동 주파수를 가집니다. 하지만 dual-slope PWM 모드의 대칭 특성으로 인해 모터 제어에 적합합니다.
Posted by 구차니
일단 싸긴한데 내용을 보면 이게 임베디드랑 무슨연관인가 싶은 내용만 잔뜩
그냥 소프트웨어 공학 기사 같은 기분이야 -_-

 시험 수수료
- 필기 : 18800
- 실기 : 21900

[링크 : http://www.q-net.or.kr/crf005.do?id=crf00503&jmCd=1121]
Posted by 구차니
개소리 왈왈2014. 1. 1. 00:15
2014년 한해도 좋은일만 가득하시길 기원합니다!!
Posted by 구차니
수영장 등록하고 수영복도 사러갈겸 가는데
흰색 뭉뭉이가 목끈도 없이 비글을 따라가길래
아직 새끼라서 안 묶었나 싶었는데 방향이 달라서 그냥 지나쳤다.

그런데 돌아오는길에 사거리에서 차가 우회전하려다 못하고 있고
사람들이 우르르 몰려있길래 가봤더니
경찰에 흰색 뭉뭉이!

아까 비글 주인이 흰색 뭉뭉이가 쫄아서 우회전 하려는 차 아래로 기어들어 가는걸 끄집어 내고
그걸 유기견 보호센터로 보내야 하나 고민하고 있었는데
의외로 애가 덩치가 있는 견종이다 보니 누구도 선듯 잡지 못하고 있었고
비글 주인은 비글로 이미 체력이 바닥 ㅋㅋㅋ


비글은 비글비글해요 ㅋㅋ


헥헥헥 와 신기해~ 라는 눈빛 ㅋㅋ


얌마 얌마 왜 서울 나들이 왔어?
힝 주인님 보고 싶... 아니 날씨도 따스하니까~ 바깥 나들이 하고 싶었다구요 ㅠㅠ


... 이 머 개같은 자세가 ㅋㅋㅋ


아무튼 사거리에서 어떻게 하냐로 고민하고 있는 사이에
자전거 타고 지나가던 1인이 자기가 주인이라고 하고
엄마를 불러서 데려는 갔지만..

주인이라는 사람도 한 25정도 되었으려나?
서하남에서 사는데 헬스하러 온 동안 따라온거 같다고 하지만
목끈도 없고 이녀석 얌전하게 있긴 하지만 다른데로 가려고 하니
주인이 꼬리를 확 잡아 당긴다.. 어? 주인 맞...나? 조금 의심이 가고

부모님이 SUV 끌고 왔는데
트렁크에 실어버리고... 어? 주인..은 주인인데.... 개장수 아냐? 라는 의심이 가기도 하고..
아무튼.. 주인은 자전거를 끌고와서 라고는 하지만
차에 실으러 가고 실을 때 까지도
저 뭉뭉이를 만진건 한사람도 없다는거..

정말 저 뭉뭉이 주인 맞을...까? 라는 불안감에 아직도 남아 있는 하루.. 

'개소리 왈왈 > 사진과 수다' 카테고리의 다른 글

뭘 보냐 닝겐  (2) 2014.03.19
여호와의 증인교가 업그레이드!  (2) 2014.01.05
광화문-서울시청  (0) 2013.12.28
여의도 불꽃축제 2013  (0) 2013.10.05
가을 하늘  (0) 2013.10.05
Posted by 구차니
개소리 왈왈2013. 12. 31. 17:19
효과가 대단했다!!



무슨효과?

지갑이 반토막 나는 효과!!!




으헝헝
수경이랑 뚜껑이랑 팬티랑(!) 지른다음
강습료 내니 빈털털이

+ 2004년도 겨울에 대학 방학당시 수영을 배웠는데 어느덧.. 10년 ㄷㄷ 
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 31. 08:40
역시 눈에 들어 오는게 최고지 ㅋㅋ
ATmega128에는 총 4개
Atmega8에는 총 3개의 timer/counter가 존재한다.

UI상으로는 Timer1/3이 16bit로 사용가능하며
TCNT1/TCNT3은
TCNT1H / TCNT1L 이런식으로 16bit 로 확장되어 있으나
TCNT1이 TCNT1L과 동일 메모리 주소로 설정되어 8bit/16bit로 사용이 가능해진다.
(Atmega8은 Timer3가 없으며 Timer1이 유일한 16bit 타이머이다)





문제는... Timer는 우선순위가 높아야 하는데 Timer3는 UART0 보다 우선순위가 낮으므로
Timer1 번을 이용해서 16bit Timer를 사용하는게 가장 무난한 선택으로 생각된다. (Timer0 8bit를 포기!)

 
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 30. 23:47
메모리나 플래시 용량이 크지 않은 micom 특성상 용량을 줄이기 위해서 발악을 해야하는데
사소한 팁이라고 해야하려나... 

inline void init_timer(void)
{
TCCR0 = 0x04;     // Prescaler 설정
TCNT0 = OVERFLOW - (F_CPU / TICKS_PER_SEC / Prescaler);// 오버플로우에 사용될 초기값
TIMSK = 0x01;     // 오버플로우 인터럽트 허용
}

int main(void)
{
int idx = 0;
int val = 1500;

DDRB = 0xFF;
PORTB = 0x00;

init_timer();
while(1)
{
;
}

return 0;
}

inline 사용시
AVR Memory Usage
----------------
Device: atmega8

Program:     146 bytes (1.8% Full)
(.text + .data + .bootloader)

Data:          2 bytes (0.2% Full)
(.data + .bss + .noinit)
 

inline 사용시
AVR Memory Usage
----------------
Device: atmega8

Program:     160 bytes (2.0% Full)
(.text + .data + .bootloader)

Data:          2 bytes (0.2% Full)
(.data + .bss + .noinit)

정말 사소한 용량 차이이지만 하나하나 쌓이면 은근 커지기에..
나중에 switch 테스트 예정 
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 30. 19:40
아래와 같이 EEMEM 이라는 접두를 이용해서 선언하면 되는데
avr/eeprom.h를 포함해야 한다.
#include <avr/eeprom.h>
EEMEM char test[128]; 

만약 include 하지 않으면 아래와 같은 에러가 발생한다.
 ../servo.c:29: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'char' 

컴파일 성공시에는 아래와 같이 메시지가 나타나는데
EEPROM 이라는게 추가 되어 나타난다. 
AVR Memory Usage
----------------
Device: atmega8

Program:     392 bytes (4.8% Full)
(.text + .data + .bootloader)

Data:          2 bytes (0.2% Full)
(.data + .bss + .noinit)

EEPROM:      128 bytes (25.0% Full)
(.eeprom) 

[링크 : http://www.nongnu.org/avr-libc/user-manual/group__avr__eeprom.html]
2012/01/03 - [embeded/ATmega/ATtiny (AVR)] - AVR EEPROM / CODE section 관련

Posted by 구차니
embeded/AVR (ATmega,ATtiny)2013. 12. 30. 17:26
1500us 센터 +-800usec 총 1600usec/180degree
아무래도 타이머를 이용한다고 하여도 16MHz 쓰는 이상
1usec 이상의 해상도는 무리라고 판단된다.

1600usec/180도 = 8usec/1도 
1usec = 0.125도

아무튼.. 계산을 해보니
정수형에 의한 오차가 발생할 수 밖에 없지만
0.1도를 한계(angle resolution)로 주고 0.05도 반올림 하여 사용하는게 전반적인 오차가 적을 것으로 생각된다.

 
Posted by 구차니
스팀은 126개


오리진은 26개


'게임 > 오리진&스팀&유플레이' 카테고리의 다른 글

몰라 걍 질러  (0) 2014.03.10
간만에 지름!! 험블번들 X  (1) 2014.01.16
스팀 연말 할인 시작!!  (0) 2013.12.22
리눅스 스팀 설치!  (0) 2013.12.17
험블번들 점보 번들 언락!  (0) 2013.12.11
Posted by 구차니