아두이노 DAC, PWM

cornpip
|2024. 2. 18. 16:00

Digital-to-Analog Converter (DAC)

아두이노는 DAC기능이 없어 연속적인 아날로그 값을 만들 순 없지만 PWM을 이용해 비슷한 기능을 할 수 있다. (UNO R4는 있는 듯)

Pulse Width Modulation (PWM)

LED 밝기 조절을 예시로 살펴보자.

어떻게 전압의 펄스 폭 조절이 밝기에 변화를 줄 수 있을까?

=> 펄스의 주기는 매우 빠르기 때문에 사람 눈으로 본다면 펄스 폭이 50%인 것은 밝기가 50%인 것과 같게 보인다.

 

아두이노의 AnalogWriteMega.ino example을 실행시켜보자.

const int lowestPin = 4;
const int highestPin = 6;


void setup() {
  // set pins 2 through 13 as outputs:
  for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
    pinMode(thisPin, OUTPUT);
  }
}

void loop() {
  // iterate over the pins:
  for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) {
    // fade the LED on thisPin from off to brightest:
    for (int brightness = 0; brightness < 255; brightness++) {
      analogWrite(thisPin, brightness);
      delay(2);
    }
    // fade the LED on thisPin from brightest to off:
    for (int brightness = 255; brightness >= 0; brightness--) {
      analogWrite(thisPin, brightness);
      delay(2);
    }
    // pause between LEDs:
    delay(100);
  }
}

 

analogWrite 함수로 PWM 비율을 정할 수 있다.

아두이노는 2~13번 핀에 PWM을 지원한다.  3개의 핀만 확인해보자.한 동영

'embedded' 카테고리의 다른 글

I2C Communication  (2) 2024.02.17