336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

http://www.atmel.com/images/atmel-2486-8-bit-avr-microcontroller-atmega8_l_datasheet.pdf


.

.

.

96쪽  (PWM관련)

ATmega128은 TCCR1A, TCCR1B, TCCR1C 의 3개의 채널을 갖고있는 반면

ATmega8은 TCCR1A, TCCR1B 의 2개의 채널을 갖고있다.

ATmega128에서의 TCCR1A Register Bit configuration

TCCR1A = (1<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)|(0<<COM1C1)|(0<<COM1C0)|(1<<WGM11)|(0<<WGM10);

COM1C1, COM1C0 비트가 있다.

반면...

ATmega8에서의 TCCR1A Register는 COM1C1, COM1C0 비트 없이 구성되어있다.


The FOC1A/FOC1B bits are only active 

when the WGM13:0 bits specifies a non-PWM mode. 

However, for ensuring compatibility with future devices, 

these bits must be set to zero when TCCR1A is written when operating in a PWM mode. 

When writing a logical one to the FOC1A/FOC1B bit, 

an immediate Compare Match is forced on the waveform generation unit. 

The OC1A/OC1B output is changed according to its COM1x1:0 bits setting. 

Note that the FOC1A/FOC1B bits are implemented as strobes. 

Therefore it is the value present in the COM1x1:0 bits that determine the effect of the forced compare.

Posted by ElectricShock
:
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

▼버튼기반 Servo 제어

http://winavr.scienceprog.com/example-avr-projects/servo-motor-control-using-avr.html


//Program code written for WinAVR toolset:

//-------------------------

#include <avr\io.h>

int main(void) 

{

DDRD=0x00;            //Input으로 지정    //Port D pins as input

//Enable internal pull ups

PORTD=0xFF;            //High값을 Default로 지정 (풀업저항을 Vcc에 연결)

DDRB=0xFF;            //Output으로 지정  //Set PORTB1 pin as output

//TOP=ICR1;

//Output compare OC1A 8 bit non inverted PWM

//Clear OC1A on Compare Match, set OC1A at TOP

//Fast PWM

//ICR1=20000 defines 50Hz PWM    //Hz 그림설명 링크

//50Hz = 1/50sec = 2/100sec = 0.02sec = 20msec = 20000usec


ICR1=20000;        //Input Capture Register

//2000*8 = 160000 clocks

TCCR1A|=(0<<COM1A0)|(1<<COM1A1)|(0<<COM1B0)|(0<<COM1B1)|

(0<<FOC1A)|(0<<FOC1B)|(1<<WGM11)|(0<<WGM10);

//https://gist.github.com/mkleemann/1552059

//set Fast PWM mode with ICR1 as compare rigister

//WGM11을 1로 Set

TCCR1B|=(0<<ICNC1)|(0<<ICES1)|(1<<WGM13)|(1<<WGM12)|

(0<<CS12)|(1<<CS11)|(0<<CS10);

//set Fast PWM mode with ICR1 as compare rigister

//WGM13, WGM12를 1로 set

//


//start timer with prescaler 8

for (;;) 

{

if(bit_is_clear(PIND, 0))

{

//increase duty cycle

OCR1A+=10;

loop_until_bit_is_set(PIND, 0);

}


if(bit_is_clear(PIND, 1)) 

{

//decease duty cycle

OCR1A-=10;

loop_until_bit_is_set(PIND, 1);

}

}

}

//----------------------------------


http://extremeelectronics.co.in/avr-tutorials/servo-motor-control-by-using-avr-atmega32-microcontroller/

▲ATmega16용


▼UART기반 Servo 제어

http://miobot.tistory.com/34

#include<stdio.h>

#include<avr/io.h>

#include<avr/interrupt.h>


#define PERIOD 1729

#define MAX 198

#define MIN 60

#define CENTER 129


volatile unsigned int p_width = 0;

volatile unsigned int duty = CENTER;


ISR(TIMER0_OVF_vect)

{

TCNT0 = 0x60;            //8-bit comparator continuously compares TCNT0 and OCR0.

p_width++;

if(p_width <= duty)

PORTA |= 0x01;

else

PORTA &= ~(0x01);

if(p_width >= PERIOD)

p_width = 0;

}


void init_timer0(void)

{

TCCR0 = 0x00;    //Stop

ASSR = 0x00;    //set async mode

TCNT0 = 0x60;    //set count start from 96 to 255+1

TCCR0 = 0x01;

TCNT0 = 0xFE;

}


static int putch_uart1(char message, FILE *stream)    //4 using printf()

{

if(message == '\n')

putch_uart1('\r', stream);

while((UCSR1A & 0x20) == 0x00);

UDR1 = message;

return 0;

}


int getch_u1(void)

{

while ((UCSR1A & 0x80) == 0);

return UDR1;

}


void init_port(void)

{

PORTA = 0x00; DDRA = 0x00;

PORTB = 0x00; DDRB = 0x00;

PORTC = 0x00; DDRC = 0x00;

PORTD = 0x00; DDRD = 0x00;

PORTE = 0x00; DDRE = 0x00;

PORTF = 0x00; DDRF = 0x00;

PORTG = 0x00; DDRG = 0x00;

}


void init_uart1(void)

{

UCSR1B = 0x00;

UCSR1A = 0x00;

UCSR1B = 0x06;

UBRR1L = 0x67;

UBRR1H = 0x00;

UCSR1B = 0x18;

}


void init_devices(void)

{

cli();

init_port();

init_uart1();

init_timer0();

fdevopen(putch_uart1,0);

TIMSK = 0x01;

sei();

}


int main(void)

{

unsigned int duty_ctrl = CENTER;    //90 degree

char ch;

init_devices();

DDRA = 0xFF;    //PortA Output

printf("\n Servo Motor test... \n");

printf("type '<' or '>' to control servo \n");

while(1)

{

ch = getch_ul();

if((ch == '.') || (ch == '>')) duty_ctrl++;

if((ch == ',') || (ch == '>')) duty_ctrl--;

if(duty_ctrl >= MAX) duty_ctrl = MAX;

if(duty_ctrl <= MIN) duty_ctr = MIN;

duty = duty_ctrl;

printf("duty : %3d\n", duty_ctrl);

}

}


▼PWM 제어 기초자료 (Servo 제어에 필수)

http://instructables.tistory.com/474


'AVR > AVR Servo' 카테고리의 다른 글

AVR Servo(다이나믹셀)  (0) 2016.07.27
Posted by ElectricShock
:
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.


Naver

[다른계시판에 내블로그 링크걸기]




YouTube 카드섹션을 내 블로그로 링크걸기

▲관리자 계정으로 들어가면 위 그림의 하단과 같은 !표시가 되있는 카드섹션 버튼을 볼 수 있다.


▲카드추가를 누르면 외부URL(=블로그 등등)의 링크를 만들 수 있다.

넘어가 보자.



★외부링크를 이용하여 트래픽을 늘리면 정책위반이 될수 있으므로 주의해야한다.




▲아직은 링크를 바로 만들수 없는 단계이다.

링크 URL에 그냥 붙여넣기를 하면 불가능하다는 메세지를 보게될 것이다.

아래의 설정 버튼을 클릭해보자.


▲빨간 네모를 표시한곳에 원하는 URL 링크를 적고 추가버튼을 누르면 된다.


▼승인 보류중임을 확인할 수 있다.

이 단계를 넘어가면 개인 블로그를 카드섹션을 통해서 홍보할 수 있다.


▲위 인증 버튼을 클릭하면 ▼아래 화면으로 이동한다.

정리중에 오타가 있는데

http://instructables.tistory.com 까지만 적고 인증을 해야한다.


▼권장 방법으로 했는데 쉽지않다.

대체방법 탭을 누르길 권한다.


▼생성된 Meta Code를 그대로 Copy해서 갖고온다.


▼생성된 메타코드를

관리자(=Admin)

HTML/CSS 편집 으로 들어와서 

<head> ... </head> 사이에 복사한다.

앞으로의 수정을 위해서 <!-- ??? --> 를 이용하여 주석처리를 해둔다. 


위 위 그림의 하단에 있는 빨간색의 확인 버튼을 클릭하면

아래와 같은 성공 메세지를 볼수 있다.



instructables.tistory.com/64의 링크를 카드섹션으로 걸려고 했지만 한번에 되지 않는다.

instructables.tistory.com을 먼저 링크를 걸고

취소후

다시 instructables.tistory.com/64로 수정하여 세부 링크를 설정해주면 된다.

천천히 하는게 포인트다.





Google Web Master >> MetaTag >> 인증성공




타 유튜버 채널 앤딩에 넣기


YouTube에서 프로필클릭 >> Studio

왼쪽패널의 동영상을 클릭 >> 해당영상의 세부정보 클릭



Posted by ElectricShock
:

BLOG main image
잡동사니들(지극히 개인취향인...) (다른글에도 댓글 부탁해요♥) You May Leave English Messages on GuestBook. by ElectricShock

공지사항

카테고리

분류 전체보기 (782)
MiDi (2)
Programming(=프로그래밍) (3)
Animation (4)
Blender (3D Graphic Program.. (10)
Blendtuts.com (Series) (1)
Blender 기초 팁들 (2)
Processing (디지털미디어과) (2)
Music (1)
Books in the world (0)
Communication(CAN, UART, et.. (12)
MCU Examples (PIC 기반) (7)
Transistor (1)
Mikro C Pro (11)
Mikro Pascal (1)
Proton IDE (0)
Robot (0)
Swift 3D (1)
Dummies Series (1)
All about Hacking (0)
제2 외국어 (1)
PIC 해외서적들 (3)
AVR (25)
PIC (MikroC) (MPLAB) (4)
Assembly (2)
ARM (3)
Arduino (26)
PSpice (1)
Proteus ISIS (14)
CodeVision (2)
FPGA (15)
MPLAB (24)
PCB (the Procedure) (15)
3D Printer (5)
PICKIT3 (6)
Matlab (11)
RaspBerry PI (15)
BeagleBone (1)
Android Studio (17)
졸업작품 (172)
Korea History (0)
Issue(사회) (73)
Multimeter 리뷰 (1)
Oscilloscope (1)
A (34)
B (19)
J (6)
C (32)
P (12)
T (37)
H (12)
I (12)
M (44)
R (5)
E (5)
F (2)
D (9)
O (2)
L (7)
S (9)
W (2)
V (6)
G (14)
Visual C++ or Visual Studio (2)
Android App Development (0)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백