Iowa State University

CPRE 288 Laboratory

Lab 8: Servo Position Control with PWM

Lecture - Lab Connection

In lecture, you have studing output compare and pulse width modulation (PWM).  This lab will explore the use of PWM to control the position of a servo attached to the cyBOT platform.


  • Read through this lab description. Think about the functionality.
  • Skim documents to understand the operation of the servo motor, including the servo datasheet and other resources as needed given in the Reference Documents listed below.
  • Review the readings assigned in preparation for Lab 8, including textbook, section 9.2(,,, and theTiva TM4C123GH6PM datasheet related to the timer and PWM mode. Don’t read everything, look for basic concepts and overviews first,ignore things that seem outside the scope of the lab,browse steps given for initialization, configuration, etc. Figures 9.5 and 9.15 in the textbook may be helpful.
  • Keep in mind the following:
    • You are using the “PWM Mode”of the timer(General-Purpose Timer Module, GPTM)–textbook sections, You are not using the “PWM Generator Block,”which is an entirely separate module of the microcontroller. A timer can be configured to generate PWM output signals in PWM mode.
    • You are not using interrupts for PWM in this lab. Lab 8 does not involve any interupts.
  • Draft the code. It might help to sketch your system. It might help to create an outlineand/or flow chart of the code. The code should be complete, but you don't have to compile or execute it before coming to the lab. Attempt to draft some code to show your TA.
  • Print the Lab Evaluation Form, so that your TA can check off work performed during this lab session.
  • Answer the prelab questions below to receive prelab credit on the lab evaluation form. Bring your answers with you to lab.

Prelab Questions (5 points)

Answer the following questions in preparation for the lab(refer to the Tiva TM4C123GH6PM datasheet , textbook, and/or other resources as needed):
  1. How does the servo motor work? For example, what are the pulse widths necessary for full clockwise, center, and full counter-clockwise positions? (1pt)
  2. What Timer1 registers are relevant to this lab? (2pts)
  3. With a Timer running at the 16 MHz system clock, how many timer ticks are there in 20ms duration? (1pt)
  4. Describe timer programming for the PWM signal in terms of the high pulse and the low pulse. When is the output pin set? When is the output pin cleared? (1pt)

Reference Documents

  • Tiva TM4C123GH6PM datasheet
  • Parallax Standard Servo datasheet, (900-00005-Standard-Servo-Product-Documentation-v2.2.pdf)
  • Standard Servo tutorial, Parallax,, Standard Servo-application-note.pdf

Reference Files

Download the following files to a single folder on your U: drive (right-click and select 'Save Target As'. Alternatively, download the zipped folder at the bottom of the page).

  • timer.c/timer.h: The file that contains the utility functions for the cyBOT platform.
  • lcd.c/lcd.h: The program file with a number of LCD functions.

Lab 8 Description

  • Lab 8 Manual: A detailed description of the objectives to complete for Lab 8


Turn the power to the Cerebot board and iRobot off before charging. The Cerebot board consumes power and the battery will not charge if the robot is in full_mode (which it enters after calling oi_init, turing the power LED yellow). The robot is charging when the robot's power LED is pulsing red and both green LEDS on the dock are lit.

Reference Files

Files Description
Tiva TM4C123GH6P datasheet.pdf Information about the TM4C123GH6P
Lab Evaluation Form Evaluation form for Lab