# 4.Digital-Analog Converter

วัตถุประสงค์ของ DAC นั้นตรงกันข้ามกับของ ADC DAC แปลงสัญญาณดิจิทัลเป็นสัญญาณอะนาล็อกสำหรับเอาต์พุต

จำเพลงเมื่อเปิด NyBoard ได้ไหม กำลังใช้ PWM เพื่อสร้างเสียงเพลงซึ่งใช้การสลับความเร็วสูงเพื่อปรับรอบการทำงานเป็นแรงดันเอาต์พุต

เมื่อเปรียบเทียบกับ PWM แล้ว DAC จะส่งแรงดันออกโดยตรงโดยไม่ต้องคำนวณรอบการทำงาน ESP32 รวม DAC 8 บิต 2 แชนเนลที่มีค่า 0-255 ช่วงแรงดันไฟฟ้าคือ 0-3.3V ดังนั้นสูตรการคำนวณแรงดันเอาต์พุตของ DAC จึงเป็นดังนี้:

$$
DAC=（int）TargetV/3.3V∗255
$$

The demo is as follows:

```c
#define DAC1 25 

void setup() {  
}

void loop() {
  
  // 8bit DAC, 255 = 3.3V, 0 = 0.0V 
  for(int i = 0; i < 255; i++){
    dacWrite(DAC1, i);
    delay(10);
  }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.petoi.com/thai/biboard/demo-applications/4.digital-analog-converter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
