Embedded Systems Design Course Applying the mbed microcontroller

Similar documents
Embedded Systems Design Course Applying the mbed microcontroller

Pulse width modulation

Lesson 16 Analog-to-Digital Converter (ADC)

Embedded Systems Design Course Applying the mbed microcontroller

Conversion Between Analog and Digital Signals

Interfacing Analog to Digital Data Converters

DIGITAL-TO-ANALOGUE AND ANALOGUE-TO-DIGITAL CONVERSION

DAC Digital To Analog Converter

Pulse Width Modulation

Accurate Measurement of the Mains Electricity Frequency

HITACHI INVERTER SJ/L100/300 SERIES PID CONTROL USERS GUIDE

Lab Experiment 1: The LPC 2148 Education Board

SAMPLE CHAPTERS UNESCO EOLSS DIGITAL INSTRUMENTS. García J. and García D.F. University of Oviedo, Spain

Application Report. 1 Introduction. 2 Resolution of an A-D Converter. 2.1 Signal-to-Noise Ratio (SNR) Harman Grewal... ABSTRACT

Chapter 6: From Digital-to-Analog and Back Again

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

QUICK START GUIDE FOR DEMONSTRATION CIRCUIT BIT DIFFERENTIAL ADC WITH I2C LTC2485 DESCRIPTION

Designed & Developed By: Ms. Nidhi Agarwal. Under the Guidance of: Dr. SRN Reddy, Associate Professor, CSE. Computer Science & Engineering Department

PCM Encoding and Decoding:

Microcontroller to Sensor Interfacing Techniques

Analog-to-Digital Converters. Transducers

Analog to Digital Conversion of Sound with the MSP430F2013

EVAL-UFDC-1/UFDC-1M-16

Microcomputers. Analog-to-Digital and Digital-to-Analog Conversion

Disturbance Recoder SPCR 8C27. Product Guide

MCP4725 Digital to Analog Converter Hookup Guide

Measuring Resistance Using Digital I/O

DATA LOGGER AND REMOTE MONITORING SYSTEM FOR MULTIPLE PARAMETER MEASUREMENT APPLICATIONS. G.S. Nhivekar, R.R.Mudholker

Project Plan. Project Plan. May Logging DC Wattmeter. Team Member: Advisor : Ailing Mei. Collin Christy. Andrew Kom. Client: Chongli Cai

Current Loop Tuning Procedure. Servo Drive Current Loop Tuning Procedure (intended for Analog input PWM output servo drives) General Procedure AN-015

AC : PRACTICAL DESIGN PROJECTS UTILIZING COMPLEX PROGRAMMABLE LOGIC DEVICES (CPLD)

Analog signals are those which are naturally occurring. Any analog signal can be converted to a digital signal.

MSFET MICROSENS Miniature ph Sensor Module

Analog-to-Digital Converters

Digital To Analog Converter with Sine Wave Output

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

1. Oscilloscope is basically a graph-displaying device-it draws a graph of an electrical signal.

Microcontroller Programming Beginning with Arduino. Charlie Mooney

FFT Frequency Detection on the dspic

Lab 5 Getting started with analog-digital conversion

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

The modular concept of the MPA-3 system is designed to enable easy accommodation to a huge variety of experimental requirements.

Microcontroller-based experiments for a control systems course in electrical engineering technology

NETWORK ENABLED EQUIPMENT MONITOR

AN2680 Application note

Section 3. Sensor to ADC Design Example

AN3252 Application note

Digital Sampling Oscilloscope

Analog Representations of Sound

ADS9850 Signal Generator Module

BIODEX ADDENDUM BIODEX EMG/ANALOG SIGNAL ACCESS CONFIGURATION UTILITY SOFTWARE FOR SYSTEM 3 REVISION 2 AND SYSTEM 4 DYNAMOMETERS

PHY-2464 Physical Basis of Music

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

isppac-powr1220at8 I 2 C Hardware Verification Utility User s Guide

INTEGRATED CIRCUITS. For a complete data sheet, please also download:

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

UniPi technical documentation REV 1.1

Ultrasonic Distance Measurement Module

DS1621 Digital Thermometer and Thermostat

IR Communication a learn.sparkfun.com tutorial

Programmable Single-/Dual-/Triple- Tone Gong SAE 800

b 1 is the most significant bit (MSB) The MSB is the bit that has the most (largest) influence on the analog output

Digital to Analog and Analog to Digital Conversion

Android based Alcohol detection system using Bluetooth technology

Temperature Sensors. Resistance Temperature Detectors (RTDs) Thermistors IC Temperature Sensors

DS1621 Digital Thermometer and Thermostat

NTE2053 Integrated Circuit 8 Bit MPU Compatible A/D Converter

Digital Single Axis Controller

If an occupancy of room is zero, i.e. room is empty then light source will be switched off automatically

International Journal of Electronics and Computer Science Engineering 1588

HP03 BAROMETER MODULE Version: 1.1

Hideo Okawara s Mixed Signal Lecture Series. DSP-Based Testing Fundamentals 46 Per-pin Signal Generator

DS Wire Digital Thermometer and Thermostat

The Answer to the 14 Most Frequently Asked Modbus Questions

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

RPLIDAR. Low Cost 360 degree 2D Laser Scanner (LIDAR) System Development Kit User Manual Rev.1

25. AM radio receiver

User Guide FFFA

Fingerprint Based Biometric Attendance System

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

Step Response of RC Circuits

SYSTEM 45. C R H Electronics Design

Technical Manual. FAN COIL CONTROLLER COOLING or HEATING ANALOG or PWM Art A

[F/T] [5] [KHz] [AMP] [3] [V] 4 ) To set DC offset to -2.5V press the following keys [OFS] [+/-] [2] [.] [5] [V]

24-Bit Analog-to-Digital Converter (ADC) for Weigh Scales FEATURES S8550 VFB. Analog Supply Regulator. Input MUX. 24-bit Σ ADC. PGA Gain = 32, 64, 128

Massachusetts Institute of Technology

A+ Guide to Managing and Maintaining Your PC, 7e. Chapter 1 Introducing Hardware

Signal Processing in So.ware and Electric Field Sensing

1 Coffee cooling : Part B : automated data acquisition

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

A PC-BASED TIME INTERVAL COUNTER WITH 200 PS RESOLUTION

IO Expansion Module User & Installation Manual

Analogue Input, 4-fold, MDRC AE/S 4.1, GH Q R0001

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1

Transmitter Interface Program

How To Use An Ionsonic Microscope

Transcription:

Embedded Systems Design Course Applying the mbed microcontroller Analog input and output These course notes are written by R.Toulson (Anglia Ruskin University) and T.Wilmshurst (University of Derby). (c) ARM 2012 These course notes accompany the textbook Fast and effective embedded system design : Applying the ARM mbed 1

Analog input and output Introduction to analog signals and data Concepts of analog-to-digital conversion Analog inputs on the mbed Reading and logging data from analog inputs Concepts of digital-to-analog conversion Analog output with the mbed Generating output waveforms 2

Introduction to analog data Microcontrollers are often required to interface with analog signals They must be able to convert input analog signals, for example from microphone or temperature sensor, to digital data They must also be able to convert digital signals to analog form, for example if driving a loudspeaker or dc motor We will first consider conversion from analog-to-digital, before later looking at digital-to-analog conversion 3

Concepts of analog-to-digital conversion An analog-to-digital convertor (ADC) is an electronic circuit whose digital output is proportional to its analog input Effectively it "measures" the input voltage, and gives a binary output number proportional to its size The input range of the ADC is usually determined by the value of a voltage reference 4

Concepts of analog-to-digital conversion The conversion is started by a digital input, called here SC Voltage Reference + It takes finite time, and the ADC signals with the EOC line when the conversion is complete Analogue Input + - Analogue to Digital Converter Digital Output (n bits) The resulting data can then be enabled onto a data bus using the OE line SC EOC OE (Start Convert) (End of (Output Enable) Conversion) Example Control Lines 5

Concepts of analog-to-digital conversion The `staircase visible in a 3-bit ADC Digital Output 111 110 101 100 011 010 001 000 0 V max Analogue Input 6

Concepts of analog-to-digital Resolution and quantisation conversion By converting an analog signal to digital, we are effectively approximating it, as any one digital output value has to represent a very small range of analog input voltages, i.e. the width of any of the steps on the staircase n. If we want to convert an analog signal that has a range 0-3.3 V to an 8-bit digital signal, then there are 256 (i.e. 2 8 ) distinct output values. Each step has a width of 3.3/256 = 12.89 mv, and the worst case quantisation error is 6.45mV. The mbed uses a 12-bit ADC. This leads to a step width of 3.3/2 12, or 0.8 mv; the worst case quantisation error is therefore 0.4 mv. 7

Concepts of analog-to-digital Sampling frequency conversion When converting an analog signal to digital, we repeatedly take a sample and quantise this to the accuracy defined by the resolution of our ADC. The more samples taken, the more accurate the digital data will be. Samples are normally taken at fixed periods (i.e., every 0.2ms) and define the rate of sampling by the sampling frequency (the number of samples taken per second). 8

Concepts of analog-to-digital Sampling frequency conversion The sample frequency needs to be chosen with respect to the rate of which the sampled data is changing. If the sample frequency is too low then rapid changes in the analog signal may not be obvious in the resulting digital data. For this reason the Nyquist sampling criterion states that the sampling frequency must be at least double that of the highest frequency of interest. 9

Concepts of analog-to-digital conversion Digital sampling of an analog signal 10

Analog inputs on the mbed The mbed has up to six analog inputs, on pins 15 to 20 11

Analog-to-digital conversion on the mbed The library functions are shown in the table below AnalogIn Functions AnalogIn read read_u16 operator float An analog input, used for reading the voltage on a pin Usage Create an AnalogIn, connected to the specified pin Read the input voltage, represented as a float in the range [0.0, 1.0] Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF] operator float An operator shorthand for read() 12

Reading and logging data from analog inputs Exercise 1: Attach a potentiometer output to mbed pin 20. Start a new mbed project and enter the code below. This code will continuously display the analog input value when used with a host PC terminal application. //Reads input through the ADC, and transfers to PC terminal #include "mbed.h" Serial pc(usbtx, USBRX); AnalogIn Ain(p20); float ADCdata; int main() { pc.printf("adc Data Values... \n\r"); while (1) { ADCdata=Ain; pc.printf("%f \n\r",adcdata); wait (0.5); } } 13

Reading data from analog inputs Exercise 2: Using the four onboard mbed LEDs, write a program that will use a potentiometer input on pin 20 to continuously control how many LEDs are on. Use the following chart to define the LED control: Analog input value x LED1 LED2 LED3 LED4 x <= 0.2 0 0 0 0 0.2 < x <= 0.4 1 0 0 0 0.4 < x <= 0.6 1 1 0 0 0.6 < x <= 0.8 1 1 1 0 0.8 < x <= 1.0 1 1 1 1 14

Concepts of digital-to-analog conversion We can represent the digital-to-analog convertor (DAC) as a block diagram with a digital input, D, and an analog output, v o The output range of the DAC, v r, is the difference between the maximum and minimum output voltages, i.e. v r = v max - v min The particular output range is usually defined by a fixed voltage reference supplied to the DAC Digital control lines allow a microcontroller to setup and communicate with the DAC 15

Concepts of digital-to-analog conversion D (n-bit Digital input) + Digital to Analogue Converter Voltage Reference + - V O (Analog Output) For each digital value input to the DAC, there is a corresponding analog output value given by Control Lines 16

Concepts of digital-to-analog conversion The mbed s LPC1768 chip has a 10-bit DAC (i.e. n=10) The mbed uses its own 3.3 V power supply as voltage reference There will therefore be 2 n steps in the mbed DAC output characteristic, i.e. 1024 The step size, or resolution, is therefore be 3.3/1024, i.e. 3.2mV per bit 17

Digital-to-analog conversion on the mbed The mbed has a single analog output on pin 18 18

Digital to analog conversion on the mbed The library functions are shown in the table below AnalogOut Functions AnalogOut write write_u16 read operator= operator float() An analog output, used for setting the voltage on a pin Usage Create an AnalogOut connected to the specified pin Set the output voltage, specified as a percentage (float) Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF] Return the current output voltage setting, measured as a percentage (float) An operator shorthand for write() An operator shorthand for read() 19

Analog output with the mbed The mbed analog output on pin 18 is configured by the following declaration: AnalogOut Aout(p18); By default, the analog object takes a floating point number between 0.0 and 1.0 and outputs this to pin 18 The actual output voltage on pin 18 is between 0V and 3.3V, so the floating point number that is output as a voltage is scaled by a factor of 3.3 20

Analog output with the mbed Exercise 3: compile the program shown below and, using an oscilloscope, familiarise yourself with the analog output. #include "mbed.h" int main() { AnalogOut Aout(p18); while(1) { Aout=0.25; // 0.25*3.3V = 0.825V wait(1); Aout=0.5; // 0.5*3.3V = 1.65V wait(1); Aout=0.75; // 0.75*3.3V = 2.475V wait(1); } } 21

Analog output with the mbed Exercise 4: Now make a sawtooth wave and view it on an oscilloscope. Create a new program and enter the following code //Sawtooth waveform on DAC output to view on oscilloscope #include "mbed.h" AnalogOut Aout(p18); float i; int main() { while(1) { for (i=0;i<1;i=i+0.1) { Aout=i; wait(0.001); } } } 22

Analog output with the mbed Exercise 5: Modify your code to create a smoother sawtooth wave, by implementing finer steps in the for loop: Exercise 6: Create a smooth triangular wave by implementing a second loop to count down also: 23

Summary Introduction to analog signals and data Concepts of analog-to-digital conversion Analog inputs on the mbed Reading and logging data from analog inputs Concepts of digital-to-analog conversion Analog output with the mbed Generating output waveforms 24