The Analog to Digital Converter (ADC)

Similar documents
Additional Timer Functionalities. Capture, Compare, PWM

Using the Digital I/O interface of STMicroelectronics STM32 Microcontrollers

Using the Special Function Registers of the Digital I/O interface of STM32

Using the Special Function Registers of the Digital I/O interface of STM32

The I2C BUS Interface

Introduction to L.A.P. 1

Handling Asynchronous Events in MCUs A Light Keyboard Driver

Using Timers of Microchip PIC18F Microcontrollers

The Serial Peripheral Interface

The Controller Area Network (CAN) Interface

Implementation of Temperature Sensor on PICM4520 Microcontroller

ADC: Analog to Digital Conversion

ATMEGA32 MUSIC PLAYER

AN5181. Building a thermometer using the STM8 Nucleo-64 boards. Application note. Introduction

Embedded Systems and Software

Bachelor of Engineering in Computer and Electronic Engineering

Microcontroller Introduction

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

Design of analog acquisition and storage system about airborne flight data recorder

CN310 Microprocessor Systems Design

Digital Input and Output

OPERATIONAL AMPLIFIER

OPERATIONAL AMPLIFIER

Hello, and welcome to this presentation of the STM32 general-purpose IO interface. It covers the general-purpose input and output interface and how

Section 16. Analog-to-Digital Converter (ADC)

X-NUCLEO-53L0A1 ranging and gesture detection sensor expansion board based on VL53L0X for STM32 Nucleo

Getting started with X-NUCLEO-53L1A1 long distance ranging ToF sensor expansion board based on VL53L1X for STM32 Nucleo

NUC123xxxAN Series Errata Sheet. Errata Sheet for 32-bit NuMicro Family Rev May 19, 2016

STM32 Ecosystem workshop. T.O.M.A.S Team

Processor and compiler dependent

ED1021 I/O Expander with UART interface & analog inputs

AN116. Power Management Techniques and Calculation. Introduction. Key Points. Power Saving Methods. Reducing System Clock Frequency

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI. Laboratory Lesson 2: - General Purpose I/O - SysTick

Embedded Systems Programming and Architectures

Interconnects, Memory, GPIO

Logic Programming with PROFETA

Grove - I2C ADC. Introduction. Features

TEVATRON TECHNOLOGIES PVT. LTD Embedded! Robotics! IoT! VLSI Design! Projects! Technical Consultancy! Education! STEM! Software!

CHAPTER 5. Voltage Regulator

8051 Microcontroller Interrupts

STM32F1xx motor-control firmware for dspin. Quick guide

RTC Interface 89C51 DS M. Krishna Kumar MAM/M7/LU17/V1/ Vcc VCC 5 SDA P1.0 6 SCL P KHz 3 BAT 3.

Developing and Debugging C Programs in MDK-ARM for the STM32L100RC Microcontroller

EZ-Red Power I/O module for PC See for other manuals

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI

XNUCLEO-F030R8, Improved STM32 NUCLEO Board

Hands-On with STM32 MCU Francesco Conti

ARM HOW-TO GUIDE Interfacing Switch with LPC2148 ARM

SPIRIT. Phase 5 Analog Board Computer and Electronics Engineering

Using the HT16K33 in DVD Player Panel Applications

Lecture 1. Course Overview and The 8051 Architecture

AN4515 Application note

STG - STM32 + FreeRTOS + LwIP/EmWin

ED1021 I/O Expander with UART interface & analog inputs

Basic and Practice in Programming Lab7

ELEC 3040/3050 Lab Manual Lab 2 Revised 8/20/14. LAB 2: Developing and Debugging C Programs in MDK-ARM for the STM32L100RC Microcontroller

F²MC-8FX FAMILY MB95200H/210H SERIES HOW TO USE DBG PIN 8-BIT MICROCONTROLLER APPLICATION NOTE

ECG (EKG) Primer Jingxi Zhang ABSTRACT

Dynamic Data Structures. CSCI 112: Programming in C

HT95R6x CPT (Call Progress Tone) Decoder Function

F²MC-8FX FAMILY MB95200H/210H SERIES HOW TO USE DBG PIN 8-BIT MICROCONTROLLER APPLICATION NOTE

ILI2312. ILI2312 Single Chip Capacitive Touch Sensor Controller. Specification ILI TECHNOLOGY CORP. Version: V1.03.

UM1724 User manual. STM32 Nucleo-64 boards. Introduction

M68HC08 Microcontroller The MC68HC908GP32. General Description. MCU Block Diagram CPU08 1

Four-Channel Universal Analog Input Using the MAX11270

IME-100 ECE. Lab 4. Electrical and Computer Engineering Department Kettering University. G. Tewolde, IME100-ECE,

FT6x06. Self-Capacitive Touch Panel Controller INTRODUCTION FEATURES

INDUSTRIAL TRAINING:6 MONTHS PROGRAM TEVATRON TECHNOLOGIES PVT LTD

General Purpose Input/Output (GPIO)

Designing with STM32F2x & STM32F4

ILI2511. ILI2511 Single Chip Capacitive Touch Sensor Controller. Specification ILI TECHNOLOGY CORP. Version: V1.4. Date: 2018/7/5

ECE 492 WINTER 2015 GROUP 2. Texas Instruments MSP430-FR Bit ADC Setup Guide

MOTENC-Lite 4-Axis PCI Motion & I/O Control Board. Reference Manual Rev 1.1, June 20, Copyright 2005 VITAL Systems Inc

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

UM1724 User manual. STM32 Nucleo boards. Introduction

Using a Temperature Sensor

P-NUCLEO-53L0A1. VL53L0X Nucleo pack with ranging, gesture detection sensor expansion board and STM32F401RE. Description. Features

C Language Programming through the ADC and the MSP430 (ESCAPE)

Interface DAC to a PC. Control Word of MC1480 DAC (or DAC 808) 8255 Design Example. Engineering 4862 Microprocessors

AN5179. RS232 communications with a terminal using the STM8 Nucleo-64 boards. Application note. Introduction

Programming Microcontroller Assembly and C

LAMP CONTROL AND MONITOR WITH PPG AND ADC

UM1724 User manual. STM32 Nucleo boards. Introduction

Introduction to ARM LPC2148 Microcontroller

TMP89FS60FG Sample Program. Rev 1.0 Dec. 2007

SquareWear Programming Reference 1.0 Oct 10, 2012

ILI2303. ILI2303 Capacitive Touch Sensor Controller. Specification

Hello, and welcome to this presentation of the STM32 Touch Sensing Controller (TSC) which enables the designer to simply add touch sensing

Microcontrollers and Interfacing week 8 exercises

Software API Library. User s Manual V1.3

For reference only Refer to the latest documents for details

PAC52XX GPIO Peripheral Firmware Design

GRAVITECH GROUP

Functional block diagram AD53x1 (Analog Devices)

P-NUCLEO-6180X2. Proximity, gesture, ambient light sensor expansion board based on VL6180X for STM32L053R8. Description. Features

STM32 F4xx Discovery Board Setup Guide

256 channel readout board for 10x10 GEM detector. User s manual

CM-700 Technical Information

FT6336G. Self-Capacitive Touch Panel Controller INTRODUCTION FEATURES

AN3980 Application note

Transcription:

ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica - Università di Catania, Italy santoro@dmi.unict.it L.A.P. 1 Course

What is an ADC? An ADC (Analog-to-Digital-Converter) is a circuit which gets an analog voltage signal (as input) and provides (to software) a integer variable proportional to the input signal.

ADC Characteristics An ADC is characterised by: The voltage range of the input signal, V ref, V ref + the input signal must always be in the interval [V ref, V ref + ] The resolution in bits of the converter, NBITS. The ADC works by using a linear law: If V in = V ref, then ADCVAL = 0 If V in = V ref +, then ADCVAL = 2 NBITS 1 ADCVAL = [ ] (V in V ref ) 2NBITS 1 V ref + V ref

ADC Characteristics In general, V ref = 0 (GND) and V ref + = VDD (power supply voltage, i.e. 5 V or 3.3 V ) In our Nucleo board, VDD = 3.3 V therefore V ref + = 3.3 V In this case, the conversion law becomes: [ 2 NBITS ] 1 ADCVAL = V in 3.3

ADC: Basic working scheme The ADC is a sequential circuit that performs conversion using a sequence of steps: 1 Sample: the signal is sampled by closing the switch and charging the capacitor; the duration of this phase is denoted as T samp 2 Conversion: the switch is open and the sampled signal is converted; the result is stored in the 16-bit variable. The duration of this phase is denoted as T conv 3 End-of-conversion: a proper bit is set to signal that the operation has been done.

ADC inputs In general, an ADC has several inputs But only one input (channel) at time can be selected for conversion (through the multiplexer) To perform conversion, the software must: Select the input channel to be converted Start the conversion (by setting a proper bit in a SFR) Wait for the end-of-conversion (by checking a proper bit in a SFR), or being notified of the end-of-conversion through an IRQ

ADC inputs on STM32F401 In the STM32F401 MCU, ADC inputs share the same pin of GPIO ports In particular, some GPIO pins can be programmed in order to be served as analog input channel (and no more used as digital I/O): Pin Analog Channel Pin Analog Channel PA0 ADC1 IN0 PA1 ADC1 IN1 PA2 ADC1 IN2 PA3 ADC1 IN3 PA4 ADC1 IN4 PA5 ADC1 IN5 PA6 ADC1 IN6 PA7 ADC1 IN7 PB0 ADC1 IN8 PB1 ADC1 IN9 PC0 ADC1 IN10 PC1 ADC1 IN11 PC2 ADC1 IN12 PC3 ADC1 IN13 PC4 ADC1 IN14 PC5 ADC1 IN15

The Nucleo64 Addon Board (look at ADC settings)

ADC characteristics on STM32F4xx In the STM32F4xx MCUs, the ADCs have configurable resolution: 6 bits, range [0, 63] 8 bits, range [0, 255] 10 bits, range [0, 1023] 12 bits, range [0, 4095] The conversion result may be aligned left or right in the 16 bit result, e.g.: 12bit Left-Aligned b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0 0 0 0 0 12bit Right-Aligned 0 0 0 0 b11 b10 b9 b8 b7 b6 b5 b4 b3 b2 b1 b0

The Software interface of ADCs Each ADC has several special function registers All of them are accessible by means of global variables called ADCx, where x is the number of the adc (our micro has only ADC1) (ADC1, ADC2,...) The type of these variables is ADC TypeDef *, i.e. pointers to a structure whose field are the SFR of the ADC

stm32 unict lib Functions for ADCs Initialize an ADC: void ADC init(adc TypeDef * adc, int res, int align); adc, the ADC circuit res, the resolution in bits ADC RES 6 ADC RES 8 ADC RES 10 ADC RES 12 align, the bit alignment ADC ALIGN RIGHT ADC ALIGN LEFT

stm32 unict lib Functions for ADCs Configure the input(s): void ADC channel config(adc TypeDef * adc, GPIO TypeDef * port, int pin, int chan); adc, the ADC circuit port, the GPIO port of the input pin, the GPIO pin of the input chan, the ADC channel associated to the input Start an ADC circuit: void ADC on(adc TypeDef * adc); Stop an ADC circuit: void ADC off(adc TypeDef * adc);

stm32 unict lib Functions for ADCs Select a channel to convert: void ADC sample channel(adc TypeDef * adc, int chan); adc, the ADC circuit chan, the ADC channel to be converted Start a sample+conversion of the selected channel: void ADC start(adc TypeDef * adc); Check if a conversion has been completed: int ADC completed(adc TypeDef * adc); Read the converted value: int ADC read(adc TypeDef * adc);

Sampling the ADC and showing the value #include <stdio.h> #include "stm32_unict_lib.h" void main(void) { DISPLAY_init(); ADC_init(ADC1, ADC_RES_8, ADC_ALIGN_RIGHT); ADC_channel_config(ADC1, GPIOC, 0, 10); ADC_on(ADC1); ADC_sample_channel(ADC1, 10); for (;;) { ADC_start(ADC1); while (!ADC_completed(ADC1)) {} } } int value = ADC_read(ADC1); char s[4]; sprintf(s, "%4d", value); DISPLAY_puts(0,s);

Exercise: Let s flash a LED with a variable period We want to make a LED flash (with a timer) with a period ranging from 50 to 500 ms The period must be set using the trimmer in PC0/ADC1 IN10 Let s initialize the timebase of a timer to 0.5 ms The auto-reload value must be in the range [100, 1000] If we set the ADC to 8 bit, we can use the formula: 1000 100 ARR = ADCVAL + 100 255

LED flash with variable period #include <stdio.h> #include "stm32_unict_lib.h" int new_arr_value = 100; void main(void) { DISPLAY_init(); GPIO_init(GPIOB); GPIO_config_output(GPIOB, 0); ADC_init(ADC1, ADC_RES_8, ADC_ALIGN_RIGHT); ADC_channel_config(ADC1, GPIOC, 0, 10); ADC_on(ADC1); ADC_sample_channel(ADC1, 10); TIM_init(TIM2); TIM_config_timebase(TIM2, 42000, 100); TIM_set(TIM2, 0); TIM_enable_irq(TIM2, IRQ_UPDATE); TIM_on(TIM2); } for (;;) { ADC_start(ADC1); while (!ADC_completed(ADC1)) {} int value = ADC_read(ADC1); new_arr_value = value * 900/255 + 100; char s[4]; sprintf(s, "%4d", new_arr_value / 2); // we will display the milliseconds DISPLAY_puts(0,s); }

LED flash with variable period (II) void TIM2_IRQHandler(void) { if (TIM_update_check(TIM2)) { GPIO_toggle(GPIOB, 0); TIM_update_clear(TIM2); TIM2->ARR = new_arr_value; // update the autoreload register with new value } }

ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica - Università di Catania, Italy santoro@dmi.unict.it L.A.P. 1 Course