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

질문댓글 환영합니다.  의뢰 원하시는 분은 링크 눌러주세요

Favicon of m.search.naver.com [AVR PWM]

naver[atmega 펄스발생기]






▼AVRPWM 관련자료

ATMPWM.pdf

This is a Guide to control unhacked servos


using Timer1 on the ATmega8 chip.



For those of you


using ATmega128 or different Timers,


the techniques and ideas can easily be applied to your situation.


(ATmega128 공용)




Red = Vcc


Black = GND


White = PWM Input




Servo control is done by sending a PWM signal


to the PWM input pin of the Servo.




The servo compares that signal

to the actual position of the servo

  and

  adjusts the servo accordingly.

The internal circuitry of the servo expects a constant 50Hz PWM signal

(a 50Hz signal is one that repeats every 20ms).


1/50 Hz = 20ms


The signal you are going to give the servo

is one that is high (5V) for 1-2ms

and

low (0V) for the remainer of the 20ms period.

The duration of the high signal determines the position that the servo attempts to maintain.

Note that the servo must continually receive this signal in order to maintain its position.


1.0ms = Full Left

1.5ms = Middle

2.0ms = Full Right


Assuming you are using a servo that has 90 degrees of rotation:

Full Left = 0 degrees

Middle = 45 degrees

Full Right = 90 degrees


Different servo have different ranges of rotation

so your own Full Left, Middle, and Full Right

maybe correspond to different angles.

You may also find that

in order to achieve the Full range of motion

you need to send the servo high pulses longer than 2.0ms

or

shorter than 1.0ms.

끝까지 회전하기 위해서는 펄스 폭이 2.0ms 이상 1.0ms 이하가 될 수도 있다.

Don't be affraid to experiment to find what your servo is capable of.



>>

Phase and Frequency Correct mode:


To generate a 50Hz signal with a high signal that varies between 1-2ms,

we will use the Phase and Frequency Correct mode of the Timer on your ATmega chip.


In Phase and Frequency Correct mode

the timer starts at zero,

 counts up to a user defined value

called ICRn

(n is the timer number. In our example, we will use Timer1 and thus ICR1),

and then counts back down to zero.

We want the counting up and down process

to take 20ms

in order to generate the 50Hz signal.


In order to determine the ICR1 value,

you should know two things:


●System clock speed

●Timer clock speed


Hopefully the system clock speed is something you already know...

For those of you using the MDMicro Maveric boards,

it will most likely be 16MHz.



The timer speed is determined by the system clock speed divided by a prescaler.

The prescaler is set by the CSn2:0 bits

which are located in the TCCRn register

(where n is the timer number).

For example, Timer1's speed is set by the CS1 bits which are located in TCCR1B register.


These images are taken from the ATmega8 data sheet:



The clock section bits are the last three bits

in the TCCR1B register.


clkio is your system clock.

For example

if your system clock was 16MHz,

your timer could be 16MHz, 2MHz, 250kHz, 62.5kHz, or 15.625kHz

depending on your prescaler.


To calculate how to generate a desired frequency,

the ATmega datasheet provides this equation:


This equation tells you

the relationship between system clock frequency, prescaler, ICR1 and the output PWM frequency.


To get 50Hz with a system clock frequency of 16MHz,

you would need to use the following TOP(ICR1) value for the following prescalers:

Prescaler N = 1 then Top(ICR1) = 160000

Prescaler N = 8 then Top(ICR1) = 20000

Prescaler N = 64 then Top(ICR1) = 2500

Prescaler N = 256 then Top(ICR1) = 625

Prescaler N = 1024 then Top(ICR1) = 156.25


Note : You cannot use prescaler 1 or 1024 to generate a 50Hz PWM with a 16MHz:

쓸수없다. 1 or 1024를 to 만들어내기위해 a 50Hz PWM을 with 16MHz로

Prescaler 1 cannot be used since 160000 is too large to fit in TCR1.

프리스케일러1은 쓰일수없다. since 160000은 너무 크다. to 맞추기에 in TCR1

TCR1 is a 16 bit register with a range from 0 to 65535.

TCR1은 16비트 레지스터이다. with a 범위를 갖는 0~65535까지 (2^16 = 65536)

Prescaler 1024 should not be used since you cannot put decimals into ICR1.

프리스케일러 1024는 씌여선안된다. since 넌 넣을수없다. 소수(=decimals) into ICR1에


I would suggest prescaler 8 and set ICR1 to 20000

because this will allow you to change OCR1A

between 1000 and 2000 to obtain 1~2ms high pulses.


If you are using CodeVision, this is the 2000 KHz timer.


>>

What is OCRxn?

If you have been reading the ATmega datasheet about PWM generation,

you maybe wondering what OCRxn is and what is the difference between ICRn.

만약 네가 이 데이터시트를 읽고있는 중이라면

넌 아마 궁금해할것이다. 뭔지 OCRxn 이, and 뭐가 다른지 between ICRn 간에서.

First note that in OCRxn,

the x defines the Timer number and n defines which servo you are controlling.

우선 기억해라. in OCRxn에서,

그 x는 정의한다. the Timer 넘버를 and n은 정의한다. 어느 서보를 네가 컨트롤하고있는지.

Most timers can control multiply servos.

For example on Timer1

you can set OCR1A, OCR1B,

and sometimes OCR1C (read the datasheet to find out how many servos a particular timer can  support)

예를들어 on Timer1상에서

넌 can set할수있다. OCR1A, OCR1B를,

and 때로는 OCR1C를


The simple explaination for OCRxn and ICRn is:


ICRn creates the 50Hz PWM signal for the servo.

OCRxn controls the actually movement of the servo.

ICRn은 만들어낸다. the 50Hz PWM 시그널을 for the 서보를위해.

OCRxn은 컨트롤한다. the 실질적 이동을 of the 서보의


Once you set ICRn (ICR1 for Timer1).

you won't change it again.

However you will be constantly changing OCRxn (OCR1A for Timer1 servo A)

to control the position of the servo.

일단 네가 세팅하면 ICRn을

넌 won't 바꿀수없다. 그걸 다시는.

However 넌 will be 끊임없이 바꾸게될것이다. OCRxn을

to 컨트롤하기위해 the 포지션을 of the 서보의


Here is diagram from the ATmega8 datasheet

which shows how the OCRxn value controls the signal length.

This diagram is little confusing for our purpose because it shows ICRn changing 

and thus producing various frequency signals.

We want a constant 50Hz signal

so we will never change ICRn after we set it.

여기 다이어그램이 있다. from the ATmega8 데이터시트에서의

which 보여주는 어떻게 the OCRxn 값이 컨트롤하는지 the signal 길이를.

이 다이어그램은 약간 햇갈린다. for 우리 목적에 because 이건 보여준다. ICRn 바뀌는

and 따라서 만들어낸다. 다양한 주파수 시그널들을.

우린 원한다. 상수 50Hz 시그널을

so 우린 will 절대 바꾸지 않을것이다. ICRn을 after we set it.



Here is a diagram that shows how we will use OC1A 

to generate 1~2ms high pulses to control servo position.

여기 a 다이어그램이있다. that 보여주는 어떻게 우리가 will 사용할지 OC1A를

to 만들기위해 1~2ms High 펄스들을 to 컨트롤하기위해 서포 포지션을.

ICR1 : Register to sets the Upper Limit(=TOP) to Timer1 (creates 50Hz signal)

TCNT1 : Count Value of Timer1 (아래 참고)

OCR1A : Sets when the PWM signal should toggle. (=Output Compare Register 1A)

OC1A : PWM을 만들어내는 AVR핀 이름중 하나(OC1A, OC1B, OC1C 등이 있다.)


It starts at zero, counts upto the value in ICR1 (Input Compare Register 1),

and then counts back down to Zero.

(파란색 선 오르막, 내리막을 참고)

When TCNT1 equals OCR1A (=Output Compare Register 1A)

while counting up, an output pin called OC1A (Output Compare 1A) goes high.

(아래 Red Circle로 표시된 부분)

When TCNT1 equals OCR1A

while counting down, output pin OC1A goes low.

(위 Blue Circle로 표시된 부분)

You can also think of the logic value on OC1A toggling every time TCNT1 = OCR1A.



To change the position of the servo,

you would change OCR1A between 1000 and 2000.

Example C code:

OCR1A = 1500;


Or to have a for loop run through all the possible servo positions:

for(OCR1A=1000; OCR1A!=2000; OCR1A++)

{

delay_ms(1);

}



I hope that helped you understand how to control a servo using an ATmega128 or ATmega8 chip.

네 이해를 돕고싶다. how to 제어하는법을 a 서보를 사용하여 an ATmega128 or ATmega8을



Advantages to using the built-in PWM generation in the Timers are

장점... to 사용하기위 the 내장 PWM 발생기를 in the 타이머에서 ...은

●Simpler code once you set all the registers correctly.

더 간단한 코드

●Servo control takes no processing time.

프로세스 시간을 요하지 않는다.

●Your servo perfomance will not be affected by other interrupts or computationally heavy programs.

인터럽트 or 무거운 계산에 영향받지않는다.


>>

Disadvantages: (=불이익)

●You can only control a limited number of servos per timer.

Usually between 2 and 3.

However multiple timers have built-in PWM generation.

●No others that I can think of...



>>

TroubleShooting:

문제해결법

If you are still unable to control servo:

여전히

●Is the servo broken? Try using it on someone else's board that already has servo working.

●Also the servo should twitch when you plug it into power and ground.

If not, something may be wrong with the servo itself.

●Did you find the correct OC1A output pin and set it up as an output pin in your code ?

●A good idea  would be to hook an oscilloscope up to your OC1A output pin to verify that you are getting a 50Hz signal with the correct high and low pulses.

●If the signal is a different speed than you experted,

are you sure about your system clock speed.

Blown fuse bits will often set the ATmega's clock to an internal 1MHz clock.

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

공지사항

카테고리

분류 전체보기 (782)
Programming(=프로그래밍) (3)
MiDi (2)
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)

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백