회로이론/장비

ESP32+MAX98357A Class D 1kHz 출력 측정

원원 2025. 8. 13. 23:29

안녕하세요. 오늘은 MAX98357A CLASS D 오디오 앰프 칩의 출력을 측정해보겠습니다.



* Class D 측정방식
Class D 앰프는 전력을 효율적으로 사용하기 위해 오디오 신호를 고속 PWM/PDM 스위칭으로 변조해 증폭하는 방식입니다.
BTL(Bridge-Tied Load) 구조에서는 출력이 스피커 +단과 −단 모두 스위칭 신호이므로, 단일 채널 측정으로는 실제 오디오 파형을 볼 수 없습니다.
따라서 다음 중 한 방법으로 측정해야 합니다.
방법 1: +단과 −단을 각각 채널로 측정 후, 차동(C1 − C2) 계산
방법 2: 차동 프로브 사용
이번 테스트에서는 방법 1을 사용했습니다.


* 측정 구성
ESP32와 MAX98357A를 이용해서 Class D 출력을 발생시켰고, Analog discovery 장비를 이용해서 측정했습니다.
스피커 +단 → 측정 장비 CH1
스피커 −단 → 측정장비 CH2
CH1−CH2 → 차동 파형


*사용 코드
ESP32에서 I2S를 이용해 1 kHz 사각파 톤을 생성하는 기본 예제를 사용했습니다.

/*
 This example generates a square wave based tone at a specified frequency
 and sample rate. Then outputs the data using the I2S interface to a
 MAX08357 I2S Amp Breakout board.
 I2S Circuit:
 * Arduino/Genuino Zero, MKR family and Nano 33 IoT
 * MAX08357:
   * GND connected GND
   * VIN connected 5V
   * LRC connected to pin 0 (Zero) or 3 (MKR), A2 (Nano) or 25 (ESP32)
   * BCLK connected to pin 1 (Zero) or 2 (MKR), A3 (Nano) or 5 (ESP32)
   * DIN connected to pin 9 (Zero) or A6 (MKR), 4 (Nano) or 26 (ESP32)
 DAC Circuit:
 * ESP32 or ESP32-S2
 * Audio amplifier
   - Note:
     - ESP32 has DAC on GPIO pins 25 and 26.
     - ESP32-S2 has DAC on GPIO pins 17 and 18.
  - Connect speaker(s) or headphones.
 created 17 November 2016
 by Sandeep Mistry
 For ESP extended
 Tomas Pilny
 2nd September 2021
 Lucas Saavedra Vaz (lucasssvaz)
 22nd December 2023
 anon
 10nd February 2025
 */

#include <ESP_I2S.h>

// The GPIO pins are not fixed, most other pins could be used for the I2S function.
#define I2S_LRC  25
#define I2S_BCLK 5
#define I2S_DIN  26

const int frequency = 1000;    // frequency of square wave in Hz
const int amplitude = 10000;    // amplitude of square wave
const int sampleRate = 8000;  // sample rate in Hz

i2s_data_bit_width_t bps = I2S_DATA_BIT_WIDTH_16BIT;
i2s_mode_t mode = I2S_MODE_STD;
i2s_slot_mode_t slot = I2S_SLOT_MODE_STEREO;

const unsigned int halfWavelength = sampleRate / frequency / 2;  // half wavelength of square wave

int32_t sample = amplitude;  // current sample value
unsigned int count = 0;

I2SClass i2s;

void setup() {
  Serial.begin(115200);
  Serial.println("I2S simple tone");

  i2s.setPins(I2S_BCLK, I2S_LRC, I2S_DIN);
  //i2s.setInverted(true, false, false);


  // start I2S at the sample rate with 16-bits per sample
  if (!i2s.begin(mode, sampleRate, bps, slot)) {
    Serial.println("Failed to initialize I2S!");
    while (1);  // do nothing
  }
}

void loop() {
  if (count % halfWavelength == 0) {
    // invert the sample every half wavelength count multiple to generate square wave
    sample = -1 * sample;
  }

  // Left channel, the low 8 bits then high 8 bits
  i2s.write(sample);
  i2s.write(sample >> 8);

  // Right channel, the low 8 bits then high 8 bits
  i2s.write(sample);
  i2s.write(sample >> 8);

  // increment the counter for the next sample
  count++;
}



*측정결과
노랑 : 스피커+
파랑 : 스피커-
주황 : 차동 (스피커+) - (스피커-)
결과적으로 약 1 kHz의 오디오 신호가 출력됨을 확인했습니다.

 

'회로이론 > 장비' 카테고리의 다른 글

ANALOG DISCOVERY-Wave generator 테스트 하기  (0) 2025.08.11
오실로스코프 트리거(trigger)란?  (0) 2022.02.07