DOC PREVIEW
GVSU EGR 345 - Lab 1 - Analog I/O with the 6811

This preview shows page 1-2-3-4 out of 11 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 11 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

3.0.1 Lab 1 - Analog I/O with the 68113.0.1.1 - Purpose3.0.1.2 - Background/Theory3.0.1.3 - Prelab3.0.1.4 - Equipment3.0.1.5 - Experimentalegr345 lab guide - 3.13.0.1 Lab 1 - Analog I/O with the 68113.0.1.1 - PurposeTo use the 6811 microcontroller boards to input and output analog data.3.0.1.2 - Background/TheoryA method for generating analog outputs, called Pulse Width Modulation (PWM), is shown in Figure 3.1. If the output is on all the time, the effective output voltage is the maximum voltage of the output. If the output is only on half the time, the effective output voltage is only half. By varying the ratio of on-time to off-time, the effective voltage is varied. The percentage of time that the signal is on is called the duty cycle. So, if the volt-age is only on half the time, the effective voltage is half the maximum voltage, and the duty cycle is 50%. This method is popular because it can produce a variable effective volt-age efficiently. (Aside: The frequency of these waves is normally above 20KHz, above the range of human hearing.) A program for generating a PWM output from a 68HC11 was written by Dr. Blauch, and is available on his website.Figure 3.1 Pulse Width Modulation (PWM)Vmax0tVeff50100---------Vmax=50% duty cycleVmax0tVeff20100---------Vmax=20% duty cycleVmax0tVeff100100---------Vmax=100% duty cycleVmax0tVeff0100---------Vmax=0% duty cycleegr345 lab guide - 3.2An analog to digital (A/D) converter converts an analog input voltage to a digital value. A successive approximation A/D converter is shown in Figure 3.2. This device is like the one in the 6811. The main operation concept is based on the successive approxi-mation logic. Once the reset is toggled the converter will start by setting the most signifi-cant bit of the 8 bit number. This will be converted to a voltage Ve that is a function of the +/-Vref values. The value of Ve is compared to Vin and a simple logic check determines which is larger. If the value of Ve is larger the bit is turned off. The logic then repeats sim-ilar steps from the most to least significant bits. Once the last bit has been set on/off and checked the conversion will be complete, and a done bit can be set to indicate a valid con-version value.Figure 3.2 Analog to digital converterIn the 68HC11, the A/D converter is 8 bit, and there are up to eight inputs avail-able. To operate the A/D converter the following steps must be used.1. Activate the A/D converter by setting the ADPU bit in the options register.2. Start an A/D conversion by writing to the A/D control register3. Wait until the conversion is done (32 clock cycles)4. Read the analog input value.Once the analog input value has been read it can be converted back into a voltage using equation (2).D to Aconvertersuccessiveapproximationlogic88+-clockresetdata out+Vref-VrefVinVeVin above (+ve) or below (-ve) Vedoneegr345 lab guide - 3.3When collecting data we are concerned with the data value, but also with when the data was read. In our case we will establish a time base for the data, by reading it at regular intervals. In the 68HC11, we do this using an interrupt. More specifically, we will use timed interrupts that run a program at a regular interval. In the 6811 the default interrupt time is 4.096 ms, however this can be changed by writing a new value to (0x____). For the Axiom boards the interrupts are enabled writing the start of the subroutine address to 0x00EC.Numerical Limits, 2s compliments, ETC.. XXXXXXXXR 2N=where,R resolution of A/D converter=VIt h e i nt e g e r v a l u e f rom the A/D conveter=VCVIR 1–------------VmaxVmin–()Vmin+=VCthe voltage calculated from the integer value=(1)(2)N number of bits=long int i;unsigned v1;int v2;char v3;unsigned v4;for(i = 0; i < 2000000; i++){// print the values}FILL IN USING SIGNED INTEGER PRINTegr345 lab guide - 3.4XXXXXXXXXXXXXXX Interrupt subroutines3.0.1.3 - Prelab1. Review C programming using previous course materials.2. Review the EGR 226 course materials.3. Read the analog I/O section in the reference manual available on the course home page.4. Review the analog I/O chapter in the textbook.3.0.1.4 - EquipmentComputer with an Internet connectionAxiom M68HC11 board10K potentiometermultimeteroscilloscope3.0.1.5 - Experimentalint main(){char mode = 0;char value;do {key = getch();if((key => ’0’) && (key <= ’9’)){value = (key - ’0’) * 10;} else if (key == ’u’){outhex16(value);} else if (key == ’q’){mode = 1;} else {putstr("key not recognized \n");}} while (mode == 0);return 0;}egr345 lab guide - 3.51. (If necessary) Look for a ’68HC11’ folder on the desktop, if it is not present download and install the C compiler for the 68HC11. See the EGR 345 and 226 course pages for additional information. You may also want to review some of the basic methods for compiling, downloading and executing programs.2. (For review) Enter the program in Figure 3.3 using ’Notepad’ or some other text editor. Compile the program using ’GCC6811 test1.c’. Start Hyperterm using the ’EVBU.ht’ icon. Turn on the EVBU, connect it to the serial port and reset the board. Type ’LOAD T’ and then download the text file ’test1.s19’ using Hyperterm. Run the program with ’G 1040’.Figure 3.3 test1.c - Simple program for the 68HC113. The program in Figure 3.4 is an example of an interrupt driven routine. Enter and test the program. Verify that the interrupt is occuring every 4ms.#include <hc11a8.h>#include <buffalo.h>int main(void){ui_loop();return 0;}void ui_loop(){unsigned foo;unsigned count;unsigned i;int val;foo = '0';for(; foo != 'q';){putstr("How many times to loop (0 - 9, or q to quit) \n");foo = getch();count = foo - '0';if((count > 0 ) && (count <= 9)){for(i = 0; i < count; i++){putstr("Looping dec=");outhex8(i);putstr(" hex=");val = i;outhex16(val);putstr("\n");}}}return 0;}egr345 lab guide - 3.6Figure 3.4 test2.c - An example of a timed interrupt4. The program in Figure 3.6 shows an example of reading analog inputs. The ana-log inputs are read continuously, and the interrupt driven subroutine checks the inputs every 4 ms. Once a second (250 * 4ms) the analog value is printed. Set up the controller as shown in Figure 3.5 and verify the operation of the pro-gram. To verify the operation, set the potentiometer, use a DMM to verify the #include <hc11e9.h>#include <buffalo.h>unsigned count = 0;unsigned seconds = 0;void realtime_update(){count++;if(count > 250){ /* once a second */count =


View Full Document

GVSU EGR 345 - Lab 1 - Analog I/O with the 6811

Documents in this Course
Y Axis

Y Axis

2 pages

Load more
Download Lab 1 - Analog I/O with the 6811
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 Lab 1 - Analog I/O with the 6811 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 Lab 1 - Analog I/O with the 6811 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?