Generate PWM Signals to the AVR Microcontroller

Sponsored Link :

. .


PWM signal can be constructed in many ways, not only use an analog method using op-amp but also use a digital method. With each change in PWM analog method is very smooth, while the digital method of any changes influenced by the resolution of the PWM PWM itself. Suppose the digital PWM PWM 8-bit means it has a resolution of 28 = 256, mean value of the PWM output has a 256 variation, variation ranging from 0-255 that represents the duty cycle 0-100% of the PWM output.
PWM in the AVR microcontroller generated by timer, on ATmega 8535 AVR microcontroller, ATmega32 Atmega16 and has three pieces in which the second timer 8-bit timer and a timer 16 bits.
PWM signal generation process on the AVR microcontroller follows:

PWM signal in AVR microcontroler1 Generate PWM Signals to the AVR Microcontroller

We see in the picture above there are some parameters, In every PWM on AVR microcontroller has the following parameters:

Resolution:

resolution is the amount of variation changes the value in the PWM. Suppose an 8-bit PWM resolution PWM has a variation of mean value changes as much as 28 = 256 variations ranging from 0-255 value changes, when we give the value exceeds the limit of resolution, it will be overflow mean value is taken from a number of bits are provided and who taken starting from the lowest bit (LSB). Most of microcontrollers uses 8-bit timer with 8 bit resolution. In the picture above described PWM resolution originated from the base of the triangle and ending at the tip of the triangle.

Compare:

compare is a comparison value. This value is used as reference What is the duty cycle of the PWM. Compare the value varies in accordance with a resolution of the PWM. In the above picture compare value is marked with a red line, where its position among the basic triangle and the tip of the triangle.

Clear:

Clear comparator used for the determination of whether the comparator inverting or non-inverting. We see the picture above the triangle and the red line. Microcontroller will membadingkan second position, suppose that when we set the PWM on Down’s clear, it means that when the triangle is below the red line (compare), then the PWM will issue a logic 0. And vice versa if the triangle is above the red line (compare), then the PWM will issue a logic 1. So that the width is determined by the narrowness of the logic one compare the position, the narrowness of the logic of a sheet that is the PWM output value, and this incident happened in the harmonic constant. Therefore compare the value is used as the value of PWM duty cycle. Clear Up is the opposite (inverse) from Clear Down on the output logic. To more clearly please see the following picture:

Prescale:
prescale used to determine the time period of the PWM. Prescale varied: 1, 8, 32, 64, 128, 256, 1024. The purpose of the prescale is set prescale 64 we suppose that means the timer / PWM will calculate a time when the CPU is clocked at 64 times the CPU clock is clok microcontroller itself. The period of the PWM can be calculated using the following formula:
T = (1/Clock CPU) * Prescale * Resolution
Example:
Microcontroller with 8-bit timer resolution = 256 and given a 12 MHz crystal programmed to issue a PWM with 8 prescale period and what is the PWM frequency?
Hence can be calculated:
T = (1 / 12000000) * 8 * 256
T = 0.0001707 seconds
F = 5.858 KHz
Enable PWM0 on Atmega8535, Atmega16 and ATmega32
PWM0 on this microcontroller OCR0 issued at the port (PORTB.3). with a resolution of 8 bits. PWM0 for setting can be done by setting the timer counter 0 (TCCR0), where the settings can view the reference table as follows:
Prescale Clear Up Clear Down
1 &H69 &H79
8 &H6A &H7A
64 &H6B &H7B
256 &H6C &H7C
1024 &H6D &H7D
For example, want to setup a timer 0 PWM comparator with a prescale 64 to clear down the TCCR0 setting with value>> TCCR0 = & H6B.
Here is a sample piece of program for the activation of PWM 0
…………..
Config Portb.3 = Output
Tccr0 = &H6B
Ocr0 = 100
………….
The above snippet is an example program for PWM0, where to change duticycle PWM0 can be altered value of Ocr0. for its own PWM output is on PIN 4 (PORTB.3).
Enable PWM1 on Atmega8535, Atmega16 and ATmega32
PWM 1 at microcontroller has two outputs, that is issued at the port PWM1a OCR1A (PORTD.5) and issued at the port PWM1b OCR1A (PORTD.4) each mempunyari resolution that can be altered between 8 bits, 9 bits, and 10 bits. for setting PWM1 can be done with a timer setting the following
Config Timer1 = Pwm , Pwm = 8 / 9 /10 , Compare A Pwm = Clear Down/Up , Compare B Pwm = Clear Down/Up , Prescale = 1 /8/64/256/1024
*mark crisp (slash>> /) indicates a choice
Where the PWM 1a and B are selectable resolution with three options, namely 8 bits or 9 bits or 10 bits. Each can be selected PWM1b PWM1a or whether the type of comparative Clear Clear Down or Up. And prescale of this PWM1b PWM1A and can be selected with a choice of one or eight or 64 or 256 or 1024.
An example we want to set PWM1 on our microcontroller 8-bit PWM is set to Compare A = Non-inverting,  and Compare B = inverting, the timer with a prescale = 8 we set as follows:
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Up , Prescale = 8
Here is a sample snippet for the activation of the program and PWM1b PWM1a.
…………….
Config Portd.4 = Output
Config Portd.5 = Output
Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Up , Prescale = 8.
Pwm1a = 100
Pwm1b = 50
Ocr1al = 100
Ocr1bl = 100
……………
The above snippet is an example program to PWM1a and PWM1b, where to change duticycle PWM1a can be altered or Ocr1al Pwm1a value. And to change duticycle PWM1b can be altered or Ocr1al Pwm1b.
Enabling PWM2 on Atmega8535, Atmega16 and ATmega32
PWM2 on this microcontroller OCR2 issued at the port (PORTD.7) with a resolution of 8 bits. PWM2 for setting can be done by setting the timer counter 2 (TCCR2), where the settings can view the reference table as follows:
Prescale Clear Down Clear Up
1 &H69 &H79
8 &H6A &H7A
32 &H6B &H7B
64 &H6C &H7C
128 &H6D &H7D
256 &H6E &H7E
1024 &H6F &H7F
For example, want to setup as a second timer with a prescale PWM comparator 64 with Clear down the TCCR2 setting with value>> TCCR2 = & H6C.
Here is a sample piece of program for PWM 2 activation
…………..
Config Portd.7 = Output
Tccr1 = &H6C
Ocr0 = 100
………….
In addition to the above way you can also directly provide timer2 pad settings directly in the following ways:
Config Timer2 = Pwm, Prescale = 1/8/32/64/128/256/1024, Compare Pwm = Clear Down/Up
Where the selectable types of comparative PWM2 whether Clear Clear Down or Up. And prescale of this PWM2 may be selected by option 1 or 8 or 32 or 64 or 128 or 256 or 1024.
An example we want to set the microcontroller to PWM2 Compare = Non-inverting, and with the timer 2 prescale 8 we set as follows:
Config Timer2 = Pwm, Prescale = 8, Compare Pwm = Clear Down
for example :
…………..
Config Portd.7 = Output
Config Timer2 = Pwm, Prescale = 8, Compare Pwm = Clear Down
Ocr2 = 100
………….

Keyword :
microcontroller ,signal ,voltage ,pwm signal ,project ,how to ,frequency ,duty cycle ,circuit ,winavr ,tutorial ,search ,pwm signals ,pwm output ,program memory ,prescaler ,waveform ,software ,sine wave ,signals ,signal generator ,servo motor ,registers ,pwm controller ,pulse width modulation ,processor ,peripheral ,microcontrollers ,memory ,lookup table ,interfacing ,family ,design ,controller ,avr-gcc ,avr studio ,avr microcontroller ,atmega ,application.


admin tagged this post with: , , Read 322 articles by

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Select Category