You are on page 1of 51

Tiva C ADC

Refrereces:
James Cockrell and Justin Loveless
Hossam Elkady Youtube Arabic Course
Practical Microcontroller Engineering with ARM Tech by Ying Bai
Analog-Digital Converter (ADC): Agenda
• How it works?
• Successive Approximation
• Register level TIVA ADC
• TIVAWare ADC driver library
• Examples
• Assignment
• ADC:
• Analog Signal:

Temperature Humidity

Pressure
Light Intensity

Level Sound
• ADC:
• Analog Signal:

01110111
ADC CPU
• ADC:
• Analog Signal:

Sound Physical Analog Proper Digital


Temperature Quantity Signal Voltage Signal
Pressure Signal
Sensor ADC CPU
Level Conditioning
Humidity
Voltage

Temp Voltage Voltage

Digital
Output
Time Time Time

10011100
• ADC: Step Size =
𝑽𝒓𝒆𝒇
𝟐
=
𝟓𝒗
𝟐
= 𝟐. 𝟓 𝟐𝟏 = 2 ADC
• Resolution:
1 Bit
Voltage (V)

5
4.5
4
3.5 High – Logic 1
3
2.5
2
1.5 LOW – Logic 0
1
0.5
0 Time (ms)
0 1 2 3 4 5 6 7 8
𝟓𝒗
• ADC: 𝟒
= 𝟏. 𝟐𝟓𝒗
𝟐𝟐 = 4 ADC
• Resolution:
2 Bit
Voltage (V)

5
4.5 11
4
3.5
3 10
2.5
2
01
1.5
1
0.5 00
0 Time (ms)
0 1 2 3 4 5 6 7 8
𝟓𝒗
• ADC: 𝟖
= 𝟎. 𝟔𝟐𝟓
𝟐𝟑 = 8 ADC
• Resolution:
3 Bit
Voltage (V)

5
4.5
111
4
110
3.5
101
3
100
2.5
011
2
010
1.5
001
1
000
0.5
0 Time (ms)
0 1 2 3 4 5 6 7 8
• ADC: Step Size =
𝟓𝒗
4096
= 𝟏. 𝟐 𝒎𝒗
𝟐𝟏𝟐 = 4096 ADC
• Resolution:
12 Bit
Voltage (mV)

12
10.8
9.6
8.4
7.2
6
4.8
3.6
2.4
1.2
0 Time (ms)
0 1 2 3 4 5 6 7 8
• ADC: Assume
• Successive Approximation ADC: Step Size
10 mV

0
0000 0000
• ADC: Assume
• Successive Approximation ADC: Step Size
10 mV

128 * 10 mv = 1.28 V

> 128
1V 1000 0000
• ADC: Assume
• Successive Approximation ADC: Step Size
10 mV

64 * 10 mv = 640 mV

< 64
1V 0100 0000
• ADC: Assume
• Successive Approximation ADC: Step Size
10 mV

96 * 10 mv = 960 mV

< 96
1V 0110 0000
• ADC: Assume
• Successive Approximation ADC: Step Size
10 mV

112 * 10 mv = 1120 mV

> 112
1V 0111 0000
• ADC: Assume
• Successive Approximation ADC: Step Size
10 mV

108 * 10 mv = 1080 mV

> 108
1V 0110 1000
• ADC: Assume
• Successive Approximation ADC: Step Size
10 mV

100 * 10 mv = 1000 mV

= 100
1V 0110 0100
• ADC: Assume
• Successive Approximation ADC: Step Size
10 mV

102 * 10 mv = 1020 mV

> 102
1V 0110 0110
• ADC: Assume
• Successive Approximation ADC: Step Size
10 mV

101 * 10 mv = 1010 mV

> 101
1V 0110 0101
• ADC: Assume
• Successive Approximation ADC: Step Size
10 mV

100 * 10 mv = 1000 mV

>
1V

0110 0100
• ADC:

Channels
Enable Clock
• ADC:
• ADC:

Software
Timer
GPIO
Trigger Etc.
• ADC:

Poll This Register


or use Interrupt

Software
Timer
GPIO
Etc.
• ADC:
Vref

Software
Timer
GPIO
Etc.
TM4C ADC Specs
• Reference voltages:
• VREFP – tied to 3.3V on the Launchpad.
• VREFN – tied to ground on the Launchpad.
• Range & Resolution
• Range = 0  4095
• Resolution = 3.3V / 4096 = 8.05 mV (p. 803)
• Max Sampling Speed = 1 million samples/second
• Hardware Averaging
• Averages 4 samples in hardware during conversion
• Differential Sampling
• Sample the difference between two inputs
• Internal Temp Sensor
• Can be sampled for chip temp
• ADC:
• ADC:
• ADC:
• Sample Sequencer:
• ADC:
• Sample Sequencer:
• ADC:
• Differential versus Single-Ended:

A0 Digital A0

ADC Single-Ended
A1 Digital A1

A0

ADC Digital (A0-A1) Differential

A1
• ADC:
• Internal Temperature Sensor:
• ADC:
• ADC Input:

12
Input Channels (A0 to A11)

ADC
Internal Temperature Sensor
Example 3: TIVAWareADC
TIVA Ware Example 4 setup

It’s actually that simple!

3.3V

Tiva C
PE3 Pot

GND
Example ADC Code
1. Set up clock for 40 MHz

2. Enable peripheral ADC0, then reset it to apply changes

3. Disable ADC0 sequencer 3

4. Configure ADC sequencer

5. Configure steps for sequences

6. Enable peripheral GPIO port E


Example ADC Code

1. Activate PE3’s alternate function (AIN0)

2. Set up interrupt handler for ADC0 sequencer 3

3. Enable interrupts for ADC0 sequencer 3

4. Re-enable ADC0 sequencer 3

5. Enable global interrupts

6. Post request for ADC conversion (in a loop)


Example ADC Code (ISR handler)

1. Clear interrupt flag for ADC0 Sequencer 3

2. Wait until conversion is done

3. Read data, and process it


Libraries to include
• From the TivaWare peripheral drivers:

• File path to TivaWare libraries and examples:


• C:\ti\TivaWare_C_Series-2.1.1.71\examples\peripherals

You might also like