DOC PREVIEW
NMT EE 308 - 9S12 SUBSYSTEMS

This preview shows page 1-2 out of 7 pages.

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

Unformatted text preview:

EE 308 Spring 2006 9S12 SUBSYSTEMS: PULSE WIDTH MODULATION, A/DCONVERTER, AND SYNCHRONOUS SERIAN INTERFACEIn this sequence of three labs you will learn to use the 9S12’S hardware sybsystem. 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) tocontrol 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 showshow this can be done. The L293D motor controller acts as a switch. When the signal on the enable input(EN1) of the L293DH is high the switch is closed, current flows through the motor, and the motor speedsup. When the signal is low, the switch is open, no current flows, and the motor slows down. IN1 and IN2determine the direction of the motor. When IN1 is high and IN2 is low, OUT1 will be high and OUT2 willbe low. Changing the logic levels of IN1 and IN2 reverses the voltage levels on OUT1 and OUT2, and themotor changes direction. With a high enough frequency PWM signal the amount the motor speeds up andslows down in one period is negligible, and the motor turns at a constant speed. By adjusting the duty cyclethe speed of the motor can be controlled. For the motors you will be using in this lab, use a PWMfrequency 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 motorsyou will use in this lab have encoders which will generate 15 pulses in a single revolution of the motor. Alight emitting diode (LED) sends light through a wheel with holes in it which is attached to the shaft of themotor, and an optical sensor detects the light. When the light shines through a hole and hits the sensor, theoutput 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 themotor. The motors we will use have two optical encoders, on opposite sides of the wheel. This allows youto 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 theinput 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.1. Connect the motor directly between 0 and 15 V to verify that the motor turns (Do not use theL293D for this part.) Connect the Red lead from the optical encoder to Vcc, and the Black lead toground. Have a TA or Instructor check your wiring before turning the power on. The motorsand encoders are fairly expensive, and we do not want to burn up any of them. Use a logic probeto verify that the Blue lead from the optical encoder is pulsing, indicating that the encoder is work-ing.2. Program your 9S12 to generate a PWM frequency of 5 kHz, with an active low PWM signal with aduty cycle of 50%. Connect the circuit shown in Figure 1. Use your logic probe to verify that theoptical encoder is working.Page 2 Port T7 Port Px Port Ax TxD RxD9S12ENA1 VDDIN1 OUT1GND GNDGND GNDOUT2IN2 VM ENA2PCDisplay L293D 1 16 +5V 2 Green 3 4 12 O 5 13 6 Yellow 7 +15 V 8 9 Tmotor VCC +5V RedBlue Black Optical EncoderEE 308 Spring 2006 3. Connect the output of the optical sensor to one of the input capture pins of the 9S12. To your pro-gram from Part 2, add code to use the input capture function to measure the period of the signalfrom the optical encoder, and to print the value to the terminal. (Note that you should use an inter-rupt to measure the period, and in the interrupt service routine set a global variable to the numberof clock cycles between rising edges. You should print this number to the terminal in the mainprogram loop, not in the ISR.)The motor speed at 100% duty cycle will be about 500 RPM. Plan to operate the motors between50 RPM and 500 RPM. We will set the prescaler such that we can measure speeds as low as 20RPM (to avoid overflow of the TCNT register in case the motor slows down below the 50 RPMlower limit).a) With a 500 RPM motor speed, how much time will there be between successive risingedges from the optical sensor?b) With a 20 RPM motor speed, how much time will there be between successive risingedges from the optical sensor?Set the prescaler of the 9S12 so the rollover time of the TCNT register is the smallest timewhich 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. Theduty cycle of the signal should be determined by reading the four DIP switch values into the fourleast significant bits of Port B: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 cycleregister 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 timerpulses 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 3EE 308 Spring 2006 THE 9S12 ANALOG TO DIGITAL


View Full Document

NMT EE 308 - 9S12 SUBSYSTEMS

Documents in this Course
Load more
Download 9S12 SUBSYSTEMS
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 9S12 SUBSYSTEMS 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 9S12 SUBSYSTEMS 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?