# Acmp_Continuous_Loop_Demo

---

## Function Description

This example demonstrates how to play simple music using the 8-bit DAC embedded in the ACMP module:

1. The YTM32B1MD2 has no stand-alone DAC peripheral; ACMP0 embeds an 8-bit DAC whose analog output can be routed to the external pin PTC8 (DAC0_OUT) through the OUTEN bit of the DAC register.
2. The program uses Direct Digital Synthesis (DDS): a 256-point sine lookup table plus a phase accumulator continuously rewrites the DAC value register at a fixed sample rate (20 kHz), synthesising note waveforms on PTC8.
3. Sample timing is provided by the Cortex-M33 DWT cycle counter (accurate and does not conflict with the OSIF SysTick). The core clock is read at runtime via `CLOCK_SYS_GetFreq(CORE_CLK, ...)`, so nothing is hard-coded.
4. The built-in tune is "Twinkle Twinkle Little Star". It is played in a loop from the `main` loop; the blue LED lights up while the tune plays as a beat indicator.
5. Note frequencies, durations and the melody can be edited in `app/dac_music.c` / `app/dac_music.h`.

> Note: the PTC8 pin mux (DAC0_OUT) is already configured in `board/pin_mux.c`. The ACMP DAC output has limited drive strength, so connect PTC8 to an oscilloscope, an active buzzer or an amplified speaker to listen — do not drive a low-impedance speaker directly.

---

## Hardware Requirements

+ **EVB**: YTM32B1MD2-EVB-Q100
+ **Debugger**: J-LINK v9.2 or later version
+ **Other**: an oscilloscope / active buzzer / amplified speaker connected to PTC8 (DAC0_OUT) to observe or hear the output

---

## Software Requirements

+ **SDK**      : YTM32B1MD2_1_4_0 or later version
+ **GCC**      : GNU GCC v10.3 or later version
+ **Keil/MDK** : ARM Keil/MDK v5.36 or later version
+ **IAR***     : IAR v8.4 or later version
+ **VS Code**  : Microsoft Visual Studio Code IDE v1.76 or later version(GNU GCC toolchain, CMake v3.25, ninja, Cortex-Debug extensions installation required)
+ **J-LINK** : SEGGER JLINK v6.96 or later version, YTM32B1MD2 patch(support package) installation required.
+ **Ozone**  : SEGGER Ozone v3.28 or later version.
  
---