Anda di halaman 1dari 4

1 Nghin cu, tm hiu

1.1 Principle of pulse generator


1.1.1 Generating PWM
Pulse-width modulation (PWM), is a modulation technique used to encode a message
into a pulsing signal. Generating PWM is change the interval that signal at a high state (duty
cycle) in a fixed cycle (period), thereby changing the average output voltage of load

We have:
-T: the pulse period.
-T1: Times that pulse at high state
- Adjustment coefficient D (%): D = T1/T.
- Maximum voltage provided for load: Udmax
- The average voltage provided for the load when use PWM: Ud = Udmax. D

1.1.2 Generating PWM with ATmega 8

Timer/Counter1:
Timer/Counter1 is a multifunctional T/C 16 bits. It is an ideal T/C for the programming
measurement and programmable controllers by its high resolution (16 bits) and can generate
PWM (Pulse Width Modulation often used for motor control).
Register: there are plenty of registers related to T/C1. Because this is 16 bits T/C, but the
memory data width of AVR is 8-bit, so sometimes it's necessary to use pairs of the 8-bit register
to form one 16-bit registers. Two 8-bit registers will have names ending with the letters L and H
in which L is a register contains 8 bits low (lOW), and H is the 8-bit registers containing 16 bits
high of the value that it creates.

TCNT1H and TCNT1L (Timer/Counter Register): two 8-bit registers constitute 16 bits

register (TCNT1) which contains operational values of T/C1. Both of this register allows read

and write values directly. These registers are combined as follows:

TCCR1A and TCCR1B (Timer / Counter Control Register): are two registers control the
operation of the T/C1. All operation mode of T/C1 determine through the bits in this registers.
However, this is not high and low bytes of a register, which is two completely independent
registers. All bits in this register, include the mode select bits or select waveform bits (Waveform
Generating Mode - WGM), the specified output format bits (Compare Match Output - COM), the
value divided prescale select bits for the clock (Clock Select - CS)... The structure of the two
registers is shown below.

The Timer1 of Atmega8 give us two broad channel PWM generator that:
- Channel A: The signal in OC1A (PORTB.1)
- Channel B: The signal in OC1B (PORTB.2)
With many PWM generate mode. Here we will clarify about Fast PWM mode, mode 14
(WGM13 = 1, WGM12 = 1, WGM11 = 1, WGM10 = 0).
In the Fast PWM mode, a count of 1 cycle from BOTTOM to TOP counts (single-slope),
so this mode called Fast PWM (PWM fast). There are five modes in Fast PWM mode
corresponding to selecting five different values of TOP. The establishment and operation mode
for Fast PWM are performing through 4 bits WGM and the output waveform select bits, the
Output Compare Mode in TCCR1A registers, TCCR1B and TCCR1A registers.

Notice that COM1A1, COM1A0, and COM1B1, COM1B0 are selected bits of the PWM
output signal format (Output Compare Mode bits). COM1A1, COM1A0 used for channels A and
COM1B1, COM1B0 used for Channel B.
- Set the output form of PWM signal in TCCR1A registers.
- When activated, the initial state of OC1A is a high state (depending on the type of PWM
signal selected above), TCNT1 increased value from 0 until its value equal to the value on the
OC1A, then OCR1A register is reset to 0. TCNT1 still continue to increase until its value equal
to the value in a ICR1 register, and then TCNT1 reset to 0 and OC1A pulled up to the high state.

From here we can set up:


- The value of ICR1: the cycles of the pulse.
- The value of OCR1A: the pulse duration at a high state.
Thus, we have created things ranging PWM with optional adjustment coefficient.

Anda mungkin juga menyukai