Unformatted text preview:

Example – A/D converterObjectiveprogram A/D converterSingle channel, single conversion, Mult=0, Scan=0Flowchart and codeexecutionSingle channel, continuous conversion, Mult=0, Scan=1Multiple channel, Single Conversion, Mult=1, Scan=0Multiple channel, Continuous conversion, Mult=1, Scan=1What you have learnedDr. Victor Giurgiutiu Page 1 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example A/D CONVERTEREXAMPLE – A/D CONVERTEROBJECTIVEThis example will help you learn how to use the M68HC11 microcontroller to collect analog data indigital form. The following objectives are considered:- Review the use of A/D conversion function of the M68HC11 microcontroller.- Illustrate various modes of performing A/D conversion.This example covers the following topics:- Single channel, single conversion, MULT=0, SCAN=0;- Single channel, continuous conversion, MULT =0, SCAN =1;- Multiple channel, single conversion, MULT =1, SCAN =0;- Multiple channel, continuous conversion, MULT =1, SCAN =1;PROGRAM A/D CONVERTERSINGLE CHANNEL, SINGLE CONVERSION, MULT=0, SCAN=0In this section, we will study the single-channel single-conversion. The channel selected in this examplewill be the pin PE1. The program will do the followinga) Initialize the A/D conversionb) Set ADCTL to reflect the following control bits:i) CD=0, CC=0, CB=0, CA=1 to select pin PE1ii) SCAN=0, i.e., no scanningiii) MULT=0, i.e., single channelc) Check if the A/D conversion has finished. The conversion is finished when the flag CCF is set.d) Load the results from the AD registers ADR1 – ADR4 and store them into memory locationsVAL1 – VAL4.e) Loop back to b)FLOWCHART AND CODEThe program flowchart is show below. Two flowchart levels are presented: the big-picture and thedetails. The big-picture is used to understand the overall architecture of the program. The details areused to explain some of the blocks. (Details are given only for those blocks which are somehow new,and have not been used in previous programs.) The essential code for this program is shown to theright of the flowchart. The essential code was incorporated into the standard template asm to generatethe code file Ex_AD_1.asm.Dr. Victor Giurgiutiu Page 2 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example A/D CONVERTER Big-picture Flowchart Flowchart Details -VAL1 1 byte -VAL2 1 byte -VAL3 1 byte -VAL4 1 byte Define variables -X=REGBAS -AD converter Initialize CCF=0? N Y -MULT = 0 -SCAN = 0 -CA=1 LABEL1 ADC Perform A/D conversion Store conversion results Store ADR1, ADR2, ADR3, ADR4 to VAL1, VAL2, VAL3, VAL4 CodeORG DATAVAL1 RMB 1VAL2 RMB 1VAL3 RMB 1VAL4 RMB 1* Main programORG PROGRAMSTART LDX #REGBAS* switch on A/D converterBSET OPTION,X,%10000000* Perform single A/D conversion on PE0,PE1,PE2,PE3ADC BSET ADCTL,X,%00000001; SCAN=0, . MULT=0, CA=1LABEL1 LDAA ADCTL,XANDA #%10000000BEQ LABEL1* Store the four consecutive conversion valuesLDAA ADR1,XSTAA VAL1LDAA ADR2,XSTAA VAL2LDAA ADR3,XSTAA VAL3LDAA ADR4,XSTAA VAL4BRA ADCORG RESETFDB STARTEXECUTIONOpen THRSim11. Close the Commands window. View CPU registers, AD converter registers, port Epins, memory list, Sliders E port. Open and assemble Ex_AD_1.asm. Reset registers and memory. Setstandard labels (Label/Set Standard Labels). Set display of ADCTL and accA to binary. Arrangewindows for maximum benefit: Press the RESET button. Your screen should look like this:Dr. Victor Giurgiutiu Page 3 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example A/D CONVERTERStep through the program up to LABEL1. The AD conversion control register ADCTL has been set toperform a single A/D conversion on the pin PE1. Your screen looks like this:We are now ready to perform the conversions. Set a breakpoint just after exiting the check CCF loop,i.e., at line $c010. Make the value of PE1 = 1000 mV. Run. The program performs the AD conversionand exists the loop. The registers ADR1 – ADR4 have the value $33, which is the hex value of1000*$ff/5000 (check with your hex calculator!). The screen looks like this:Dr. Victor Giurgiutiu Page 4 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example A/D CONVERTERStep through the program until all the four AD registers get transferred into the memory storagelocations VAL1 – VAL4. The screen looks like this:Remove the breakpoint from $c010. Enter 1500 mV into PE1. Run. The program will run continuously.The converted value $4c (1500*$ff/5000=$4c, check with your hex calculator!) appears in the ADR1 –ADR4 registers and is transferred into VAL1 – VAL4. The screen looks like this:Dr. Victor Giurgiutiu Page 5 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example A/D CONVERTERPut value 2000 mV into PE1. The converted value $66 (2000*$ff/5000=$66, check with your hexcalculator!) appears in ADR1 – ADR4 and then in VAL1 – VAL4. The screen looks like this:Dr. Victor Giurgiutiu Page 6 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example A/D CONVERTERPut value 2500 mV into PE1. The converted value $80 appears in ADR1 – ADR4 and then in VAL1 –VAL4 (2500*$ff/5000=$7f with normal 1 bit convention, check with your hex calculator!. But M68HC11uses ½ bit accuracy convention, and hence rounds up to $80). The screen looks like this:Put value 3500 mV into PE1. The converted value $b3 appears in ADR1 – ADR4 and then in VAL1 –VAL4 (3500*$ff/5000=$b2 with normal 1 bit convention, check with your hex calculator!. But M68HC11uses ½ bit accuracy convention, and hence rounds up to $b3). The screen looks like this:Dr. Victor Giurgiutiu Page 7 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example A/D CONVERTERPut value 5000 mV into PE1. The converted value $ff appears in ADR1 – ADR4 and then in VAL1 –VAL4 (5000*$ff/5000=$ff, check with your hex calculator!). The screen looks like this:At the end of this process, you have verified the conversion of six voltage values in the range 0 – 5 V,and have obtained the results indicated in Table 1.Dr. Victor Giurgiutiu Page 8 1/14/2019EMCH 367 Fundamentals of Microcontrollers Example A/D CONVERTERTable 1Voltage at pin PE1 (mV) AD converted values (Hex)1 1000 $332 1500 $4c3 2000 $664 2500 $805 3500 $b36 5000 $ffLet the program run, and move freely the slider bar on PE1. Observe the reaction time of the MCUsimulator, and how the converted


View Full Document

SC EMCH 367 - Example – A/D Converter

Download Example – A/D Converter
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Example – A/D Converter and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Example – A/D Converter 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?