bm-305 mikrodenetleyiciler güz 2015 (3. sunu) (yrd. doç. dr. deniz dal)

14
BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Upload: cornelius-park

Post on 14-Dec-2015

236 views

Category:

Documents


10 download

TRANSCRIPT

Page 1: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

BM-305

Mikrodenetleyiciler

Güz 2015

(3. Sunu)(Yrd. Doç. Dr. Deniz Dal)

Page 2: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. 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.

Page 3: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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.

Page 4: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Analog Çıkış ve Darbe Genişlik Modülasyonu (Pulse Width Modulation – PWM)

In the graphic below, 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.

Page 5: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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.

Page 6: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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).

Page 7: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

PWM ile LED Parlaklığının Kontrolü

Page 8: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

PWM ile LED Parlaklığının Kontrolü

Page 9: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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

Page 10: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Geçici Anahtar ile LED Kontrolü

Page 11: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Geçici Anahtar ile LED Kontrolü

Page 12: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

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)

Page 13: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Potansiyometre Çıkış Geriliminin Analog Giriş Olarak Kullanılması

Page 14: BM-305 Mikrodenetleyiciler Güz 2015 (3. Sunu) (Yrd. Doç. Dr. Deniz Dal)

Potansiyometre Çıkış Geriliminin Analog Giriş Olarak Kullanılması