Download presentation
Presentation is loading. Please wait.
1
Analog-to-Digital Converter Chapter 9 MC9S12DP256
2
Method of Successive Approximation
3
Implementing Successive Approximation
30
\ 9S12DP256 Analog-to-Digital Converter -- File: ATD256.WHP HEX 0082 CONSTANT ATD0CTL2 \ ATD Control Register 2 0084 CONSTANT ATD0CTL4 \ ATD Control Register 4 0085 CONSTANT ATD0CTL5 \ ATD Control Register 5 0086 CONSTANT ATD0STAT \ ATD Status Register 0090 CONSTANT ADR00H \ A/D Result Register 0 : ADCONV.ON ( -- ) 85 ATD0CTL4 C! \ 8-bit resol, /8 clock C0 ATD0CTL2 C! ; \ Set ADPU and AFFC : ADCONV.OFF ( -- ) 0 ATDCTL2 C! ; \ Clear ADPU : WAIT.FOR.CONV ( -- ) BEGIN 7 ATD0STAT ?HI UNTIL ;
31
: AVG4 ( -- n ) \ Average 4 values in ADR0 - ADR3 0 ADR00H 2- 4 FOR \ sum addr DUP R@ 2* + C@ \ sum addr val ROT + SWAP \ sum addr NEXT DROP 4 / ; : ADCONV ( ch# -- val ) \ Avg 4 readings from channel ch# ADCONV.ON 8 MOD 80 OR ATDCTL5 C!\ ch# < 8; SCAN=0 MULT=0 WAIT.FOR.CONV AVG4 ADCONV.OFF ;
32
: GET.4VALUES ( -- val4 val3 val2 val1 ) \ read 4 a/d regs ADR0H 2- 4 FOR \ addr1 DUP R@ 2* + C@ SWAP \ valn addr1 NEXT DROP ; : ADCONV03 ( -- val3 val2 val1 val0 ) \ Convert 1st 4 channels ADCONV.ON 10 ATDCTL5 C! WAIT.FOR.CONV GET.4VALUES ; : ADCONV47 ( -- val3 val2 val1 val0 ) \ Convert 2nd 4 channels ADCONV.ON 14 ATDCTL5 C! WAIT.FOR.CONV GET.4VALUES ; DECIMAL
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.