Hardware Reference
In-Depth Information
Stop AD0 when in wait mode (set bits 5 to 1)
Disable external trigger on channel 7 (set bits 4, 3, and 2 to 0)
Disable AD0 interrupt (set bit 1 to 0)
Write the value $E0 into this control register.
The setting of the ATD control register 3 is as follows:
Perform four conversions
Disable FIFO mode
When BDM becomes active, complete the current conversion then freeze
Write the value $22 into ATD0CTL3.
The setting of the ATD control register 4 is as follows:
Select 10-bit operation (set bit 7 to 0)
Set sample time to two A/D clock periods (set bits 6 and 5 to 00)
Set the value of PRS4,PRS0 to 00101
Write the value $05 to this control register.
The setting of the ATD control register 5 is as follows:
Result register right-justified (set bit 7 to 1)
Result is unsigned (set bit 6 to 0)
Nonscan mode (set bit 5 to 0)
Single-channel mode (set bit 4 to 0)
Select channel 7 (set bits 2..0 to 111)
Write the value $87 to this control register
The following subroutine will perform the desired ATD confi guration:
#include
“c:\miniide\hcs12.inc”
openAD0
movb
#$E0,ATD0CTL2
jsr
wait20us
; wait for 20 μ s
movb
#$22,ATD0CTL3
movb
#$05,ATD0CTL4
rts
wait20us
movb
#$90,TSCR1
; enable TCNT and fast timer flag clear
movb
#0,TSCR2
; set TCNT prescaler to 1
bset
TIOS,$01
; enable OC0
ldd
TCNT
; start an OC0 operation
addd
#480
;
std
TC0
;
brclr
TFLG1,C0F,*
; wait for 20 μ s
rts
This routine does not write into the ATD0CTL5 register because that would start the conver-
sion. We should write into the ATD0CTL5 register only when we want to perform the conversion.
The C language version of the subroutine is as follows:
void wait20us (void);
void openAD0 (void)
{
ATD0CTL2 5 0xE0;
wait20us();
Search WWH ::




Custom Search