# Project Name：Adc_Demo

---
## Function description

This project is designed to demonstrate the MCAL Adc module configuration and usage:
- **Adc**: 
  - Test the Api of Adc ,including Init,read status，start conversion...
  - ADC0 performs conversions with interrupts, after a group conversion completed, the data read from the ADC FIFO register to the result buffer in the IRQ handler.
  - ADC1 performs conversions with DMA, after a group conversion completed, the data is transferred from the ADC FIFO register into the result buffer by DMA.
  - There are six groups configured in this demo, the detail information of each group is as follows:

|HW Instance|Group Name|Transfer Type|Trigger Type|Conversion and Access Mode|Channel List|
|----|----|----|----|----|----|
|ADC0|ADC0_GP0_OMSA|Polling|Software|One short conversion and single access|ADC0_SE0, ADC0_SE1|
|ADC0|ADC0_GP1_CMSA|Interrupt|Software|Continuous conversion and single access|ADC0_SE0, ADC0_SE1,VDD,VREF,VSS|
|ADC0|ADC0_GP2_CMLSA|Interrupt|Software|Continuous conversion and liner streaming access|ADC0_SE0, ADC0_SE1,VDD,VREF,VSS,VDD25|
|ADC0|ADC0_GP3_CMCSA|Interrupt|Software|Continuous conversion and circular streaming access|ADC0_SE0, ADC0_SE1,VDD,VREF,VSS,VDD25|
|ADC1|ADC1_GP0_CMSA|DMA|Software|Continuous conversion and single access|ADC1_SE16~ADC1_SE22|
|ADC1|ADC1_GP1_CMCSA|DMA|Software|Continuous conversion and circular streaming access|ADC1_SE16~ADC1_SE22|

After reset,he demo project will initialize the Adc driver, set up result buffers for all groups, enable notifications for the necessary groups, and start all group to conversion. All group will be repeatedly start conversion and read the result in while(1).After all channel groups are converted, the ADC0_SE0 channel conversion results from all groups are mutually checked.

This demo code defines the following variables to observe the acquisition results and the program's running status:

- **Variables for ADC Conversion Results** 
  - `Adc0_Group0ResultPhys`: An array for storing the physical values of the conversion results of ADC0 Group0, with units of millivolts.
  - `Adc0_Group1ResultPhys`: An array for storing the physical values of the conversion results of ADC0 Group1, with units of millivolts.
  - `Adc0_Group2ResultPhys`: An array for storing the physical values of the conversion results of ADC0 Group2, with units of millivolts.
  - `Adc0_Group3ResultPhys`: An array for storing the physical values of the conversion results of ADC0 Group3, with units of millivolts.
  - `Adc1_Group0ResultPhys`: An array for storing the physical values of the conversion results of ADC1 Group0, with units of millivolts.
  - `Adc1_Group1ResultPhys`: An array for storing the physical values of the conversion results of ADC1 Group1, with units of millivolts.

- **Variables for Counting Conversion Times**
  - `Adc0_Group0ConCompCnt`: Counts the number of completed conversions for ADC0 Group 0.
  - `Adc0_Group1ConCompCnt`: Counts the number of completed conversions for ADC0 Group 1.
  - `Adc0_Group2ConCompCnt`: Counts the number of completed conversions for ADC0 Group 2.
  - `Adc0_Group3ConCompCnt`: Counts the number of completed conversions for ADC0 Group 3.
  - `Adc1_Group0ConCompCnt`: Counts the number of completed conversions for ADC1 Group 0.
  - `Adc1_Group1ConCompCnt`: Counts the number of completed conversions for ADC1 Group 1.
  - `Adc0_ResultNotMatchCnt`: The program checks the correctness of the ADC0 channel 0 conversion results among different groups. Specifically, it compares the results of Group 0 with those of Group 1, Group 2, and Group 3. If the difference between the results of Group 0 and another group exceeds 100mV, the `Adc0_ResultNotMatchCnt` variable is incremented.

- **Expected values for the conversion results of each Channel** (VDD supply voltage is 5V):

|Channel|Description |Expected Value (mV)|
|----|----|----|
|ADC0_SE0~ADC0_SE1, ADC1_SE16~ADC1_SE22|ADC0 and ADC1 external input channels  |External input value  |
|VDD|Power supply voltage |5000  |
|VREFH|VREFH voltage value |5000  |
|VSS|VSS voltage value |0  |
|VDD25|VDD25 voltage value |2500  |

**Note**: In this Demo, the MCU is powered by 5V. If you need to use 3.3V power supply, please modify the calculation of the physical values of the ADC conversion results by yourself.

---


## Setup

+ ***Step1***: Open the `Adc_Demo.yct` with the YCT tool, config the toolchain per your required(by default, the VS code + GCC are used)
+ ***Step2***：Generate the codes， you can change the configurations if needed(to adapt to your own HW design), if so, please ensure all the modifications are OK with no any errors exist before generating the code.
+ ***Step3***: Open the generated project with VS code/IAR/Keil IDE per your selected.
+ ***Step4***: Compile the project, power on the EVB and download it to the EVB via the available debugger, such as a J-Link debugger probe.
+ ***Step5***: At last, enjoy the demo example.
  
---


## Hardware Requirements

- **Evaluation Board (EVB)**: YTM32B1ME0-Q144-EVB-Rev.B/C
- **Debugger**: J-Link HW v9.2 or later, with the YUNTU `YTM32B1ME0` patch (support package) installed.

**Note**: Please check the version number at the bottom of the EVB. If it is `YTM32B1ME0-EVB-Q144 Rev.C`, please use the example projects ending with `_RevC` for `YTMEVB_Demo`, `Icu_Demo`, and `Dio_Demo`.

---

## Software Requirements

- **Configuration & Code Generation Tool**:
  - **MCAL**: Yuntu Config Tool (YCT) v2.7.0 or later
- **Compiler Toolchain**:
  - **GCC**: GNU GCC v10.3 or later
  - **Keil/MDK**: ARM Keil/MDK v5.36 or later(`armclang v6.18.2` is recommended to be used as the compiler)
  - **IAR**: IAR v9.50 or later
  - **VS Code**: Microsoft Visual Studio Code IDE v1.76 or later (with C/C++ support, GNU toolchain, CMake v3.25, ninja, and Cortex-Debug extensions installed)
- **Debugger Driver**:
  - **J-Link**: SEGGER J-Link v7.82 or later, with the YUNTU `YTM32B1ME0` patch (support package) installed.
  - **Ozone Debugger Tool**: SEGGER Ozone v3.28 or later

  ***Note***: The **YTM32B1ME0** patch needs to be installed, which can be obtained through the **YCT** tool or by contacting the ***Yuntu Sales/FAE team***.


---