Starting from:
$30

$24

Laboratory Exercise #07 Pulse Width Modulator and Servos Solution

1 Introduction




In this lab you will write a task to configure a Pulse With Modulator (PWM) and use the PWM signal to drive a small servo.




2 Rationale




Servos are used in many applications as an actuator, for example ailerons, elevator, and rudder on airplanes. PWM signals can also be used to control the speed of a motor such as found on quad-copters.




2.1 Program Modifications




Make as copy of the ADC project from Lab #05. You will add a task as described below. You should remove the ADC task that reads the potentiometer voltage.




2.2 PWM Background




The operation of the Pulse Width Modulator was described in class. The steps to program the PWM are outlined below. Additional information on the PWM hardware and DriverLib software are at:




http://www.ittc.ku.edu/~gminden/Embedded_Systems/PDFs/TI_Stellaris_LM3S1968 _EvalBoard.pdf,




http://www.ittc.ku.edu/~gminden/Embedded_Systems/PDFs/TI_Stellaris_LM3S1968. pdf, and




http://www.ittc.ku.edu/~gminden/Embedded_Systems/PDFs/TI_Stellaris_DriverLib.p df.




You should read those documents. In particular read the example PWM code in the DriverLib document.




Watch out for line-breaks in the URLs.




2.3 Connector Pin-outs and Servo Connections




With the LM3S1968 evaluation board receptacle facing you, we use twenty pins on the left-hand side to connect to off-board circuits. These pins are described in EECS 388 Laboratory #05 write-up. You should use PD<1/PWM<1 to drive the servo.




The servo has three wires: (a) the black wire is ground, (b) the red wire should be connected to the +5 VDC terminal on the LM3S1968 evaluation board, and (c) the white wire should be connected to PD<1/PWM<1. You should refer to the




EECS 388 Laboratory #7
1
 
Version B







Sensor Orientation presentation to determine the expansion board pin for PD<1/PWM<1.




3 New Tasks




Write a new FreeRTOS task to generate the PWM signal and control the servo. The PWM signal shall have a period of 20 mS. The pulse width shall vary between 1.0 mS and 2.0 mS with a period of 1.0 S.




The task will do the following steps (states):




Initialize the required peripherals.



Alternate between 1.0 mS and 2.0 mS pulse width with a period of 1.0 S.



3.1 Initialization Step




Initialized the required peripherals, e.g. PortD<1, PWM0 generator, PWM<1, signal and configure PortD<1 to be an output that uses the PWM<1 as the alternative output.




Configure PWM0 for a period of 20 mS.




Determine the values to generate either a 1.0 mS pulse or 2.0 mS pulse. Use 1.0 mS as the initial pulse width.




3.2 Alternate Servo Positions




The <while-loop of your task should alternate between generating a pulse of 1.0 mS and 2.0 mS
























































































EECS 388 Laboratory #7
2
 
Version B



More products