Professional Documents
Culture Documents
1
For more details, please refer to the following resources:
1. http://ww1.microchip.com/downloads/en/DeviceDoc/39705b.pdf
2. http://courses.ece.msstate.edu/ece3724/main_pic24/videos/lectures/ch11_part1/
3. http://lib.myilibrary.com.ezproxy.aus.edu/Open.aspx?id=334823
2
Analog to Digital Converter (ADC) and
Digital to Analog Converter (DAC) Concepts
http://courses.ece.msstate.edu/ece3724/main_pic24/lectures/chap11_adcdac.pdf
3
4
5
6
7
8
ADC Code due to Vin
9
Vin due to ADC Code
10
PIC24 Microcontroller: Analog to Digital Conversion
Conversion
Circuit
11
12
13
AD Configuration
Analog Inputs Channels are connected to PortB PortB Associate wit five registers:
Port B is multiplexed port and can be used as:
• TRISB (data direction registers)
• Digital Input / Digital Output • PORTB (Data Register)
• Analog Inputs • LATB (Latch Register of PortB)
• Comparators • ODCB (Open Collector of PortB)
• Communication port • AD1PCFG Register ( ATD Port Configuration)
Port B Usage Description
RB0 AN0/EMUD1/CN2 Analog Input 0 /In-Circuit Emulator /Data Input/Output/ Interrupt on change input
RB1 AN1/EMUC1/CN3 Analog Input 1 /In-Circuit Emulator Clock/ Input/Output/ Interrupt on change input
RB2 AN2/C2IN-/SS1/CN4 Analog Input 2 /Comparator2 Negative Input/ Slave Select Input/Frame Select Output (SPI1)
/ Interrupt on change input
RB3 AN3/C2IN+/CN5 Analog Input 3 /Comparator2 Positive Input /Interrupt on change input
RB4 AN4/C1IN-/CN6 Analog Input 4 (THERMAL SENSOR – TC 1047A) /Comparator 1 Negative Input
/Interrupt on change input
RB5 AN5/C1IN+/CN7 Analog Input 5 ( VARIABLE POT -10K) /Comparator1 Positive Input /Interrupt on change
input
14
Step1 – Configure PORTB as Analog input:
AD1PCFG = 1111 1111 1101 1111 = 0XFFDF ; All are Digital Inputs/Outputs except AN05 is Analog (POT)
S/H amplifier is connected to the Input disconnected; S/H amplifier holds signal. Conversion
analog input pin for sampling. trigger starts A/D conversion.
http://ww1.microchip.com/downloads/en/DeviceDoc/39705b.pdf 16
Step 2. AD1CON1 Register
(Remember Step 1 was:. AD1PCFG – Port Configuration Register : Analog ‘0’ ; Digital ‘1’)
Wake-up
Discontinue
Or Continue
In Idle mode
Data
Format
17
Step 2. AD1CON1 Register
(Remember Step 1 was:. AD1PCFG – Port Configuration Register : Analog ‘0’ ; Digital ‘1’)
18
(Remember Step 1 was:. AD1PCFG – Port Configuration Register : Analog ‘0’ ; Digital ‘1’)
SAMP = 1: Start Sampling, then give short Delay,
19
Step 2. All in one Slide AD1CON1 Register
(Remember Step 1 was:. AD1PCFG – Port Configuration Register : Analog ‘0’ ; Digital ‘1’)
Wake-up
Data
Format SAMP = 1: Start Sampling
then give short Delay,
SAMP = 0 : Start Conversion
21
Step 3. Initialization of AD1CON2
22
Step 4. AD1CON3 Register
24
Step 6. AD1CON3 Register: AD1CSSL Register
Ch0 BUFF0
BUFF1
Ch5 BUFF2
…
…
BUFE
BUFF
25
26
27
𝑭𝑺𝑹
𝑹𝒆𝒔𝒐𝒍𝒖𝒕𝒊𝒐𝒏 = = 3300/1024 = 3.22 mV
𝟐𝒏
Weights 1648.64 824.32 412.16 206.08 103.04 51.52 25.76 12.88 6.44 mV 3.22mV Dec HEX
mV mV mV mV mV mV mV mV
Vin mV
B9 (512) B8 (256) B7(128) B6(64) B5(32) B4 (16) B3 (8) B2 (4) B1 (2) B0 (1)
0 0 0 0 0 0 0 0 0 0 0 000 000
9.66
12.88 0 0 0 0 0 0 0 1 0 0
22.54 0 0 0 0 0 0 0 1 1 1 007
2565
1 0 1 0 0 1 0 0 0 1 291
2. AD1CON1
– Turn ADC module on
– Turn on during idle
– Data in integer form
– Auto convert
– Auto sample start
3. AD1CON2
– Use vref+ and vref-
– do not scan inputs
– ignore interrupts
– 16 word buffer
– use MUX A
4. AD1CON3
– sample using internal RC clock
– auto sample set time
– clock division for sampling clock
6. AD1CSSL
– analog channel is ignored in sequential
29
scanning
30
AD1PCONFG
– Select the port to be digital I/O or
Analog Input
Initialize AD1CON1
ADC () – Turn ADC module on
– Turn on during idle
– Data in integer form
– Manual sample start
– Manual convert
Convert AD1CON2
– Use vref+ and vref-
ADC ()
– do not scan inputs
– ignore interrupts
– 16 word buffer
– use MUX A
Convert AD1CON3
– Sample using internal RC clock
Done – auto Manual sample set to the most
amount of time
– Clock division for sampling clock
AD1CSSL
– Analog channel is ignored in sequential
Return scanning
Result
31
Step1 – Configure PORTB as Analog input:
void InitADC
{
}// InitADC 32
Step 2. All in one Slide AD1CON1 Register
(Remember Step 1 was:. AD1PCFG – Port Configuration Register : Analog ‘0’ ; Digital ‘1’)
void InitADC
{
}// InitADC
33
void InitADC
{
}// InitADC 34
Conversion Modes:
35
ADC Conv-Time TAD
= TCY (ADCS+1)≥ 75nsec
= 2/Fosc (1+1)
= 2/32MHz(2)
= 4/32MHz
= 1/8 µsec=125 µsec
36
void InitADC
{
}// InitADC
37
Step 6. AD1CON3 Register: AD1CSSL Register
void InitADC
{
}// InitADC 38
39
The whole Story
40
Analog to Digital Converter (ADC) and
Digital to Analog Converter (DAC) Concepts
http://courses.ece.msstate.edu/ece3724/main_pic24/lectures/chap11_adcdac.pdf
41
Analog Applications
42
LM35 - Precision Centigrade Temperature Sensor
43
Sensors Reading and Conversation
VT-Sen = 10mv/1CO
1 10 = 10/3.23=3 1
Temp Sensor resolution=
25 250 = 250/3.22 25.11
= 77.6= 78
10mV 1CO
X 20CO 100 1000 = 1000/3.22 100
= 310.56
= 311 311*3.22/10
X = 10mV * 20CO= 200mV = 100.142
For the TC1047A, the output voltage range is typically 100mV at -40C, 500mV
at 0C, 750mV at +25C, and 1.75V at +125C.
45
Temperature Measurement
Temp = [ (ATD-Reading) * (ATD-RES)] / (Sen-Res) ]
.
= 10mV/Co*(60Co )+500mV
= 1100mV=1.1V
VOUT 500 mV AD-Reading=BUF0
Temp C =
=Vout / RES = 1100mV/3.22
10 mV = 341.614 =342 Units
342 * 3.22 500 mV
60C Temp Value
=342*3.22/10 = 102.6C??
10 mV 46
47
48
49
50
51
52
53
54
55
VCC
Vw-sen = 2.5mv/0.1kg
Weight V-w-sen ATD- (Units *3.22mV )/ Height V-w-sen ATD- (Units *3.22mV )/
READING READING
Kg mV (1.5mv/0.1kg) CM mv “Units”
(15mV/1cm)
“Units”
100 183
1.5mV 0.1kg
1cm 15mv
X 50kg
175cm x
X = 1.5mV * 50kg / 0.1kg = 750mV
X = 175 *15 = 2625mv
ATD-Reading = 750mV/ 3.22mV (10bit-RES) = 233 units
ADC-Reading = 2625mv/3.22 = 815
The above value is the return value from the ATD-Convert() H= [815* 3.22mv]/15mv = 174.9
Weight = [ (ATD-Reading) * (ADT-RES)] / (Sen-Res) ] 56
= 233 units *3.22mV/[1.5mV/0.1Kg] = 50 Kg
Weight Height BMI = Your are
(Kg) (M2 ) Weight (Kg) / Height (M2 )
61
void InitADC
{
}// InitADC 62
111111001111 1111
ADC1BUF0 = CH08
ADC1BUF1 = CH09
63
64
65
66
67
68