-
The Design of A Miniature Analog to
Digital Converter
-
i
-
ii
National InstrumentNI
PCI-6024E 12bits
MicroChip PIC16F877
ADC 10bits NI
PCI-6024E PIC16F877
-
iii
Abstract
There are many kinds of analog to digital converter cards which have extensive application in modern today. But the price of the analog to digital converter card is also direct proportion to its convertibility. During the biomedical signal processing courses in college, we have ever used the data acquisition card PCI-6024E developed by National Instrument (NI.) company. The analog to digital convertibility of this card can achieve 12 bits while the price is also high. For the benefits of build-in analog to digital converter and the 10 bits resolution within the PIC16F877 chip developed by MicroChip company, we adopt it to develop an analog to digital converter in this study. Although the resolution of PIC16F877 is lower than PCI-6024E data acquisition card, it still has highly usage for its low cost.
-
iv
.................................................................................................................................i
.......................................................................................................................ii
Abstract....................................................................................................................... iii
...............................................................................................................................iv
..........................................................................................................................vi
....................................................................................................................... viii
...............................................................................................................1
1.1 .....................................................................................................................1 1.2 .............................................................................................................1 1.3 .............................................................................................2
...........................................................................3
2.1 .................................................................................................3 2.2 .................................................................................................7 2.3 .........................................................................................8
..................................................................... 11
3.1 ...................................................................................................12 3.1.1 PIC16F877 ...........................................................................12 3.1.2 ...........................................................................................16 3.1.3 ...........................................................................................18 3.1.4 ...................................................................................................20
3.2 ...............................................................................................21 3.2.1 ...................................................................................21 3.2.2 ...................................................................................22
3.3 ...............................................................................22
.....................................................................23
4.1 ...........................................................................................23 4.1.1 130Hz........................................................................................23 4.1.2 150Hz........................................................................................23 4.1.3 160Hz........................................................................................24 4.1.4 170Hz........................................................................................24 4.1.5 180Hz........................................................................................24
-
v
4.1.6 185Hz........................................................................................25 4.1.7 190Hz........................................................................................25
4.2 ...........................................................................................26 4.2.1 50Hz..........................................................................................26 4.2.2 60Hz..........................................................................................26 4.2.3 70Hz..........................................................................................26 4.2.4 80Hz..........................................................................................27 4.2.5 90Hz..........................................................................................27 4.2.6 105Hz........................................................................................27 4.2.7 110Hz........................................................................................28
4.3 .......................................................................................29 4.3.1 75Hz..........................................................................................29 4.3.2 85Hz..........................................................................................29 4.3.3 95Hz..........................................................................................29 4.3.4 105Hz........................................................................................30 4.3.5 115Hz........................................................................................30 4.3.6 120Hz........................................................................................30
4.4 ...........................................................................................................31
.....................................................................................................32
.....................................................................................................................33
A ................................................................................34
B PIC16F877 ................................................................................35
-
vi
1.1 ............................................................................................................2 2.1 [1] ...........................................................................................................4 2.2 [1] ...............................................................................................4 2.3 [1] ...............................................................................................................6 2.4 [1] .......................................................................................................6 2.5 [1] ...................................................................................7 2.6 [1] ...............................................................................9 3.1 PIC16F877 [8].......................................................................................11 3.2 [2] .....................................................................................14 3.3 ..................................................................................................15 3.4 ADCON1 BIT3BIT0[7]..................................................................16 3.5 ADCON1 [7] .........................................................................................16 3.6 [7] .....................................................................................17 3.7 ADCON0 [7] .........................................................................................17 3.8 TXSTA [7].............................................................................................19 3.9 ......................................................................................................20 3.10 ....................................................................................................21 3.11 ....................................................................................................22 4.1 130HZ ......................................................................................................23 4.2 150HZ ......................................................................................................23 4.3 160HZ ......................................................................................................24 4.4 170HZ ......................................................................................................24 4.5 180HZ ......................................................................................................24 4.6 185HZ ......................................................................................................25 4.7 190HZ ......................................................................................................25 4.8 50HZ ........................................................................................................26 4.9 60HZ ........................................................................................................26 4.10 70HZ ......................................................................................................26 4.11 80HZ ......................................................................................................27 4.12 90HZ ......................................................................................................27 4.13 100HZ ....................................................................................................27 4.14 110HZ ....................................................................................................28 4.15 75HZ ..................................................................................................29 4.16 85HZ ..................................................................................................29 4.17 95HZ ..................................................................................................29 4.18 105HZ ................................................................................................30
-
vii
4.19 115HZ ................................................................................................30 4.20 120HZ ................................................................................................30
-
viii
3.1 PIC 8051 .............................................................................13 3.2 ..................................................................................14 3.3 ..................................................................................15 3.4 ..........................................................................................18 3.5 BAUD RATE ...........................................................................................19 3.6 MAX232 ..........................................................................................20 3.7 ..........................................................................................................22 4.1 ..................................................................................................31
-
1
1.1
CD VCD DVD
1.2
Lab VIEWPCI
PCI
-
2
1.3
PCI
PIC16F877
RS232
LabVIEW6.i RS232 Lab
VIEW6.i 1.1
1.1
-
3
2.1
.
0 1
()0 ~ 1 3 bit
A/D 3 bit 000001010011100101
110111 0 ~ 1 8
2.1
011 0.3125 ~ 0.4375
0.125 0.0625 2.2
1V 2V 0.125 1V 2V
LSBLeast
Significant Bit N
N N2 full scale
N2FSB LSB 1 =
-
4
2.1 [1]
2.2 [1]
1 LSB 1 LSB
.sampling
aperture
time, ns s[1]
-
5
aperture time
samplingholdsampling hold
sampling time
2.3a )(tf 2.3b )(tu
T )(tg )t(u)t(f)t(g =
)(tu
)(tu = tn cos nk
nksink sn
=
Tk= Ts
2=
)(tg tn cosnk
nk sink)t(f)t(g sn
=
=
1)lim(sin =
)(tg
tn cosk)t(f2k)t(f tn cosk)t(f)t(g1n
sn
s
=
=
+==
)(tf )(tg
( )[ ] ( ) += sinsin21cossin
sf
As fnf Af splice
noise 2.4 As ff
4 Af 2sf
Lowpass filter Af
splice noisesampling[1]
-
6
2.3 [1]
2.4 [1]
-
7
2.2
mssns
ms
s
PCM
sample hold
data
acquisition system
VideoHi-VISON
ns COMS
2 2.5
2.5 [1]
-
8
2.3
micro computer system
micro
computer interface
Busy pollinginterruptDMA
. Busy
read Busy
0 ms
polling
. polling
Busy
-
-
9
. interrupt
2.6
W polling R
data
IRPRQ
2.6 [1]
. DMA
DMA Direct Memory Access s
s
data
-
10
DMA DMA
DMA
DMA DMA memory
Memory data word
DMA
address signalcontrol signal
DMA [1]
-
11
CPUMicrocontroller
MicroprocessorMicrocomputer
Microchip PIC16F877
OTPOne ProgrammableQTPQuick-Turn Programmable
DIPDual In Line PackagePLCCPlastic Leaded Chip CarrierQFPQuad Flat
Package OTP QTP MicroChip
DIP
3.1
3.1 PIC16F877 [8]
-
12
3.1
RS232
PIC16F877
3.1.1 PIC16F877
PIC MPASM MPASM
InterpreterMachine Code
C
PIC C C Compiler
. PIC
PIC
PIC (.c.h.inc.asm )
14bit
PIC RISC(Reduce Instruction Set Computing)
PIC (call
)
PIC RISC(Reduce Instruction Set Computing)
X86
CISC(Complex Instruction Set Computing)
-
13
8051 CISC PIC 8051
RISC PIC
RISC CISC 3.1
3.1 PIC 8051
PIC (RISC) 8051 (CISC)
. PIC
PIC16F877 20MHz PIC16F877
40 OSC1/CLKIN OSC2/CLKOUT
PIC16F877
LPLow Power Crystal
XT/Crystal/Resonator
HSHigh Speed Crytal/Reasonator
RC/Resistor/Capactor
Crystal Reasonator
Crystal LPXT HS
Reasonator XT HS
-
14
Crystal Reasonator
3.2 1C 2C Crystal 1C 2C
3.2Reasonator 1C 2C 3.3
3.2 [2]
3.2
1C 2C
32K Hz 33 pF 33 pF LP
200K Hz 15 pF 15 pF
200K Hz 47- 68 pF 47- 68 pF
1M Hz 15 pF 15 pF
XT
4M Hz 15 pF 15 pF
4M Hz 15 pF 15 pF
8M Hz 15- 33 pF 15- 33 pF
HS
20M HZ 15- 33 pF 15- 33 pF
-
15
3.3
1C 2C
455K
Hz
68-100 pF 68-100 pF
2.0M
Hz
15- 68 Pf 15- 68 pF
XT
4.0M
Hz
15- 68 pF 15- 68 pF
8.0M
Hz
10- 68 pF 10- 68 pF HS
16.0M
Hz
10- 68 pF 10- 68 pF
Crystal
20MHz 1C 2C 1533pF 3.3
3.3
200 ns ( MHz201 )
-
16
3.1.2
.
PIC16F877 5
5 PIC16F877 PORTA
ADCON1
PCFG3PCFG0bit3bit0 3.4 A
D I/O PORT 3.5 ADCON1
ADFM 10bit 0Lgft Justified1Right
Justified
3.4 ADCON1 bit3bit0[7]
3.5 ADCON1 [7]
-
17
.
PIC16F877
(Conversion Time)(Sampling Frequency)
PIC16F877 ADT = 1 bit
10 bits = 12 ADT ( 1 bit 1 bit
10 bits 12 bits ) PIC16F877 ADT
s6.1 10 bits s2.1912s6.1 = 3.6
3.7 ADCON0 s6.1
3.6 [7]
3.7 ADCON0 [7]
-
18
PIC16F877 ADT ADCON0 ADCS1 (bit7) ADCS0 (bit6)
20MHz 3.4 ADT
ADT = s6.1 s6.1MHz20132T32T OSCAD ===
3.4
AD Clock Source ( ADT ) Maximum Device Frequency
Operation ADCS1ADCS0 MAX
2 OSCT 0 0 1.25MHz
8 OSCT 0 1 5MHz
32 OSCT 1 0 20MHz
RC Mode 1 1 Note 1
(Note 1 ADT = s4 s6~2 )
ADT = 8 OSCT ADT ( s6.1 )
5MHz ADT =32 OSCT
s4.6MHz5132T32T OSCAD === > s6.1
RC Mode ADT s6~2 s4 RC
1MHz
3.1.3
. TXSTA
Baud Rate PIC16F877
TXSTA BRGH
-
19
bit2 3.8 3.5
3.8 TXSTA [7]
3.5 Baud Rate
SYNC BRGH = 0Low Speed BRGH = 1High Speed
0 ( )( )1x64FoscRate Baud +=
2 ( )( )1x4FoscRate Baud +=
( )( )1x16FoscRate Baud +=
x 255~0
5.625MHz 2400bps
BRGH=0
( )( )1x64KHz5265bps2400Rate Baud+
==
x =35.621 x =36 SPRBG
REGISTER
. MAX232 RS232
MAX232 IC RS232
MAX232 RS232
High =1 5VLow
=0RS232 3.6
-
20
3.6 MAX232
HIGH=1 Low =0
-3V -15V +3V +15V
Mark Space
-6V +6V
RS232 Pin2 RXD Pin3 TXD
23
Pin2 Pin3 Pin2
Pin3 TXD RXD
3.1.4
3.9
-
21
3.2
Lab View6.i Lab View6.i
RS232
RS232 8 bits
Baud Rate Data bits RS232
Baud Rate 57600bpsData bits
8 8 bits RS232
0 COM1 1 COM2
3.2.1
3.10
-
22
3.2.2
3.11
3.3
250Hz
10bits
5
3.7
250Hz
10bits
-
23
4
RS232 Baud Rate 57600 bps
7.2KHz RS232 8 bits
10bits
3.6KHz 10bits
4.1
4.1.1 130Hz
130Hz
4.1
4.1 130Hz
4.1.2 150Hz
150Hz
4.2
4.2 150Hz
-
24
4.1.3 160Hz
160Hz
4.3
4.3 160Hz
4.1.4 170Hz
170Hz
4.4
4.4 170Hz
4.1.5 180Hz
180Hz
4.5
4.5 180Hz
-
25
4.1.6 185Hz
185Hz
4.6
4.6 185Hz
4.1.7 190Hz
190Hz
4.7
4.7 190Hz
190Hz
185Hz
-
26
4.2
4.2.1 50Hz
50Hz
4.8
4.8 50Hz
4.2.2 60Hz
60Hz
4.9
4.9 60Hz
4.2.3 70Hz
70Hz
4.10
4.10 70Hz
-
27
4.2.4 80Hz
80Hz
4.11
4.11 80Hz
4.2.5 90Hz
90Hz
4.12
4.12 90Hz
4.2.6 105Hz
105Hz
4.13
4.13 100Hz
-
28
4.2.7 110Hz
110Hz
4.14
4.14 110Hz
110Hz
105Hz
-
29
4.3
4.3.1 75Hz
75Hz
4.15
4.15 75Hz
4.3.2 85Hz
75Hz
4.16
4.16 85Hz
4.3.3 95Hz
95Hz
4.17
4.17 95Hz
-
30
4.3.4 105Hz
105Hz
4.18
4.18 105Hz
4.3.5 115Hz
115Hz
4.19
4.19 115Hz
4.3.6 120Hz
120Hz
4.20
4.20 120Hz
-
31
120Hz
115Hz
4.4
185Hz
105Hz
115Hz 4.1
4.1
(Hz)
185
105
115
4.1 250Hz
4
8 2 bits
-
32
PIC16F877 ADC 42 s
100 s RS232
USB ADC
23.8KHz
USB RS232 8 bits
ADC
11.9KHz
-
33
[1] A/D 2001
[2] PIC / PIC16F877 2002
[3] PIC16F87X 2000
[4] PIC16F87X
2001
[5] PIC 1998
[6] LabVIEW 2003
[7] Micro Chip PIC16F877 DataSheet
[8] Texa Instruments MAX232 DataSheet
-
34
A
-
35
B PIC16F877
list p=16F877
#include
val_25 equ .30
val_75 equ .3
count_25 equ 0x20
count_75 equ 0x21
adc_data_msb equ 0X22
adc_data_lsb equ 0x23
org 0x00
nop
goto Initial
org 0x04
goto Rs_int
Initial:
banksel TRISC
clrf TRISC
banksel PORTC
clrf PORTC
banksel TRISA
movlw B'00011111'
movwf TRISA
banksel ADCON1
-
36
movlw B'10001000'
movwf ADCON1 ;V+=RA2,V-=RA3
banksel ADCON0
movlw B'10000001' ;32Tosc,channel 0, ADC on
movwf ADCON0
banksel INTCON
bsf INTCON,GIE
bsf INTCON,PEIE
banksel PIE1
clrf PIE1
bsf PIE1,ADIE
banksel adc_data_msb
clrf adc_data_msb
banksel adc_data_lsb
clrf adc_data_lsb
call delay_25
banksel ADCON0
bsf ADCON0,GO
Main:
nop
goto Main
;The start of interrupt
Rs_int:
movf ADRESH,W
-
37
banksel adc_data_msb
movwf adc_data_msb
clrw
banksel ADRESL
movf ADRESL,W
banksel adc_data_lsb
movwf adc_data_lsb
Rs232_setup:
banksel TXSTA
clrf TXSTA
bsf TXSTA,TXEN
bsf TXSTA,BRGH
bcf TXSTA,SYNC
clrw
banksel SPBRG
movlw .20 ;baudrate=57600
movwf SPBRG
banksel RCSTA
bsf RCSTA,SPEN
bcf RCSTA,CREN
Trans_low:
clrw
-
38
banksel adc_data_lsb
movf adc_data_lsb,W
banksel TXREG
movwf TXREG
Rs232_high:
banksel TXSTA
btfss TXSTA,TRMT
goto Rs232_high
clrw
banksel adc_data_msb
movf adc_data_msb,W
banksel TXREG
movwf TXREG
Rs232_tx:
banksel TXSTA
btfss TXSTA,TRMT
goto Rs232_tx
call delay_75
banksel ADCON0
bsf ADCON0,GO
banksel PIR1
bcf PIR1,ADIF
retfie
-
39
;delay time 50
delay_75:
movlw val_75
movwf count_75
loop_75
call delay_25
decfsz count_75,f
goto loop_75
return
;delay time 25
delay_25:
movlw val_25
movwf count_25
loop_25
nop
decfsz count_25,f
goto loop_25
return
end