Analog-to-Digital Converter (ADC)

Slides:



Advertisements
Similar presentations
Jordan Barry Victor Brzeski
Advertisements

Analog to Digital Conversion (ADC)
10-1 Bard, Tiwari, Telang, Janapa Reddi, Gerstlauer, Valvano, Yerraballi EE 319K Introduction to Embedded Systems Lecture 10: Sampling, Analog-to-Digital.
Analog Comparator Positive input chooses bet. PB2 and Bandgap Reference. Negative input chooses bet. PB3 and the 8 inputs of the A/D. ACME= Analog Comparator.
Lecture 9: D/A and A/D Converters
AD Converter UNIT 19 로봇 SW 교육원 조용수. 학습 목표 AD Converter AD Converter Register 2.
Lecture 12 Analog to Digital Converters. 2  What is an ADC?  Output vs. input  Input range  Single-ended vs. differential inputs  Output coding:
5-1 Analogue Input/Output Many sensors/transducers produce voltages representing physical data.  To process transducer data in a computer requires conversion.
Academic Workshop Lab Measuring Temperature with Thermistors.
Explain the introduction to ADC, ADC characteristics, Programming ADC using PIC18, Introduction to DAC and DAC interfacing with PIC18.
ECT 357 Ch 10 Analog to Digital COnversion. Today’s Quote: It’s better to die with a good name than to live with a bad one. It’s better to die with a.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
DEEPAK.P MICROPROCESSORS AND APPLICATIONS Mr. DEEPAK P. Associate Professor ECE Department SNGCE 1.
Department of Electrical Engineering, National Taiwan Ocean University NuMicro Learning Board Introduction 1/29/2015 Richard Kuo Assistant.
Pulse Width Modulation
Renesas Electronics Europe GmbH A © 2010 Renesas Electronics Corporation. All rights reserved. RL78 Clock Generator.
2/26/2015 Richard Kuo Assistant Professor
ARM Timers.
Digital to Analogue Converter
Department of Electrical Engineering, National Taiwan Ocean University Analog-to-Digital Converter (ADC) 4/18/2013 Richard Kuo Assistant.
ELN5622 Embedded Systems Class 7 Spring, 2003 Aaron Itskovich
UART: Universal Asynchronous RX/TX
Renesas Electronics Corporation © 2010 Renesas Electronics America Inc. All rights reserved. RX 12 Bit Analog-to-Digital Converter A Rev /1/10.
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Module Introduction Purpose  This training module provides an overview of the analog interfaces.
3/23/2015 Richard Kuo Assistant Professor
Suleyman Demirel University CSS340 Microprocessor Systems – Lecture 2 ATMEGA328P ARCHITECTURE ANALOG INPUTS.
The Silicon Laboratories C8051F020
Analog Capture- Port E. Digital to Analog and Analog to Digital Conversion D/A or DAC and A/D or ADC.
By James Cockrell and Justin Loveless
Analog/Digital Conversion
Lab 3: ADC.
Analog to Digital Converter (ADC)
Embedded Systems Design 1 Lecture Set C Interfacing the MCS-51 to: –D/A Converter –A/D Converter.
0808/0809 ADC. Block Diagram ADC ADC0808/ADC Bit μP Compatible A/D Converters with 8-Channel Multiplexer The 8-bit A/D converter uses successive.
AAPT workshop W03 July 26, 2014 Saint Cloud State University, MN, USA
EKT 314/4 WEEK 9 : CHAPTER 4 DATA ACQUISITION AND CONVERSION ELECTRONIC INSTRUMENTATION.
1 Lab 4: D/A Converter Lab 4: D/A Converter This is a simple resistive network for a D/A converter Port 1, Port 0 are digital inputs ==> 00 (minimum),
EE 319K Introduction to Embedded Systems
Outline Introduction to NuMaker TRIO Programming environment setup
Serial Peripheral Interface
Application Case Study Security Camera Controller
Outline Analog to digital conversion (ADC) of NuMaker TRIO
SAR ADC Input Types TIPL 4003 TI Precision Labs – ADCs
Pulse Width Modulation
Cortex-M0 MCU Clocks & Pins
Analog-Digital Conversion
ECE 3430 – Intro to Microcomputer Systems
NuMicro MCU New Project Express Creation
Prof. Chung-Ta King Department of Computer Science
CS4101 Introduction to Embedded Systems Lab 9: NuMaker ADC and LCD
ADC, DAC, and Sensor Interfacing
Engineering 4862 Microprocessors Lecture 25
ADC, DAC, and Sensor Interfacing
Created by Luis Chioye Presented by Cynthia Sosa
Simple ADC structures.
ECE 354 Computer Systems Lab II
Simple ADC structures.
ADC, DAC, and Sensor Interfacing
CSE 171 Lab 11 Digital Voltmeter.
Digital Control Systems Waseem Gulsher
PIC18F458 Analog-to-Digital
ADC and DAC Programming in AVR
ADC and DAC Data Converter
MSP432™ MCUs Training Part 6: Analog Peripherals
ECE 3430 – Intro to Microcomputer Systems
Prof. Chung-Ta King Department of Computer Science
UNIT 5 Analog signals.
Chapter 7 Converters.
ADC and DAC Data Converter
ECE 3567 Microcontroller Lab
Presentation transcript:

Analog-to-Digital Converter (ADC) 1/20/2017 Richard Kuo Assistant Professor

Outline 6.0 NuMicro_ADC.ppt Analog-to-Digital Converter Introduction Lab. ADC Single_Cycle mode (ADC) Lab. ADC Continuous mode (ADC_4ch) Lab. To read Variable Resistor (ADC_VR1) Lab. To read Photoresistor (ADC_Photoresistor) Lab. To read Thermistor (ADC_Thermistor) Lab. To read Joystick (ADC_Joystick) Lab. ADC Triggered by PWM (ADC_Trigger)

Signal Conversion ADC DAC Filter

Analog to Digital Conversion

Digital Conversion Vin is input voltage for ADC to sample Vref is reference voltage for ADC to compare with Vin Vref is connected to 3.3V on NUC140 learning board 12-bit ADC : output is a 12-bit binary code, so its value = 0 ~ 4095 Decimal Binary Voltage (Vref=3.3V) 0000_0000_0000 0/4096 * 3.3V 1 0000_0000_0001 1/4096 * 3.3V 2048 1000_0000_0000 2048/4096 * 3.3V 4095 1111_1111_1111 4095/4096 * 3.3V

ADC Architectures Direct-Conversion ADC SAR (Successive Approximation Register) ADC ΔΣ (Sigma-Delta) ADC Sigma-Delta ADC SAR ADC Successive Approximation Register Direct-Conversion ADC

SAR (Successive Approximation Register) ADC End-Of-Conversion clock N-bit DAC Vref Comparator - + Sample & Hold Vin

ADC specification 12-bit SAR ADC (10-bit accuracy) Analog input voltage range: 0~Vref (Max to 5.0V). Operation voltage: AVDD=3.0V~5.5V; Input channel: Up to 8 single-end analog input channels 4 pairs of differential analog input channel. NUC140 = Up to 800KSPS, NANO102 up to 1MSPS The maximum ADC operating frequency is 16M Hz Three ADC operation modes Single mode Single-cycle mode Continuous mode

ADC pins configuration The ADC input pins share with GPIO group A The ADC input pins must be configured in input type Single-end input mode ADC0 ~ ADC7 = PA0~PA7 Differential input mode ADC0 ~ ADC3 Differential input channels are the paired channels Differential input paired channel Single-end input channel 1 2 3 4 5 6 7

ADC Clock Source NUC100

ADC Clock Selection (in SYS_init.c) void CLK_SetModuleClock( uint32_t u32ModuleIdx, uint32_t u32ClkSrc, uint32_t u32ClkDiv) ADC Clock Source CLK_CLKSEL1_ADC_S_HXT CLK_CLKSEL1_ADC_S_LXT CLK_CLKSEL1_ADC_S_PLL CLK_CLKSEL1_ADC_S_HCLK CLK_CLKSEL1_ADC_S_HIRC ADC Clock Divider CLK_CLKDIV_ADC(x) Module Index = ADC Clock Source Clock Divider ADC clock 8-bit divider = x

ADC Sample Modes Single Mode Single-Cycle Mode Continuous Mode

ADC Single mode

ADC Single-Cycle mode

ADC Continuous mode

ADC Initialization (in adc.c) void ADC_Open(ADC_T *adc, uint32_t u32InputMode, uint32_t u32OpMode, uint32_t u32ChMask) ADC input mode ADC_INPUT_MODE_SINGLE_END ADC_INPUT_MODE_DIFFERENTIAL ADC operation mode ADC_OPERATION_MODE_SINGLE ADC_OPERATION_MODE_SINGLE_CYCLE ADC_OPERATION_MODE_CONTINUOUS ADC struct pointer ADC input mode ADC operation mode ADC channel

NuMicro Cortex-M0 Learning Board ADC reference voltage is VCC33 (3.3V) ADC0~7(GPA0~7) VR1

ADC Sample Codes ADC : Single Cycle Conversion ADC_8ch : Continuous Conversion ADC_Photoresistor : ADC0 reading sensors (GL5516, MQ7, UVM30) ADC_Thermistor : ADC1 reading thermistor & calculate temperature ADC_Joystick : ADC0 & ADC1 reading Joystick

ADC (Single Cycle Mode) MCU_init.h (chip initialization setting) //Define Clock source #define MCU_CLOCK_SOURCE #define MCU_CLOCK_SOURCE_HIRC // HXT, LXT, HIRC, LIRC #define MCU_CLOCK_FREQUENCY 50000000 //Hz //Define MCU Interfaces #define MCU_INTERFACE_ADC #define ADC_CLOCK_SOURCE_HIRC // HXT, LXT, PLL, HIRC, HCLK #define ADC_CLOCK_DIVIDER 1 #define PIN_ADC_0 #define PIN_ADC_1 #define PIN_ADC_2 #define PIN_ADC_3 #define ADC_CHANNEL_MASK ADC_CH_0_MASK | ADC_CH_1_MASK | ADC_CH_2_MASK | ADC_CH_3_MASK #define ADC_INPUT_MODE ADC_INPUT_MODE_SINGLE_END // SINGLE_END, DIFFERENTIAL #define ADC_OPERATION_MODE ADC_OPERATION_MODE_SINGLE_CYCLE // SINGLE, SINGLE_CYCLE, CONTINUOUS CPU clock maximum frequency ADC Single Cycle Conversion

ADC volatile uint8_t u8ADF; void ADC_IRQHandler(void) { ADC Flag for main loop to detect when ADC sample finished and ADC interrupt is generated volatile uint8_t u8ADF; void ADC_IRQHandler(void) { uint32_t u32Flag; // Get ADC conversion finish interrupt flag u32Flag = ADC_GET_INT_FLAG(ADC, ADC_ADF_INT); if(u32Flag & ADC_ADF_INT) u8ADF = 1; ADC_CLR_INT_FLAG(ADC, u32Flag); } Set ADC software flag when IRQ ocurrs

ADC void Init_ADC(void) { ADC_Open(ADC, ADC_INPUT_MODE, ADC_OPERATION_MODE, ADC_CHANNEL_MASK); // set ADC modes & channels ADC_POWER_ON(ADC); // Power on ADC ADC_EnableInt(ADC, ADC_ADF_INT); // Enable ADC ADC_IF interrupt NVIC_EnableIRQ(ADC_IRQn); // Enable CPU NVIC } Define in MCU_init.h

ADC int32_t main (void) { int i; uint32_t u32Result; SYS_Init(); Init_ADC(); printf("\n\nCPU @ %dHz\n", SystemCoreClock); u8ADF = 0; while(1) { ADC_START_CONV(ADC); // start ADC conversion while (u8ADF == 0); // wait for ADC sampling finished & generate interrupt to set this flag to 1 // read ADC result & print it for (i=0; i<4; i++) { u32Result = ADC_GET_CONVERSION_DATA(ADC, i); printf("ADC%d = %d, ",i, u32Result); } printf("\n"); u8ADF =0; // clear the flag start ADC conversion Check flag from ADC IRQHandler clear ADC software flag when ADC result is printed

ADC_4ch (Continuous Mode) MCU_init.h (chip initialization setting) //Define Clock source #define MCU_CLOCK_SOURCE #define MCU_CLOCK_SOURCE_HIRC // HXT, LXT, HIRC, LIRC #define MCU_CLOCK_FREQUENCY 50000000 //Hz //Define MCU Interfaces #define MCU_INTERFACE_ADC #define ADC_CLOCK_SOURCE_HIRC // HXT, LXT, PLL, HIRC, HCLK #define ADC_CLOCK_DIVIDER 1 #define PIN_ADC_0 #define PIN_ADC_1 #define PIN_ADC_2 #define PIN_ADC_3 #define ADC_CHANNEL_MASK ADC_CH_0_MASK | ADC_CH_1_MASK | ADC_CH_2_MASK | ADC_CH_3_MASK #define ADC_INPUT_MODE ADC_INPUT_MODE_SINGLE_END // SINGLE_END, DIFFERENTIAL #define ADC_OPERATION_MODE ADC_OPERATION_MODE_CONTINUOUS // SINGLE, SINGLE_CYCLE, CONTINUOUS CPU clock maximum frequency ADC Continuous Conversion Mini51/54/58 only support Single mode conversion

ADC_4ch volatile uint32_t u32ADCvalue[4]; void ADC_IRQHandler(void) { uint8_t i; uint32_t u32Flag; // Get ADC conversion finish interrupt flag u32Flag = ADC_GET_INT_FLAG(ADC, ADC_ADF_INT); if(u32Flag & ADC_ADF_INT) { for (i=0; i<4; i++) { u32ADCvalue[i] = ADC_GET_CONVERSION_DATA(ADC, i); printf("ADC%d = %4d, ",i, u32ADCvalue[i]); } printf("\n"); ADC_CLR_INT_FLAG(ADC, u32Flag); check ADC interrupt flag read ADC value clear ADC interrupt flag

ADC_4ch void Init_ADC(void) { ADC_Open(ADC, ADC_INPUT_MODE, ADC_OPERATION_MODE, ADC_CHANNEL_MASK); ADC_POWER_ON(ADC); ADC_EnableInt(ADC, ADC_ADF_INT); NVIC_EnableIRQ(ADC_IRQn); ADC_START_CONV(ADC); } int32_t main (void) SYS_Init(); Init_ADC(); while(1); start ADC conversion once when using Continous Mode When ADC finish its conversion, ADC interrupt will occur, ADC_IRQHandler will print out ADC value

Gas Sensor

CO gas sensor - MQ7

CO gas sensor - MQ7 CO

UV Sensor - UVM-30

IR Ranger - GP2Y0A41SK0F 0.4V ~ 3V 30cm ~ 3cm every 5ms

IR Ranger : Distance vs Output voltage

Photoresistor (GL5516)

Photoresistor Connection Diagram Learning Board Vcc3.3V pullup resistor 10Kohm Measure the resistance for calibration in main.c ADC6 (GPA6) Photoresistor 0~10Kohm Gnd Sample Code : ADC_Photoresistor

ADC_Photoresistor get ADC value & print it void ADC_IRQHandler(void) { uint32_t u32Flag; uint32_t u32ADCvalue; // Get ADC conversion finish interrupt flag u32Flag = ADC_GET_INT_FLAG(ADC, ADC_ADF_INT); if(u32Flag & ADC_ADF_INT) { u32ADCvalue = ADC_GET_CONVERSION_DATA(ADC, 0); printf("ADC0= %4d\n",u32ADCvalue); } ADC_CLR_INT_FLAG(ADC, u32Flag); get ADC value & print it

ADC_Photoresistor define in MCU_init.h void Init_ADC(void) { ADC_Open(ADC, ADC_INPUT_MODE, ADC_OPERATION_MODE, ADC_CHANNEL_MASK); ADC_POWER_ON(ADC); ADC_EnableInt(ADC, ADC_ADF_INT); NVIC_EnableIRQ(ADC_IRQn); ADC_START_CONV(ADC); } int32_t main (void) SYS_Init(); Init_ADC(); printf("ADC ch0 reading sensor\n"); while(1); define in MCU_init.h

Thermistor NTC Thermistor : Negative Temperature Coefficient temperature rising will decrease resistance B or β parameter equation log(R) = log(R0) + B * (1/T – 1/T0) 1/T = 1/T0 + (log(R) – log(R0)) / B T = 1 / (1/T0 + (log(R) – log(R0)) /B) Temperature Calculation

Thermistor Connection Diagram Learning Board Vcc3.3V pullup resistor 10Kohm Measure the resistance for calibration in main.c ADC6 (GPA6) thermistor 0~10Kohm Gnd Sample Code : smpl_ADC_Thermistor

ADC_Thermistor thermistor pullup resistor

ADC_Thermistor Resistance to Temperature calculation void Thermistor(int16_t ADCvalue) { double T, Temp; double T0 = 301.15; // 273.15 + 28 double lnR; int16_t R; // Thermistor resistence int16_t R0 = 8805; // calibrated by reading R at 28 degree celsius int16_t B = 3950; int16_t Pullup = 9930; // 10K ohm // R / (Pullup + R) = adc / 4096 R = (Pullup * ADCvalue) / (4096 - ADCvalue); // B = (log(R) - log(R0)) / (1/T - 1/T0) T = 1 / (1/T0 + (log(R)-log(R0)) / B ); Temp = T - 273.15; printf("ADC:%4d, R=%d, Temp.=%f\n", ADCvalue, R, Temp); } Resistance to Temperature calculation

ADC_Joystick

ADC_Joystick using 2 channels AD0 & ADC1 to read joystick X & Y value void ADC_IRQHandler(void) { uint32_t u32Flag; u32Flag = ADC_GET_INT_FLAG(ADC, ADC_ADF_INT); if(u32Flag & ADC_ADF_INT) { X = ADC_GET_CONVERSION_DATA(ADC, 0); Y = ADC_GET_CONVERSION_DATA(ADC, 1); } ADC_CLR_INT_FLAG(ADC, u32Flag); void Init_ADC(void) ADC_Open(ADC, ADC_INPUT_MODE, ADC_OPERATION_MODE, ADC_CHANNEL_MASK ); ADC_POWER_ON(ADC); ADC_EnableInt(ADC, ADC_ADF_INT); NVIC_EnableIRQ(ADC_IRQn); ADC_START_CONV(ADC); using 2 channels AD0 & ADC1 to read joystick X & Y value

PWM Trigger ADC Sampling

ADC Conversion Trigger Sources (Nano100)

ADC Driver function call (adc.c) void ADC_EnableHWTrigger(ADC_T *adc, uint32_t u32Source, uint32_t u32Param) ADC HW Trigger Source ADC_ADCR_TRGS_STADC ADC_ADCR_TRGS_PWM ADC STADC Trigger Mode ADC_ADCR_TRGCOND_LOW_LEVEL ADC_ADCR_TRGCOND_HIGH_LEVEL ADC_ADCR_TRGCOND_FALLING_EDGE ADC_ADCR_TRGCOND_RISING_EDGE ADC struct pointer ADC HW Trigger Source ADC STADC Trigger Mode Triggered by External pin STADC Triggered by PWM

Project : Plant Care Function : use ADC to read Moisture & pH Platform : http://goods.ruten.com.tw/item/show?21006164261964 Example : http://youtu.be/TPE6D7xjKXo Demo : http://youtu.be/OXeeFVVFSlg

Important Notice ! This educational material are neither intended nor warranted for usage in systems or equipment, any malfunction or failure of which may cause loss of human life, bodily injury or severe property damage. Such applications are deemed, “Insecure Usage”. Insecure usage includes, but is not limited to: equipment for surgical implementation, atomic energy control instruments, airplane or spaceship instruments, the control or operation of dynamic, brake or safety systems designed for vehicular use, traffic signal instruments, all types of safety devices, and other applications intended to support or sustain life. All Insecure Usage shall be made at user’s own risk, and in the event that third parties lay claims to the author as a result of customer’s Insecure Usage, the user shall indemnify the damages and liabilities thus incurred by using this material. Please note that all lecture and sample codes are subject to change without notice. All the trademarks of products and companies mentioned in this material belong to their respective owners.

References Analog-to-digital converter - Wikipedia, the free encyclopedia Flash ADC - Wikipedia, the free encyclopedia Understanding SAR ADCs: Their Architecture and Comparison with ... TI High Speed Analog to Digital Converter Basics http://en.wikipedia.org/wiki/Delta-sigma_modulation http://www.beis.de/Elektronik/DeltaSigma/DeltaSigma.html

Digital to Analog Converter (DAC) Binary-Weighted Resistor DAC ΔΣ DAC (Sigma-Delta DAC) R-2R Ladder DAC Vout =   - (Vmsb + Vn + Vlsb) = - (Vref + Vref/2 + Vref/ 4)