Lecture 3
Lecture 3
Mikrodenetleyiciler
Güz 2019
(3. Sunu)
(Dr. Öğr. Üyesi Deniz Dal)
Analog Çıkış ve Darbe Genişlik Modülasyonu
(Pulse Width Modulation – PWM)
Arduinos and other microcontrollers provide analog to digital (ADC) conversion to
convert an input voltage to a digital value. You might think that they also provide the
converse which is digital to analog (DAC) conversion. This is not the case. Instead they
provide pulse-width modulated (PWM) outputs. The Arduino library provides this
functionality with a function called analogWrite(). The name seems to imply DAC
functionality, but it just controls the PWM output. For many applications, such as the
case of motor control, PWM is sufficient.
Analog Çıkış ve Darbe Genişlik Modülasyonu
(Pulse Width Modulation – PWM)
Pulse Width Modulation, or PWM, is a technique for getting analog results with
digital means. Digital control is used to create a square wave, a signal switched
between on and off. This on-off pattern can simulate voltages in between full on (5
Volts) and off (0 Volts) by changing the portion of the time the signal spends on
versus the time that the signal spends off. The duration of "on time" is called the
pulse width. To get varying analog values, you change, or modulate, that pulse
width. If you repeat this on-off pattern fast enough with an LED for example, the
result is as if the signal is a steady voltage between 0 and 5v controlling the
brightness of the LED.
Görev Çevrimi (Duty Cycle)
A duty cycle is the percentage of
one period in which a signal is
active. A period is the time it
takes for a signal to complete an
on-and-off cycle.
A 60% duty cycle means that the
signal is on 60% of the time but
off 40% of the time.
The "on time" for a 60% duty
cycle could be a fraction of a
second, a day, or even a week,
depending on the length of the
period.
Analog Çıkış ve Darbe Genişlik Modülasyonu
(Pulse Width Modulation – PWM)
In the graphic next, the green lines
represent a regular time period.
This duration or period is the
inverse of the PWM frequency. In
other words, with Arduino's PWM
frequency at about 500Hz, the
green lines would measure 2
milliseconds each. A call to
analogWrite() is on a scale of 0 -
255, such that analogWrite(255)
requests a 100% duty cycle (always
on), and analogWrite(127) is a 50%
duty cycle (on half the time) for
example.
analogWrite Fonksiyonu ve Arduino UNO PWM Çıkış Pinleri
Writes an analog value (PWM wave) to a pin. Can be used to light a LED at varying brightnesses
or drive a motor at various speeds. After a call to analogWrite(), the pin will generate a steady
square wave of the specified duty cycle until the next call to analogWrite() (or a call to
digitalRead() or digitalWrite() on the same pin). The frequency of the PWM signal on most pins is
approximately 490 Hz.
On the Uno, this function works on pins 3, 5, 6, 9, 10, and 11. Those pins are marked with a tilde
~ symbol and output a variable duty cycle from 0 to 255 (0 to 100%).
You do not need to call pinMode() to set the pin as an output before calling analogWrite().
The analogWrite function has nothing to do with the analog pins or the analogRead function.
Syntax:
analogWrite(pin, value)
Parameters:
pin: the pin to write to.
value: the duty cycle: between 0 (always off) and 255 (always on).
PWM ile LED Parlaklığının Kontrolü
PWM ile LED Parlaklığının Kontrolü (Sketch)
PWM ile LED Parlaklığının Kontrolü (Bağlantı)
Dijital Giriş ve digitalRead Fonksiyonu