Beruflich Dokumente
Kultur Dokumente
10
The A/D subsystem allows the possible range of input analog voltages to be limited using two reference voltages: VRH (Highest possible input voltage) Any input voltage higher than this value will result in the highest possible digital word value. VRL (Lowest possible input voltage) Any input voltage lower than this value will result in the lowest possible digital word value (zero).
Relationship digital token and input analog voltage if VRH=5V, VRL=0V, and AD word size is 8 bits.
If we had an 8 bit A/D, where VRL = 0 V and VRH = 5V, then =(5-0)/(28-1) =5/255 =0.01960 Volts =19.6mV
The relationship between analog input voltage (Vi) and the resulting digital token (Dt) is Dt =
(Vi-VRL)/
Max
Assume an A/D system with a 12 bit word size and VRH and VRL set to 3V and 1V respectively, calculate
Monday, 2 November 2009
10
Dt =
(Vi-VRL)/
Max
1.89V since it is greater than VRL and less than VRH would be Dt = (Vi-VRL)/ = (1.89-1)/0.000488 = 1823
11
Dt =
(Vi-VRL)/
Max
2.4V since it is greater than VRL and less than VRH would be Dt = (Vi-VRL)/ = (2.4-1)/0.000488 = 2868
12
Dt =
(Vi-VRL)/
Max
13
14
How is it done?
Vi
S/H
Comparator
D/A
Dt
Weights Array Control Logic
Init Reset
There are many ways of converting analog signals into digital tokens. The most common method used in micro-controllers is the successive approximation approach.
15
How is it done?
Vi
S/H
Comparator
D/A
Dt
Weights Array Control Logic
Init Reset
How is it done?
3.8V Vi S/H
Comparator
D/A
Dt
Weights Array Control Logic
Init Reset
How is it done?
3.8V Vi S/H
Comparator
D/A
Dt
100 Weights Array
How is it done?
3.8V Vi S/H
Comparator
2.5V
D/A
Dt
100 Weights Array
How is it done?
3.8V Vi S/H
Comparator
2.5V
D/A
Dt
100 Weights Array
1
Control Logic Init Reset Clock 100 Shift Register
How is it done?
3.8V Vi S/H
Comparator
D/A
Dt
100 Weights Array
How is it done?
3.8V Vi S/H
Comparator
D/A
Dt
110 Weights Array
How is it done?
3.8V Vi S/H
Comparator
3.75V
D/A
Dt
110 Weights Array
How is it done?
3.8V Vi S/H
Comparator
3.75V
D/A
Dt
110 Weights Array
1
Control Logic Init Reset Clock 010 Shift Register
How is it done?
3.8V Vi S/H
Comparator
D/A
Dt
110 Weights Array
How is it done?
3.8V Vi S/H
Comparator
D/A
Dt
111 Weights Array
How is it done?
3.8V Vi S/H
Comparator
4.375V
D/A
Dt
111 Weights Array
How is it done?
3.8V Vi S/H
Comparator
4.375V
D/A
Dt
111 Weights Array
0
Control Logic Init Reset Clock 001 Shift Register
How is it done?
3.8V Vi S/H
Comparator
4.375V
D/A
Dt
111 Weights Array
0
Control Logic Init Reset Clock 000 Shift Register
How is it done?
3.8V Vi S/H
Comparator
4.375V
D/A
Dt 110
Weights Array
0
Control Logic Init Reset Clock 000 Shift Register
The MC9S12XDP512 contains two (S12ATD10B8CV3) 8 channel 10 bit successive approximation A/D subsystems. The external reference voltages VRH and VRL are set to 5V and GND respectively on the Adapt9S12X board. It also has external trigger pins, that can be used to initiate a sampling of the analog inputs. A bit like the IRQ interrupt pin, but specically for the A/D subsystem.
20
Bus Clock
ATD clock
ATD10B8C
ETRIG0 ETRIG1 ETRIG2 ETRIG3 (See Device Overview chapter for availability and connectivity)
ATDCTL1
ATDDIEN
PORTAD VDDA VSSA VRH VRL Successive Approximation Register (SAR) and DAC
AN7 AN6
Analog Multiplexer
21
ATD0
Monday, 2 November 2009
ATD1
22
All interaction with the AD subsystems is done via there I/O register sets.
ATDxCTL0 ATDxCTL1 ATDxCTL2 ATDxCTL3 ATDxCTL4 ATDxCTL5 ATDxDRXH ATDxDRXL ATDxSTAT0 ATDxSTAT1 ATDxDIEN ATDxPTAD
23
24
WRAP2-WRAP0
Channel number to wrap from. When doing multiple conversions this register denes when the analog multiplexer should switch back to AN0 (or AN8). It will switch back to AN0 (or AN8) after sampling the channel dened in this register.
25
ETRIGCH2
ETRIGCH1
ETRIGCH0
ETRIGSEL
0 - Selects a analog input channel as the triggering source. 1 - Selects one of the triggering channels as the triggering source.
ETRIGCH2-ETRIGCH0
This number represents the triggering source.
26
ETRIGP
ETRIGE
ASCIE
ACIF
ADPU (ATD Power Up) 0 disable subsystem 1 enable subsystem It takes approximately100useconds for the analog circuits stabilize. Once the subsystem is powered all registers are reset to there default state. AFFC (ATD Fast Flag Clear All) 0 means ATD ag clearing operates normally (A read to ATDSTAT0 and the appropriate result register is required to clear the corresponding CCF ag).
1 means only a read to the result register is required to reset the CCF ag.
Monday, 2 November 2009 27
ETRIGP
ETRIGE
ASCIE
ACIF
AWAI (ATD Wait Mode) 0 continues to run when in wait mode 1 doesnt run when in wait mode ETRIGLE 0 means edge triggered 1 means level triggered ETRIGP (work in combination with ETRIGLE) 0 means falling edge or low level 1 means rising edge or high level
28
ETRIGP
ETRIGE
ASCIE
ACIF
ETRIGE 0 means disable external trigger 1 means enable external trigger ASCIE (ATD Sequence Complete Interrupt Enable) 0 disable ATD interrupt (default) 1 enable ATD interrupt ASCIF (ATD Sequence Complete Interrupt Flag 0 = No ATD interrupt occurred 1 = An ATD interrupt occurred.
29
ATDxCTL3
0 S8C S4C
Result Register FIFO Mode If this bit is zero (non-FIFO mode), the A/D conversion results map into registers based on the conversion sequence; the result of the rst conversion appears in the rst resul the second result in the second result register, and so on. If this bit is one (FIFO mode) the conversion counter is not reset at the beginning or ending of a conv sequence; sequential conversion results are placed in consecutive result registers. In a continuously conversion sequence, the result register counter will wrap around when it reaches the end of the resu le. The conversion counter value (CC2-0 in ATDSTAT0) can be used to determine where in the resu le, the current conversion result will be placed. Aborting a conversion or starting a new conversion by write to an ATDCTL register (ATDCTL5-0) clea conversion counter even if FIFO=1. So the rst result of a new conversion sequence, started by writin ATDCTL5, will always be place in the rst result register (ATDDDR0). Intended usage of FIFO mode is c conversion (SCAN=1) or triggered conversion (ETRIG=1). Finally, which result registers hold valid data can be tracked using the conversion complete ags. Fast mode may or may not be useful in a particular application to track valid data. 0 Conversion results are placed in the corresponding result register up to the selected sequence len 1 Conversion results are placed in consecutive result registers (wrap around at end).
S2C
S1C
FIFO
FRZ1
FRZ0
10 FRZ[1:0]
Background Debug Freeze Enable When debugging an application, it is useful in many cases to ATD pause when a breakpoint (Freeze Mode) is encountered. These 2 bits determine how the ATD wil to a breakpoint as shown in Table 5-9. Leakage onto the storage node and comparator reference capac compromise the accuracy of an immediately frozen conversion depending on the length of the freeze
30
FIFO Denes the behavior of the results registers. 0 means the results are stored in the corresponding registers. 1 means the results are stored in consecutive registers (wrap around at ATDDR15). FRZ1-FRZ0 Sets the behavior in freeze mode (halted during debugging).
31
SRES8 Sets the word size of the A/D. 0 means a 10 bit word size for the result. 1 means an 8 bit word size for the result.
32
SMP1-SMP0 (Sample time select) Set the length of time for sampling the analog input. Using these two bit you set how long the sample and hold circuit can charge.
33
PRS4-PRS0 (ATD Clock Prescaler) Set the frequency of the ATD clock. The relationship between the ATD clock and the Bus Clock (8MHz) is shown below
34
DJM (Result Register Data Justication) 0 means left justied. 1 means right justied. DSGN (Result Data Register Signed or Unsigned) 0 means unsigned data representation in Result Register. 1 enable signed data representation in Result Register.
35
DJM+DSGN
36
SCAN (Continuous Conversion Sequence Mode) 0 means single conversion sequence. 1 means continuos operation. MULT (Multi-channel sample mode) 0 means sample only one channel. 1 means sample across several channels.
37
SRES8 1 1 1 0 0 0
DJM 0 0 1 0 0 1
DSGN 0 1 X 0 1 X
Description and Bus Bit Mapping 8-bit / left justied / unsigned bits 815 8-bit / left justied / signed bits 815 8-bit / right justied / unsigned bits 07 10-bit / left justied / unsigned bits 615 10-bit / left justied / signed bits 615 10-bit / right justied / unsigned bits 09
ATDxCTL5
DJM
DSGN
SCAN
MULT
CC
CB
CA
CD-CA (Analog Input Channel Select Code) Select the analog Input. 81 0100 8100 01 0.020 0000 8000 00 80 0.000 A write to this register will start the conversion process.
Table 5-16. Analog Input Channel Select Coding
CC 0 0 0 0 1 1 1 1 CB 0 0 1 1 0 0 1 1 CA 0 1 0 1 0 1 0 1 Analog Input Channel AN0 AN1 AN2 AN3 AN4 AN5 AN6 AN7
01 00 FF
38
Result Registers
ATDxDRXH & ATDxDRXL
The result of the A/D conversion are stored in the appropriate result register. Since the A/D has a 10 bit word size the result is stored a 16 bit result register made up of ATDxDRxH:ATDxDRxL in which the result is either right or left justied. The results be read when the conversion is completed, this is signalled b either an A/D interrupt being triggered or the SCF bit in ATDxSTAT0 is set.
ATDxDRXH
ATDxDRXL
39
40
ATDxSTAT0
SCF 0 ETORF FIFOR 0 CC2 CC1 CC0
SCF
0 means a conversion in progress 1 means all conversions are complete ETORF 0 means no external trigger overrun has occurred. 1 means an external trigger overrun has occurred. FIFOR 0 means no FIFO overrun has occurred. 1 means a FIFO overrun occurred.
CC2 CC0
ATDxSTAT1
CCF6 CCF5 CCF4 CCF3 CCF2 CCF1 CCF0 CCF7
CCF7-CCF0
0 means conversion number X is yet to completed. 1 means conversion number X has completed.
42
Each analog input pin can be individually switch from analog input to digital input using the ATDxDIEN register. ATDxDIEN
IEN6 IEN5 IEN4 IEN3 IEN2 IEN1 IEN0
IENX
0 means the corresponding pin is used for analog input. 1 means the corresponding pin is used for digital input.
43
PTAD7
The digital byte can be read from the ATDxPTAD register. ATDxPTAD (ATD1PTAD or ATD0PTAD0)
PTAD6 PTAD5 PTAD4 PTAD3 PTAD2 PTAD1 PTAD0
44
45
Polled Mode
Using polled mode requires the use of a spin lock. Firstly the A/D system is congured as required: It is enabled, the type and number of conversion congured, the triggering type setup and the interrupts are disabled. The conversion process is started by writing the desired value to ATD0CTL5. The program then needs to wait until the conversion is complete before reading the result. The SCF ag in the ATD0STAT0 register is set once the conversion is complete. So it will require a spin lock like SPIN: BRCLR ATD0STAT0,$80, SPIN
46
Polled Mode
Example
mainloop: SpinLock: JSR InitAD MOVB #$00, ATD0CTL5 BRCLR ATD0STAT0,$80,SpinLock LDD .... Spin InitAD: BRA Spin MOVB #$80,ATD0CTL2 ; Turn on A/D Subsystem LDX #820 DBNE OFF X,* ; Delay a minimum of 100us MOVB #$E0,ATD0CTL2 ; Turn on A/D Subsystem,External Trigger and Interrupts MOVB #$08,ATD0CTL3 ; One conversion, FIFO off MOVB #$60,ATD0CTL4 ; Set Max sample time, 10 bit and Fast ATD Clock RTS ATD0DR0H
47
Interrupt Mode
It is enabled, the type and number of conversion congured, the triggering type setup and the interrupts are enabled. The conversion process is started by writing the desired value to ATD0CTL5.
The program then needs to wait until the conversion is complete before reading the result. However it can continue on to another task and doesnt need to wait for the result. The ISR will take care of processing the result for it once i is ready.
48
Interrupt Mode
Example
MOVB #$F7,IVBR mainloop: Spin InitAD: JSR InitAD MOVB #$00, ATD0CTL5 BRA Spin MOVB #$80,ATD0CTL2 ; Turn on A/D Subsystem LDX #820 DBNE X,* ; Delay a minimum of 100us MOVB #$E2,ATD0CTL2 ; Turn on A/D,External Trigger OFF and Interrupts ON MOVB #$08,ATD0CTL3 ; One conversion, FIFO off MOVB #$60,ATD0CTL4 RTS ATDISR: LDD .... RTI ORG $FFD2 DC.W ATDISR ; Set up Interrupt Vector Table ; ATD Vector ATD0DR0H ; Set Max sample time, 10 bit and Fast ATD Clock
49