0% found this document useful (0 votes)
8 views

Lecture 3

Uploaded by

hakanismail53
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lecture 3

Uploaded by

hakanismail53
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

BM-305

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

digitalRead() reads the value from a specified digital pin,


either HIGH or LOW.
Syntax:
digitalRead(pin)
Parameters:
pin: the number of the digital pin you want to read (int)
Returns:
HIGH or LOW
Geçici Anahtar ile LED Kontrolü
Geçici Anahtar ile LED Kontrolü (Sketch)
Geçici Anahtar ile LED Kontrolü (Bağlantı)

Yukarıdaki devreyi kalıcı bir anahtarla da (dip switch) gerçekleyiniz.


Analog Giriş ve analogRead Fonksiyonu
analogRead() reads the value from the specified analog pin. The Arduino UNO
board contains a 6-channel, 10-bit analog to digital converter (ADC). This means
that it will map input voltages between 0 and 5 volts into integer values between 0
and 1023. This yields a resolution between readings of: 5 volts / 1024 units
or, .0049 volts (4.9 mV) per unit. The input range and resolution can be changed
using analogReference().
Syntax:
analogRead(pin)
Parameters:
pin: the number of the analog input pin to read from (0 to 5)
Returns:
int (0 to 1023)
Potansiyometre Çıkış Geriliminin Analog Giriş Olarak Kullanılması
Potansiyometre Çıkış Geriliminin Analog Giriş Olarak Kullanılması
(Sketch)

Seri Monitör penceresindeki bağlantı hızı da bu olmalı.!!!


Potansiyometre Çıkış Geriliminin Analog Giriş Olarak Kullanılması
(Bağlantı)
Uygulama 1
(Analog Giriş ve Analog Çıkış Uygulaması)
A0 pinine bağlı bir potansiyometreden okunan giriş gerilimi ile 9
numaralı dijital pine bağlı ledin parlaklığını kontrol edecek bir sketch
yazınız. (Analog Giriş ve Analog Çıkış Uygulaması)
Uygulama 2
(Analog Giriş ve Dijital Çıkış Uygulaması)
A0 pinine bağlı bir potansiyometreden okunan giriş gerilimi 2.35 Volttan
küçükse 8 numaralı dijital pine bağlı ledi yakıp 9 numaralı dijital pine
bağlı ledi söndüren aksi takdirde 8 numaralı dijital pine bağlı ledi
söndürüp 9 numaralı dijital pine bağlı ledi yakan bir sketch yazınız.
Potansiyometreden okunan gerilimi Seri Monitör penceresine aktarıp
ledlerin doğru zamanda yanıp söndüklerini gözlemleyiniz.

You might also like