ele22mic lecture 14 & 15
DESCRIPTION
ELE22MIC Lecture 14 & 15. Edge Detector Latch vs Flip Flop S-R Latch, Transparent D-Latch Clocked D-Latch J-K Flip Flop, Toggle Flip Flop Flip Flop Applications Register/Memory, Shift Register, Counter 68HC11 Analog to Digital Converter Variable Speed Stepper Motor Application. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/1.jpg)
ELE22MIC Lecture 14 & 15• Edge Detector
• Latch vs Flip Flop– S-R Latch, Transparent D-Latch– Clocked D-Latch– J-K Flip Flop, Toggle Flip Flop
• Flip Flop Applications– Register/Memory, Shift Register, Counter
• 68HC11 Analog to Digital Converter
• Variable Speed Stepper Motor Application
![Page 2: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/2.jpg)
![Page 3: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/3.jpg)
68HC11 Timer - PreScaler
• Crystal Frequency vs clock Pre-Scaler
![Page 4: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/4.jpg)
Edge DetectionPositive-Going Edge Detection
![Page 5: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/5.jpg)
Clocked Set Reset Latch
![Page 6: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/6.jpg)
Transparent D Latch
![Page 7: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/7.jpg)
Edge Triggered D Flip FlopPositive Clock Edge-Triggered
D Flip Flop
![Page 8: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/8.jpg)
J-K Flip Flop
![Page 9: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/9.jpg)
Toggle Flip FlopWhile the toggle pin is held high, the Q line changes state on every positive CLK transition.
![Page 10: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/10.jpg)
4 Bit - Ripple Counter
![Page 11: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/11.jpg)
Timer-Counter Pre-Scaler
![Page 12: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/12.jpg)
3 Bit Shift Register
![Page 13: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/13.jpg)
Variable Speed Stepper Motor
• The next application we will look at is a Variable Speed Stepper Motor control
• The forward/reverse speed is controlled by a potentiometer connected to the ADC input
![Page 14: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/14.jpg)
Variable Speed Stepper Motor
• The unsigned potentiometer value is biased by 128 so that mid-way = 0 speed, 255 = full speed forwards, -255 = full speed reverse.
• The stepper motor coil activation sequence is controlled by four output lines of Port A
![Page 15: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/15.jpg)
ULN2003
![Page 16: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/16.jpg)
Stepper Motor
![Page 17: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/17.jpg)
ULN2003
![Page 18: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/18.jpg)
Variable Speed Stepper Motor (1)
REGBAS EQU $1000 Starting address for register blockRAM EQU $2000PORTA EQU $00 Port A INPUT:PA0..2, OUTPUT:PA3..6, & I/O PA7* Port Outputs can be used when not using timer* latches specified in TCTL1 (below)PORTB EQU $04 Output port BCFORC EQU $0B Force Output Compare...OC1M EQU $0C OClM7,OClM6,OClM5,OClM4;OClM3,-,-,-OC1D EQU $0D OClD7,OClD6,OClD5,OClD4;OClD3,-,-,-TCNT EQU $0E Free running counter (16 bit)TIC1 EQU $10 IC1 register (16 bit)TOC1 EQU $16 OC1 register (16 bit)TOC2 EQU $18 OC2 register (16 bit)TOC3 EQU $1A OC3 register (16 bit)
![Page 19: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/19.jpg)
Variable Speed Stepper Motor (2)
TCTL1 EQU $20 OM2,OL2,OM3,OL3;OM4,OL4,OM5,OL5TCTL2 EQU $21 -,-,EDGlB,EDGlA;EDG2B,EDG2A,EDG3B,EDG3ATMSK1 EQU $22 OC1I,OC2I,OC3I,OC4I;OC51,IC1I,IC2I,IC3ITFLG1 EQU $23 OC1F,OC2F,OC3F,OC4F;OC5F,IC1F,IC2F,IC3FTMSK2 EQU $24 TOI,RTII,PAOVI,PAII;-,-,PR1,PR0TFLG2 EQU $25 TOF,RTIF,PAOVF,PAIF;-,-,-,-PACTL EQU $26 DDRA7:PAEN:PAMOD:PEDGE:-:-:RTR1:RTR0* DDRA7 - Data Direction Register for Port A bit 7* PAEN - Pulse Accumulator ENable* PAMOD - For Pulse Accumulator - See Section 11 of ref.man.* PAMOD = 0 -> Event Count,* PAMOD= 1 -> Gated Time Accumulation* RTR1:RTR0 - Select Real Time Interrupt Rate
![Page 20: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/20.jpg)
Variable Speed Stepper Motor (3)
*** HC-COM Routine Addresses & Pseudo Vector Equates.OUTA EQU $FFB8 Print character in A-reg.OUTCRL EQU $FFC4 Output <cr><lf>.OUTSTO EQU $FFCA Output Msg seg (no <cr,lf>).OUTSTR EQU $FFC7 Output Msg w/leading <cr,lf>PVIC1 EQU $00E8 EVB Pseudo Vector for IC1PVTOF EQU $00D0 EVB Pseudo Vector for TOFPVOC2 EQU $00DC EVB Pseudo Vector for OC2PVOC1 EQU $00DF EVB Pseudo Vector for OC1
REGS EQU $1000 * 68HC11 Config Registers base locationTOF EQU %10000000 * Timer overflow flagN1 EQU 30 * times for one sec
![Page 21: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/21.jpg)
Variable Speed Stepper Motor (4)
OPTION EQU $39ADCTL EQU $30ADR1 EQU $31ADSET EQU %00000100 * A/D input on PE-4CCF EQU %10000000 * Conversion complete flagADPU EQU %10000000 * A/D power up bit* * * Monitor EquatesOUTLHF EQU $FFB2 Print left halfOUTRHF EQU $FFB5 Print right halfCRLF EQU $FFC4 Print CRLF
![Page 22: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/22.jpg)
Variable Speed Stepper Motor (5)
*** RAM Variable Assignments ORG RAM Start variables in EVB RAM (upper half) JMP STARTHDLY RMB 2 Half-cycle delay (in 0.5mS increments)
* Some routines use only first 5 bytes of DBUFRADCVAL RMB 1StepDirn RMB 2
StepPtr RMB 2 * Pointer to items in following tableStepTable FCB %0001000, %0100000, FCB %0010000, %1000000, StepEnd EQU *
![Page 23: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/23.jpg)
Variable Speed Stepper Motor (6)
START:TOP5 LDS #$0047 * Top of User's Stack area on EVB LDD #$0 STD StepDirn
LDD #$8000 STD HDLY
LDAA #$7E * Jump (extended) Opcode STAA PVOC2 * Pseudo Vector see manual text LDX #SV5OC2 * Address of OC2 service routine STX PVOC2+1 * Finish jump instruc to TOF svc
![Page 24: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/24.jpg)
Variable Speed Stepper Motor (7)
LDX #REGBAS * Point to 68HC11 configuration register block LDAA #%0000000 * STAA OC1M, X * Output Compare Mask = 0 for all OCs LDAA #%0000000 * OM2:OL2 = 0:1 STAA TCTL1,X * SET All timers not connected to outputs
LDAA #%1000000 * OM2:OL2 = 0:1 STAA TFLG1,X * Clear any pending,OC2F STAA TMSK1,X * Enable OC2 interrupts CLI * Enable Interrupts
LDX #StepTable STX StepPtr * StepPtr -> Start of stepper table values
![Page 25: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/25.jpg)
Variable Speed Stepper Motor (8)
LDX StepPtr * Get our table pointer -> X LDAA 0, X * Get the contents of the table -> Acc A LDX #REGBAS * Get configuration register base address -> X STAA PORTA, X * Store initial Stepper motor position
LDAA #%11111000 STAA OC1D, X STAA CFORC, X
BSET OPTION,x ADPU * Power up the ADC* JSR delay100us * Wait for Charge Pump to stabilise
![Page 26: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/26.jpg)
Variable Speed Stepper Motor (9)
* Start the conversion SCAN=0, MULT=0FOREVER: * Beginning of LOOP-FOREVER LDAA #ADSET * Select ADC input from Port E-4 STAA ADCTL,x * Signal ADC to start conversion
* Wait until conversion doneconvwait: BRCLR ADCTL,x CCF convwait
* Get the input and print it using the BUFFALO Monitor LDAA ADR1, x * Get ADC converted input voltage value
![Page 27: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/27.jpg)
Variable Speed Stepper Motor(10)
PSHA SUBA #$80 STAA ADCVAL * Store for ISR use BPL PlusOne BMI MinusOne LDD #0 BRA StorDirn * If 0, store 0PlusOne: LDD #1 BRA StorDirnMinusOne: NEGA * A = -A STAA ADCVAL * Store for ISR use LDD #-1
![Page 28: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/28.jpg)
Variable Speed Stepper Motor(11)
StorDirn: STD StepDirn
LDAA ADCVAL SUBA #$7F NEGA ASLA LDAB #0 STD HDLY * Speed - save delay PULA TAB * save it (A) in B JSR OUTLHF * output high nybble TBA * restore it to A JSR OUTRHF * output low nybble JSR CRLF * output carriage return - line feed
![Page 29: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/29.jpg)
Variable Speed Stepper Motor(12)
* Clear the TOF to start the delay JSR delay100us
BRA FOREVER * loop forever
![Page 30: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/30.jpg)
Variable Speed Stepper Motor(13)
**** SV5OC2 - Output Compare 2 service routine* Called at each OC2 interrupt.***SV5OC2: LDD HDLY * Get delay time for 1/2 cycle LDX #REGBAS ADDD TOC2,X * Add HDLY to last compare value STD TOC2,X * Update OC2 (schedule next edge) BCLR TFLG1,X $BF * Clear OC2F
LDD StepPtr * X = Table Pointer ADDD StepDirn * 1, 0 or -1 XGDX
![Page 31: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/31.jpg)
Variable Speed Stepper Motor(14)
CPX #StepEnd * If at end of table, then wrap to start BLT NoWrap LDX #StepTable * by Re-Loading the starting address of table BRA StorePtrNoWrap: CPX #StepTable * If before start of table, then wrap back to end BGE NoWrapBack LDX #StepEnd-1 * by Loading the ending address of tableNoWrapBack:StorePtr: STX StepPtr * Save next address LDAA 0, X * A = Next Stepper Value
![Page 32: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/32.jpg)
Variable Speed Stepper Motor(15)
* LDX #REGBAS STAA REGBAS+PORTA * activate next stepper coil
RTI ** Return from OC2 service **
![Page 33: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/33.jpg)
Variable Speed Stepper Motor(16)
* ------------------------------------------------------------------------------------* This subroutine delays (a little over) 100 micro-seconds* ------------------------------------------------------------------------------------delay100us: PSHA * save Accumulator A* * Generate a "short" delay > 100 microsec LDAA #40 * 40 loops for 200 clock cycles at 0.5 micro seconds/clockDELAYLOOP: DECA * BNE DELAYLOOP PULA * restore Accumulator A RTS *
![Page 34: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/34.jpg)
Analog to Digital Converter
• Analog to Digital Converter section of 68HC11
• Requires 32 E-clock cycles to complete a conversion
• 8-bit successive approximation converter.
• Uses Charge re-distribution for manufacturability reasons.
• As it is based upon capacitance it automatically includes Sample & Hold functionality
![Page 35: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/35.jpg)
Analog to Digital Converter
• Analog switches are used to provide ADC internal capacitor switching and input multiplexor selection switching.
• Uses internal charge pump -> 7 to 8V– Provides high gate voltages to operate analog switches -
guarantees low impedance.
– must be enabled (disabled at reset)
– A/D Power Up (ADPU) control bit
– after starting charge pump, must delay 100us before using ADC
![Page 36: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/36.jpg)
Analog to Digital Converter
• Uses clock sources - must be selected
• Four channels are converted in sequence with the results provided in registers
![Page 37: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/37.jpg)
ADC - Input Sample
In the sample phase of the conversion:
VX, the input voltage, is used to charge the bottom plate of the capacitors relative to the VL low reference (top plate).
VX
![Page 38: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/38.jpg)
ADC - Sample
Time is allowed to elapse for 12 cycles, sufficient time for VC, the voltage on the capacitors, to charge to VX - VL.
Working with ratios of capacitances.
Total Charge is Q = 8 + 4 + 2 + 1 + 1 = 16 units.
The Charge Q = 16 (VX - VL). Setting VL =0 volts => Q = 16 VX.
![Page 39: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/39.jpg)
ADC - Hold
In the hold phase of the conversion:
The charge remains on the capacitors, and the capacitors bottom plate (reference) is shifted to VL.
QH = - 16 Vi (assuming VL =0). Now Vi = - (VX - VL).
![Page 40: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/40.jpg)
ADC - Conversion (1)
![Page 41: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/41.jpg)
ADC - Conversion (2)
In the Successive Approximation phase of the conversion:
The voltage on the capacitors, is re-distributed between the 1 unit capacitor, and the VH reference voltage.
The ratio of capacitance determines Vi = (VH/VL) CSEL/C1.
The resulting comparator input voltage is set reflects the input
Resistive losses and timing are ignored to simplify analysis.
![Page 42: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/42.jpg)
ADC - Conversion (3)
Starting with the 8 unit capacitor (MSB), it is switched VH.
The charge is Q = 8 (VH - Vi) + 8 (VL - Vi).
Q = 8VH - 16Vi assuming Vi = 0.
The ratio of capacitance determines Vi = (VH/VL) CSAR/C1.
The resulting comparator input voltage is set reflects the input ratio.
If the VX < 8/16 (VH - VL) then Vi > VL and the comparator will output a 1. C8 is set to VH, and a 1 is saved in the MSB of the Successive Approximation register (SAR).
Conversely if VX > 8/16 (VH - VL) then the comparator will output a 0. C8 is set to VL, And a 0 is saved in the MSB of the Successive Approximation register.
![Page 43: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/43.jpg)
ADC - Conversion (4)
Next the 4 unit capacitor (MSB), the capacitor is switched VH.
The resulting comparator input voltage is set reflects the input ratio.
And the SAR will save the value of the next most significant bit.
The ADC continues through the rest of the bits until all capacitors have been set and the SAR holds the value of the conversion.
Upon conversion completion:
VX = (VH - VL) x (SAR / 256)
![Page 44: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/44.jpg)
ADC - OPTION register
Setting the ADPU bit = 1 turns on the on-chip charge pump.
The CSEL Control Bit selects which charge pump is activated:
0 - ADC (highest ADC accuracy)
1 - EEPROM (needed for EEPROM efficiency)
![Page 45: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/45.jpg)
ADC - ADCTL register
The ATCTL Control Register Specifies Channel Assignments
The CCF flag is set to 1 upon completion of 4 conversions, so we can wait for conversion complete using the BRCLR instruction.
If the SCAN bit = 1, continuous conversions occur and the CCF bit is always 1.
CCF can only be read. Bits 0..5 are read/write.
![Page 46: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/46.jpg)
ADC - SCAN bit
• SCAN - Continuous Scan Control
– If SCAN=0, four conversions are performed, filling the four result registers.
– If SCAN=1, then the A-D conversion continues in a round-robin fashion, and the result registers are updated (but the CCF bit remains set).
– CD = 0, CC=0 -> AN0..AN3 in ADR1..ADR4
– CD=0, CC = 1 -> AN4..AN7 in ARD1..ADR4
![Page 47: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/47.jpg)
ADC - MULT bit
• MULT - Multiple Channel Control
– If the MULT bit=0, then a single channel is converted and the result stored.
– If MULT=1, then a conversion is performed on each channel in a group of 4 channels
![Page 48: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/48.jpg)
ADC - Channel Assignments
![Page 49: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/49.jpg)
ADRx - AD Result Registers
• The ADRx Results registers receive the converted level from the ADC.
– ADR1 - $1031
– ADR2 - $1032
– ADR3 - $1033
– ADR4 - $1034
![Page 50: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/50.jpg)
ADC Code (1)
REGS EQU $1000 ; RegistersTOF EQU %10000000 ; Timer overflow flagN1 EQU 3030 ; times for one secTFLG2 EQU $25OPTION EQU $39ADCTL EQU $30ADR1 EQU $31ADSET EQU %00000100 ; A/D input on PE-4CCF EQU %10000000
; Conversion complete flagADPU EQU %10000000 ; A/D power up bit
![Page 51: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/51.jpg)
ADC Code (2)
; Monitor EquatesOUTLHF EQU $FFB2 Print left halfOUTRHF EQU $FFB5 Print right halfCRLF EQU $FFC4 Print CRLF
; Memory Map EquatesCODE EQU $2000DATA EQU $7000STACK EQU $05F
ORG CODELDS #STACKLDX #REGS
![Page 52: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/52.jpg)
ADC Code (3)
; Power up the A/D charge pump.BSET OPTION,x ADPU
; Generate a "short" delay > 100 microsec LDAA #40 ; 40 loops for 200 clock cycles
DELAY:DECABNE DELAY
; Start the conversion SCAN=0, MULT=0LOOP:
LDAA #ADSETSTAA ADCTL,x
![Page 53: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/53.jpg)
ADC Code (4)
; Wait until conversion donespin:
BRCLR ADCTL,x CCF spin
; Get the input and print it using the BUFFALO MonitorLDAA ADR1,xTAB ; save it
JSR OUTLHFTBA ; restore itJSR OUTRHFJSR CRLF
![Page 54: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/54.jpg)
ADC Code (5)
; Delay approx 1 second using the timer overflowLDAB #N1 ; Clear the TOF to start the delay
delay1:ldaa #TOFstaa TFLG2,x ; and wait for N1 overflows
spin1: TST TFLG2,xBPL spin1
DECBBNE delay1BRA loop
![Page 55: ELE22MIC Lecture 14 & 15](https://reader035.vdocuments.mx/reader035/viewer/2022070410/568145b0550346895db2ae7a/html5/thumbnails/55.jpg)
Acknowledgments
• Images of the configuration registers, and some source code examples, are derived from the Motorola M68HC11 Reference Manual