Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

NuMicro® ADC

A Leading MCU Platform Provider

June 2016
Agenda
• ADC Applications
• ADC Block Diagram
• ADC General Features
• ADC Clock Source
• ADC Function
• Functions and Sample Code in BSP
• Sample Code

2
ADC Applications
• Current Measurement
• Voltage Measurement
• Various sensor Measurement like temp, Humidity, Load cell etc.
• Speedometer

3
AC – current measurement, voltage measurement

4
ADC Block Diagram ADC
Configuration
Control
Conversion
Results

Conversion
External Trigger Pin Results
4 options: falling/rising
/high/low

Reference
Voltage Input ADC Interrupt
Request

Channel
Selection

5
ADC General Features (I)
• 12-bit SAR ADC
- Fit for Current/Voltage measurement applications
• Analog input voltage range:
- VIN=0~VREF (Max to 5.5V).
• Operation voltage:
- AVDD = 2.5V~5.5V; VREF = 2.5V~ AVDD
• Up to 1 MSPS conversion rate (chip working at 5V)
• 3 operation modes
- Single mode
- Single-cycle scan mode
- Continuous scan mode 6
ADC General Features (II) – Input Source

• External Input channel:


- Up to 12 single-end analog input channels (NUC029SEE)
- 5 pairs of differential analog input channel.

• 2 Internal input sources:


- Internal Band-gap voltage (VBG)
- Internal temperature sensor voltage (VTEMP)

7
ADC General Features (III)
• An A/D conversion can be started by
- Software Write 1 to ADST bit (ADCR[11])
- PWM Center-aligned trigger
- External pin (STADC)
• Conversion results are held in data registers for each channel with
VALID and OVERRUN indicators.
• Supports two set digital comparators.
- User can select whether to generate an interrupt when conversion result matches the
compare register setting.
• Supports PDMA function
8
ADC Clock Source
ADC_S (CLKSEL1[3:2])

ADC_EN(APBCLK[28])
22.1184 MHz
11
HCLK ADC_CLK
10
1/(ADC_N + 1)
PLL FOUT
01
ADC_N(CLKDIV[23:16])
4~24 MHz
00

The maximum sampling rate is up to 1MSPS (Max. ADC clock is up to 21MHz)


The ADC clock frequency = (ADC clock source frequency) / (ADC_N+1);
ADC_N is an 8-bit pre-scaler

9
ADC Input Channel Setting
• The ADC input pins share with GPIO
• The ADC input pins must be configured in input type
• Single-end input mode
- Channel 0 ~ Channel 11
• Differential input mode
- Channel 0 ~ Channel 5
- Differential input channels are the paired channels of single-end input
channels

10
Trigger ADC Conversion
• Software Write 1 to ADST bit
• External pin (STADC)
• PWM Center-aligned trigger
- For Motor application

11
ADC Operation Mode

ADC Mode Type Remark

Single Mode One-shot Can set Match Counter

Single-Cycle Scan Mode One-shot for multiple CHs Can set Match Counter

Continuous Scan Mode Continuous for multiple CHs Can set Match Counter

12
Single Mode – Ex. Voltage measurement
• A/D conversion is to be performed only once on the specified single
channel.
• If software enables more than one channel in single mode, only the
lowest channel will be converted and the other enabled channels will
be ignored. 1 2 8 9 20

ADCCLK

ADST

SAMPLE

ADDRx Valid data

ADF

Note: SAMPLE is an internal signal indicates sample stage 13


x = the selected channel
Single-Cycle Scan Mode
– Ex. Multi-cell Battery Voltage Measurement
Channel0 Channel2 Channel3 Channel8

ADST

A/D converter
0x0 0x2 0x3 0x7
channel select

SAMPLE

ADC analog
R0 R2 R3 R7
macro output

ADDR0 R0

ADDR2 R2

ADDR3 R3

ADDR7 R7

Single-cycle scan on channel 0, 2, 3 and 7

Note: SAMPLE is an internal signal indicates sample stage

14
Continuous Scan Mode
– Ex. Continuous Power Measurement
Channel0 Channel2 Channel3 Channel7 Channel0 Channel2

ADST
Software clear ADST

A/D converter
0x0 0x2 0x3 0x7 0x0 0x2 0x3 0x7 0x0
channel select

SAMPLE

ADDR0

ADDR2

ADDR3

ADDR7

Continuous scan on channel 0, 2, 3 and 7


Note: SAMPLE is an internal signal indicates sample stage

15
Digital Comparator
• 2 digital comparators.
• When the conversion of the channel specified by CMPCH is
completed, the comparing action will be triggered automatically.
• Compare the ADC result of the specified channel with a user
defined compare value stored in CMPD(ADCMPRx[27:16])

16
Interrupt Sources
• Three interrupt sources
- ADF: completion of a ADC operation mode
- CMPF0: Condition match monitored by ADC comparator0
- CMPF1: Condition match monitored by ADC comparator1
ADF (ADSR0[0])
ADIE (ADCR[1])

CMPF0 (ADSR0[1])
ADC_INT
CMPIE (ADCMPR0[1])

CMPF1 (ADSR0[2])
CMPIE (ADCMPR1[1])

17
Sample Code Path

NUC029xEEBSPv3.00.001

NuMicro NUC029 Series


SampleCode Driver Reference Guide

StdDriver

ADC_SingleMode

ADC_SingleMode.uvproj
KEIL

18
Functions and Sample Code in BSP
• adc.c
- void ADC_Open(ADC_T *adc, uint32_t u32InputMode, uint32_t u32OpMode, uint32_t u32ChMask)
 This API configures ADC module to be ready for convert the input from selected channel

- void ADC_EnableInt(ADC_T *adc, uint32_t u32Mask)


 Enable the interrupt(s) selected by u32Mask parameter

• adc.h
- ADC_GET_CONVERSION_DATA(adc, u32ChNum)
 Get conversion data of specified channel

- ADC_START_CONV(adc)
 Start the A/D conversion

• gpio.h
- GPIO_DISABLE_DIGITAL_PATH(port, u32PinMask)
 Disable I/O Digital Input Path 19
ADC Sample Code - Init
void SYS_Init(void)
{
……
/* Enable ADC module clock */
CLK_EnableModuleClock(ADC_MODULE);
/* ADC clock source is 22.1184MHz, set divider to 7, ADC clock is 22.1184/7 MHz */
CLK_SetModuleClock(ADC_MODULE, CLK_CLKSEL1_ADCSEL_HIRC, CLK_CLKDIV0_ADC(7));
……
/* Disable the GPB15 digital input path to avoid the leakage current. */
GPIO_DISABLE_DIGITAL_PATH(PB, BIT15);
/* Configure the GPB15 ADC analog input pins */
SYS->GPB_MFPH &= ~(SYS_GPB_MFPH_PB13MFP_Msk | SYS_GPB_MFPH_PB15MFP_Msk);
SYS->GPB_MFPH |= SYS_GPB_MFPH_PB13MFP_ADC0_CH10 | SYS_GPB_MFPH_PB15MFP_ADC0_CH12;
}
void ADC_IRQHandler(void)
{
g_u32AdcIntFlag = 1;
ADC_CLR_INT_FLAG(ADC, ADC_ADF_INT); /* clear the A/D conversion flag */
} 20
ADC Sample Code – Main(I)
int main (void)
{
……
/* Set the ADC operation mode as single, input mode as single-end and enable the analog input channel 12 */
ADC_Open(ADC, ADC_ADCR_DIFFEN_SINGLE_END, ADC_ADCR_ADMD_SINGLE, BIT12);
/* Power on ADC module */
ADC_POWER_ON(ADC);
/* Clear the A/D interrupt flag for safe */
ADC_CLR_INT_FLAG(ADC, ADC_ADF_INT);
/* Enable the ADC interrupt */
ADC_EnableInt(ADC, ADC_ADF_INT);
NVIC_EnableIRQ(ADC_IRQn);
/* Reset the ADC interrupt indicator and Start A/D conversion */
g_u32AdcIntFlag = 0;

21
ADC Sample Code – Main(II)
while(1)
{
/* start ADC */
ADC_START_CONV(ADC);
while(g_u32AdcIntFlag == 0);

/* Get the conversion result of the ADC channel 12 */


i32ConversionData = ADC_GET_CONVERSION_DATA(ADC, 12);
printf("Conversion result of channel 12: 0x%X (%d)\n", i32ConversionData, i32ConversionData);

g_u32AdcIntFlag = 0;
/* Delay 100 ms for next conversion */
CLK_SysTickDelay(100000);
}
}

22
Thank you!

You might also like