Exercise7 - 0306-250 Assembly Language Programming Fall...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 0306-250 Assembly Language Programming Fall 2009 Laboratory Exercise Seven: A/D Conversion, PWM, and Servos This exercise investigates analog-to-digital (A/D) conversion and pulse-width modulation (PWM) on the Freescale HCS12 MCU Application Module using the HCS12 analog-todigital block (ATD) and pulse-width modulation module (PWM). A PWM waveform from the HCS12 is used to set the position of a Futaba S3003 servo. The objective of this exercise is to take a digital value converted from an analog input and to use it to set a servo to one of five positions. An assembly language program is created and is executed on the HSC12 module. Prelab Work 1. Write code to initialize the HSC12 ATD for polled conversion of channel 3 (AN3) to an unsigned 10-bit value right-justified in a word. Follow the class notes on the ATD posted on myCourses under ContentàCourse Resources. The notes also describe the wiring necessary for this exercise. 2. Write code to initialize the HSC12 PWM to produce on channel 0 a waveform with a 20-ms period and with a duty period of 2 ms. Follow the class notes on the PWM posted on myCourses under ContentàCourse Resources. The notes also describe the hardware configuration and wiring necessary for this exercise. 3. Write a subroutine PutNumW to print the unsigned word value in D to the terminal screen in decimal. You must write the subroutine so that the no registers other than CCR have changed values after return (RTS). Program Specification You need to write a program that uses the initialization code and PutNumW subroutine from your prelab work to control the servo using the value read from the Freescale project board’ potentiometer. Below is the sequence of operations the program must perform. 1. Initialize the HCS12 ATD for polled A/D conversion of analog input channel 3 to an unsigned 10-bit value right-justified in a word. 2. Initialize the HCS12 SCI for polled serial I/O with the properly commented subroutines developed in previous lab exercise, prompt using a format of eight data bits, no parity, and one stop bit—as in Lab Exercise Four. 3. Initialize the HCS12 PWM to generate a PWM waveform on channel 0 that has a period of 20 ms and a duty period of 2 ms. Page 1 of 3 0306-250 20091 Lab Ex. 7: A/D Conversion, PWM, and Servos Page 2 of 3 4. Initially set the servo position to 1 (i.e., full left deflection). 5. Using the properly documented PutString subroutine from Lab Exercise Four, output the character string below to the terminal screen followed by a carriage return character ($0D) and a line feed character ($0A) to advance the cursor to the beginning of the next line. Adjust potentiometer to set servo position (1-5) and press any key. | 6. Using your properly documented PutNumW subroutine from prelab work along with PutString, output the digital value to the terminal screen as shown below. (Note that you may use up to five digits including leading zeroes to show the decimal value.) Adjust potentiometer to set servo position (1-5) and press any key. Digital value: 0| 7. Convert the digital value to an index between 0 and 4 (inclusive) corresponding to servo positions between 1 and 5 (respectively), and use the index to set the correct PWM duty period for the servo so that the servo moves to the appropriate position. 8. Using PutString and PutNumW , output the servo position to the terminal screen as shown below. (Note that you may use up to five digits including leading zeroes to show the decimal value.) Adjust potentiometer to set servo position (1-5) and press any key. Digital value: 0 Servo position: 1 | 9. Repeat steps 5-8. Lab Procedure 1. Create a new CodeWarrior directory (folder) and project on your X: drive for this exercise. 2. Write a properly commented and properly formatted HCS12 assembly language program to set the position of a servo connected to PWM0 based on the voltage read from a potentiometer connected to AN3, according to the preceding specification. Note that you will need to adjust the PWM duty period values for your lookup table from the calculated values in the class notes to the calibration of your servo. (Suggestion: first get your program to do everything except specification seven, so that you can test it without connecting the servo.) 3. Assemble the program in CodeWarrior compiler to create a listing file. 4. Link the program in CodeWarrior to create a linker map file. 5. Test your program for proper setting of the servo (from positions 1 to 5) over the full range of the potentiometer, which must be demonstrated to the instructor. 6. Demonstrate your program for the lab instructor. Following demonstration, print the listing file, linker map file, and terminal screen output, and have your lab instructor sign your grading sheet and printed pages. Report 0306-250 20091 Lab Ex. 7: A/D Conversion, PWM, and Servos Page 3 of 3 Write a report consisting of the following sections. · Abstract · Procedure F Your procedure should include how you determined the PWM duty period values for the positioning of your servo. · Results · Conclusion Your writing should follow the rules of professional technical writing and should meet the specifications in “Laboratory and Report Guidelines” on the course reference material web page. Staple your cover page, report, listing file, linker map file, and grading sheet (in that order), and submit them at the beginning of the next lab session. Late reports are penalized 20% per day late, as defined in “Laboratory and Report Guidelines.” ...
View Full Document

This note was uploaded on 05/06/2010 for the course EECC 0306-250 taught by Professor Roymelton during the Fall '10 term at RIT.

Ask a homework question - tutors are online