嵌入式系统代写代做代考 Embedded Systems Reconfigurable computing

Reconfigurable computing

Small Embedded Systems

Unit 2.6 Analogue Input

Introduction
So far we have looked at simple circuits using mechanical buttons to switch an LED fully on or off
In this unit we look at analogue input:
Reading analogue signals
Analog to Digital Conversion
Resolution of ADCs

Analogue and Digital
Analogue electronics uses voltages that are proportional to the parameter of interest
Digital electronics just categorises voltages into one of two levels: High and Low
Gives us good immunity to noise, signal degradation, component parameter drift…
A single bit can’t represent continuous physical values all by itself
Groups of bits are used to form encodings of continuous values
binary number coding can represent a wide numerical range with good resolution if enough bits are used

Interfacing to Sensors and Actuators
Some sensors produce analog output (normally voltage)
Microcontroller uses ADC to digitise output
Others will internally digitise the measurement and store a digital value in a register
This is accessed by the microcontroller using a serial communications bus to interrogate the registers
The usual serial comms links are:
SPI: Serial Peripheral Interface
I2C: Inter-integrated circuit

Conversion to digital form
Analogue-to-digital converter (ADC) converts input voltage to output binary number
Digital-to-analogue converter (DAC) performs conversions in the opposite direction
0V
VREF
Time
111
110
101
100
011
010
001
000

Time
ADC

Conversion to digital form
ADCs are characterised by how many bits they use for their code points
This example is 3-bit
Range of voltages converted is set through reference voltage VREF

0V
VREF
Time
111
110
101
100
011
010
001
000

Time
ADC

1.75 V
1.50 V
1.25 V
1.00 V
0.75 V
0.50 V
0.25 V
0 V
Quantisation error
Example
We use a 3-bit ADC
We set VREF = 2V
The binary numbers have the following meaning:
0 V
VREF
Time
111
110
101
100
011
010
001
000

Time
ADC

Zoom in

1.75 V
1.50 V
1.25 V
1.00 V
0.75 V
0.50 V
0.25 V
0 V
Quantisation error
Example
We use a 3-bit ADC
We set Vmin=0
We set Vmax=1.75V
The binary numbers have the following meaning:
111
110
101
100
011
010
001
000

Time

Zoom in
011
010
001
000
Time

0.50 V
0.25 V
0.00 V

Quantisation error
Binary values are quantised: resolution is the size of the steps, in this case 0.25 V
Binary values can’t exactly follow continuous input value
Difference is quantisation error
011
010
001
000
Time
Quantisation error
Input value
Quantised output
0.50 V
0.25 V
0.00 V

Quantisation error
The maximum error is half the voltage step
In this case, 0.125 V
011
010
001
000
Time
Quantisation error
Input value
Quantised output
0.50 V
0.25 V
0.00 V

Quantisation error
The maximum error is half the voltage step
In this case, 0.125 V
If we use 4-bits instead of 3
Resolution is twice as good
Quantisation error is halved

Time
Quantisation error
Input value
Quantised output
0.50 V
0.25 V
0.00 V
0000
0001
0010
0011
0100

Quantisation error
In general, for n-bit ADC step size is

Maximum quantisation error is

By using enough bits we can make the quantisation error negligibly small
There are other sources of noise and error in the electronics, so quantisation error is not the same as the total error

Generalised Quantisation Error
Assuming a 0-2 V signal, each resolution step would be:

Bitwidth Resolution (V) Max error (V)
4 0.125 0.0625
6 0.03125 0.015625
8 0.0078125 0.00390625
10 0.001953125 0.0009765625
12 0.0004882813 0.0002441406
16 0.0000305176 0.0000152588
32 0.0000000005 0.0000000002

Example
An embedded system is to be developed that acquires acceleration data from a 10 g accelerometer with a 100 ms-2 range. The system will use a microcontroller with a 10-bit analogue to digital converter (ADC).
If the output of the accelerometer is 0-5 V, what is the maximum resolution of the ADC in volts?

Resolution = 5/210 = 5 mV

Calculate the maximum error of the system in metres per second-squared (ms-2)

Maximum Error = 100/211 = 0.05 ms-2

 

ATmega 328P

ESP8266
General Purpose Input Output GPIO

Many microcontrollers have integrated (ADC)
Arduino number ADC pins as A0 (, A1, A2, …)

6 inputs can be switched to 10-bit ADC
VREF defaults to 5V, but other values can be selected using AREF pin
Single 10-bit ADC input
VREF is 1V
Voltages should not exceed 1V

General Purpose Input Output GPIO
Many microcontrollers have integrated (ADC)
Arduino number ADC pins as A0 (, A1, A2, …)
Arduino function to read analog pin is

Value is a number in range 0 to 1023
Zero volts is value of 0
VREF would be a value of 1024
int value = analogRead(A0);

Reading from device to Arduino
float vref = 5.0;

void setup() {
pinMode(A0,INPUT);
Serial.begin(9600);
}

void loop() {
int val = analogRead(A0);
Serial.println(vref*val/1024.0);
delay(1000);
}
Code to read analog value and display it on host PC
Default VREF for Arduino Uno
Print voltage to terminal

ATmega 328 ADC

VREF selection
(Default is VCC)
Input pin select multiplex
Successive approximation ADC
Control registers
Data output register

Successive Approximation ADC
One of the input channels is multiplexed through to the ADC
Say the voltage on this input pin is 3.6V and VREF=5V

Conversion logic

10-bit DAC

Sample & hold comparator


+
VREF

3.6 V
5 V
3.6 V

Successive Approximation ADC
Conversion logic starts with initial guess 1000000000
Half of the available range
This converts to 2.5V (half of VREF)
The comparator confirms that the input voltage is bigger

Conversion logic

10-bit DAC

Sample & hold comparator


+
VREF

3.6 V
5 V
3.6 V
2.5 V
Bigger

Successive Approximation ADC
Now conversion logic sets next bit to 1 to give 1100000000
¾ of the available range
This converts to 3.75V (¾ of VREF)
The comparator confirms that the input voltage is smaller

Conversion logic

10-bit DAC

Sample & hold comparator


+
VREF

3.6 V
5 V
3.6 V
3.75 V
Smaller

Successive Approximation ADC
Conversion logic resets bit 8 to 0 and tries bit 7 set to 1:
Next iteration is 1010000000
of the available range
This converts to 3.125 V ( of VREF)

Conversion logic

10-bit DAC

Sample & hold comparator


+
VREF

3.6 V
5 V
3.6 V
3.125 V
Bigger

Successive Approximation ADC
First 3 bits are correct: 1010000000
Keep going for remaining bits
Full conversion takes many cycles of ADC clock
13 cycles for ATmega 328P

Conversion logic

10-bit DAC

Sample & hold comparator


+
VREF

3.6 V
5 V
3.6 V
3.125 V
Bigger

VREF Selection

The ADC’s VREF is selectable:
VCC power supply voltage (5V on Arduino Uno)
External reference voltage supplied on input pin AREF
Internally generated 1.1V bandgap reference
Conversion logic

10-bit DAC

Sample & hold comparator


+
VREF

VREF Selection

VREF is set using analogReference() Arduino library function
analogReference(DEFAULT)
sets VREF to power supply voltage VCC
analogReference(INTERNAL)
Sets VREF to built-in reference: 1.1V volts on ATmega328P
Not available on the ESP8266
analogReference(EXTERNAL)
sets VREF to voltage applied to the AREF pin (must be in range 0 to VCC)

VREF Selection
Why would we want to vary VREF from its default?
The resolution of a 10-bit ADC is of the full scale
Suppose we have a signal whose values lie in the range 0-2 V

If we set VREF = 5V, then the max error is = 2.5 mV
If we set VREF = 2V, then the max error is = 1 mV

The 1.1V internal reference
The microcontroller is also capable of generating an internal reference of approx. 1.1V
This is generated through the fundamental physics of the silicon and is independent of any applied voltages
Its accuracy is not great (± 0.1V), but it is sometimes used for equipment that must be powered by a battery for a prolonged period of time

The 1.1V internal reference
As a battery operates for a long period, its output voltage starts to decay
If the ADC reference is derived from this voltage, then the accuracy of the ADC will be a function of time
The 1.1 V reference is sometimes used to provide a reference voltage independent of the battery voltage

https://powerstream.com/AA-tests.htm

Summary
ADCs are characterised by
Number of bits
Resolution
Conversion rate
Range of conversion is set by VREF
Intelligent selection of VREF can improve resolution

/docProps/thumbnail.jpeg