ADC Presentation - James Cockrell, Justin Lovelessx
Download
Report
Transcript ADC Presentation - James Cockrell, Justin Lovelessx
Tiva C ADC
By James Cockrell and Justin Loveless
Overview of Analog-Digital Converter (ADC)
• Turns an analog voltage into a digital value
• Used for sensor measurement
• Can be triggered with either SWI’s or HWI’s
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
ADC0 and ADC1
• There are two 12 bit ADC’s
• All input channels and triggers are shared by both ADC’s
Sequencers
• Pick sequencers based on how many samples you want
• For our example we only need one sample
Sequencer
Number of Samples
Depth of FIFO
SS3
1
1
SS2
4
4
SS1
4
4
SS0
8
8
Analog input pins (p.795)
• These pins can be used as analog
inputs if their alternate functions
are enabled
Pin Name
Pin Number
Pin Assignment
AIN0
6
PE3
AIN1
7
PE2
AIN2
8
PE1
AIN3
9
PE0
AIN4
64
PD3
AIN5
63
PD2
AIN6
62
PD1
AIN7
61
PD0
AIN8
60
PE5
AIN9
59
PE4
AIN10
58
PB4
AIN11
57
PB5
Triggers (p. 793)
• Potential triggers include
•
•
•
•
•
•
Controller (software)
Timers
Analog Comparators
PWM
GPIO
Nothing (continuous samples)
• Our example will use a software as the trigger
Example setup
It’s actually that simple!
3.3V
Tiva C
PE3
GND
Pot
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
Questions?
Resources
• https://engineering.purdue.edu/ece477/Archive/2014/Spring/S14Grp1/docs/software/LM4F-LaunchPad-05%20-%20ADC.pdf
• Chapter 5
• http://www.ti.com/lit/ug/spmu298a/spmu298a.pdf
• Explains the API functions
• http://software-dl.ti.com/tiva-c/SW-TM4C/latest/index_FDS.html
• Tiva C peripheral library and examples download site
• http://software-dl.ti.com/trainingTTO/trainingTTO_public_sw/GSWTM4C123GLaunchPad/TM4C123G_LaunchPad_Workshop_Workbook.pdf
• Overview and specifications