DOC PREVIEW
NMT EE 308 - EE 308 Pre-Lab

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 8 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 8 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 8 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 8 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

EE 308 Spring 2006 9S12 Subsystems: Pulse Width Modulation, A/D Converter, and Synchronous Serial InterfaceIn this sequence of three labs you will learn to use three of the 9S12's hardware subsystems. WEEK 1Pulse Width ModulationPre-Lab1. Calculate the times asked for in Part 3.2. Determine values you need to write to the PWM registers (except for the Duty Cycle register) to control the motor.3. Calculate the values needed for the Duty Cycle Register to give the duty cycles needed for Part 4.Introduction and ObjectivesThe speed of a motor can be adjusted by powering it with a pulse width modulated signal. Figure 1 shows how this can be done. The L293D motor controller as a switch. When the signal on the enable (EN1) input of the L293D is high the switch is closed, current flows through the motor, and the motor speeds up. When the signal is low, the switch is open, no current flows, and the motor slows down. IN1 and IN2 determine the direction of the motor. When IN1 is high and IN2 is low, OUT1 will be high and OUT2 will be low. Changing the logic levels of IN1 and IN2 reverse the voltage levels on OUT1 and OUT2, and the motor changes direction. With a high enough frequency PWM signal the amount the motor speeds up and slows down in one period is negligible, and the motor turns at a constant speed. By adjusting the duty cycle the speed of the motor can be controlled. For the motors you will be using in this lab, use a PWM frequency of about 5 kHz.Page 1EE 308 Spring 2006 Figure 1. Using a pulse-width-modulated (PWM) signal to adjust the speed of a motor.To make a motor turn at a desired speed it is necessary to know how fast the motor is turning. The motors you will use in this lab have encoders which will generate 15 pulses in a single revolution of the motor. A light emitting diode (LED) sends light through a wheel with holes in it which is attached to the shaft of the motor, and an optical sensor detects light. When the light shines through a hole and hits the sensor, the output of the optical sensor is Vcc (a digital 1); when the wheel blocks the light from reaching the sensor, the voltage goes to 0 V (a digital 0). Using this optical encoder you will be able to measure the speed of the motor. The motors we will use have two optical encoders, on opposite sides of the wheel. This allows you to determine both the speed and the direction of the motor, using a technique called quadrature detection. This will be discussed more in the final lab for the course. For this lab, use just one of the optical encoders.In this lab you will use the PWM subsystem of the 9S12 to adjust the speed of a small motor, and use the input capture subsystem to measure the speed of the motor.For the pre-lab do the calculations required for Parts 3 and 4. Write the program required for Parts 5.Page 2EE 308 Spring 2006 1. Connect the motor directly between 0 and 15 V to verify that the motor turns (Do not use the L293D for this part.) Connect the Red lead from the optical encoder to Vcc, and the Black lead to ground. Have a TA or Instructor check your wiring before turning the power on. The motors and encoders are fairly expensive, and we do not want to burn up any of them. Use a log-ic probe to verify that the Blue lead from the optical encoder is pulsing, indicating that the en-coder is working.2. Program your 9S12 to generate a PWM frequency of 5 kHz, with an active high PWM signal with a duty cycle of 50%. Connect the circuit shown in Figure 1. Use your logic probe to verify that the optical encoder is working. 3. Connect the output of the optical sensor to one of the input capture pins of the 9S12. To your program from Part 2, add code to use the input capture function to measure the period of the sig-nal from the optical encoder, and to print the value to the terminal. (Note that you should use an interrupt to measure the period, and in the interrupt service routine set a global variable to the number of clock cycles between rising edges. You should print this number to the terminal in the main program loop, not in the ISR.)The motor speed at 100% duty cycle will be about 500 RPM. Plan to operate the motors between 50 RPM and 500 RPM. We will set the prescaler such that we can measure speeds as low as 20 RPM (to avoid overflow of the TCNT register in case the motor slows down below the 50 RPM lower limit).a) With a 500 RPM motor speed, how much time will there be between successive rising edges from the optical sensor?b) With a 20 RPM motor speed, how much time will there be between successive rising edges from the optical sensor?Set the prescaler of the 9S12 so the rollover time of the TCNT register is the smallest time which is larger than the above two numbers. What value did you use for the prescaler?4. Modify your program to set the duty cycle based on the state of four of your DIP switches. The duty cycle of the signal should be determined by reading the four DIP switch values into the four least significant bits of Port B:Page 3EE 308 Spring 2006 PORTB Duty Cycle PORTB Duty Cycle0000 6.25% 1000 56.25%0001 12.50% 1001 62.50%0010 18.75% 1010 68.75%0011 25.00% 1011 75.00%0100 31.25% 1100 81.2550101 37.50% 1101 87.50%0110 43.75% 1110 93.75%0111 50.00% 1111 100.00%Note that you should pre-calculate the duty cycles as the integer you will write to the duty cycle register which will give duty cycles closest to the values in the table. (Do this for part of your pre-lab.) Do not use floating point arithmetic in your C program.5. Run the motor with each of the duty cycles from Part 4. Have the 9S12 print the number of timer pulses between rising edges to the terminal. Record these numbers, and convert them to RPM. Record the speed in RPM for each duty cycle. Plot the motor speed as a function of duty cycle. How linear is it?6. Compare your results (speed of the motor vs. duty cycle) to the results of at least two other groups. Do the motors all behave the same, or are there significant differences?Page 4EE 308 Spring 2006 THE 9S12 ANALOG TO DIGITAL CONVERTERWEEK 2Pre-Lab1. Write the program for Parts 1 and 2.2. Calculate the expected 10-bit result when the voltage input to PAD8 is: 2.1.0.0 V 2.2.1.0 V 2.3.2.0 V 2.4.2.5 V 2.5.3.0 V 2.6.4.0 V 2.7.5.0 VPre-Lab 2.8. 2.9.1.Write the program for Parts 1 and 2. 2.10.2.Calculate the expected 10-bit result when the voltage input to PAD8 is: 2.11.a)0.0 V


View Full Document

NMT EE 308 - EE 308 Pre-Lab

Documents in this Course
Load more
Download EE 308 Pre-Lab
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 EE 308 Pre-Lab 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 EE 308 Pre-Lab 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?