Title: Compte rendu Technique de Projet
1Workshop Craiova Cachan Robotic Cup
Project pedagogy approach of microcontrollers
Craiova University
IUT Cachan
2Analog to Digital Conversion
Craiova University
IUT Cachan
3Analog to Digital Conversion
1 From the analog signal to the digital signal 2
The analog to digital converter of pic18f4320 3
The Conversion Time 4 The Acquisition Time 5
Programming analog to digital conversion
Bibliography microcontroller PIC 4320
documentation (PDF file) MPLAB_C18 librairies
documentation (PDF files) MPLAB_C18 header file
adc.h MPLAB_C18 c file sources (mcc18\src\traditio
nnal\pmc)
41 From the analog signal to the digital signal
Analog Signal
001 100 110 111 110 101 100 010 010 001 010 010
011 100 101
52 The analog to digital converter of pic18f4320
N (10 bits digital value)
microcontroller
0x3FF 1023
ADC 10 bits
analog input
10 bits value N
internal digital number
Vin
Vin
0x000 0
5 Volts
0 Volts
62 The analog to digital converter of pic18f4320
72 The analog to digital converter of pic18f4320
82 The analog to digital converter of pic18f4320
Configuration / initialization function
Conversion Time
OpenADC( ADC_FOSC_32 ADC_RIGHT_JUST
ADC_12_TAD, ADC_CH0 ADC_INT_OFF
ADC_VREFPLUS_VDD ADC_VREFMINUS_VSS,
15 )
Right or left justification
Acquisition Time
Channel selection
Interrupt deactivation
Voltage reference configuration
Mode selection for each Analog or Digital Inputs
93 The conversion time
microcontroller
ADC 10 bits
ST
analog input
10 bits value N
internal digital number
Vin
ST DONE
DONE
103 The conversion time
AD conversion time per bit is defined as TAD.
The conversion needs 11 TAD for 10-bit
conversion. TAD is selectable by software.
TAD 16 / 8 MHz 2 ms and Tcon 2 x 11
22 ms
114 The acquisition time
Multiplexer and analog acquisition schematic
AN0
AN1
AN2
analog mux
Vin
13 analog input channels
AN10
AN11
AN12
input selection
124 The acquisition time
- 1 select an analog input
-
- 2 - the switch is closed CHOLD is charged
- Vin VDD (1 e t/?) with ? (RsRicRss)CHOLD
- Maximum charging time reached when Vin VDD 2047
/ 2048 (1/2 LSB) - Tc ? ln(2048) 1.05 ms
- 3 - the switch is opened, Vin is read and
converted (Tcon) - 4 - CHOLD is discharged
Before conversion, the minimum required sample
time (worst case) 12,8 ms
134 The acquisition time
TACQ is configurable between 0 TAD and 20 TAD
145 Programming analog to digital conversion
Flow chart for Analog to Digital Conversion
GO/DONE 1
GO/DONE 0 ?
N is read
155 Programming analog to digital conversion
An example reading the potentiometer (plugged
on AN0)
void main(void) int i short N //
Configure ADC OpenADC( ADC_FOSC_xx
ADC_RIGHT_JUST ADC_xx_TAD,
ADC_CH0 ADC_INT_OFF, 0x0E)
only AN0, is analog input
while(1) // infinite loop
ConvertADC() // Start sampling and conversion
while (BusyADC() 1) // Wait until
conversion is done N ReadADC()
// Read N