Iowa State University

CPRE 288 Laboratory


Lab 9: Distance Determination Using Ultrasonic Sensor

Lecture - Lab Connection

In lecture, you have studied interrupts and Input Capture.  This lab will explore the use of Input Capture to measure an input pulse width that is directly proportional to the distance measured by an ultrasonic sensor, PING ))), attached to the CyBot platform.

Prelab

  • Read through this lab description. Think about the functionality.
  • Skim the datasheet for the Ping))) sensor to grasp how it operates
  • Review the readings assigned in preparation for Lab, including:
    • Textbook, Chapter 9, Sections 9.1 and 9.2 (in concert with the Tiva datasheet as needed); don’t read everything, look for basic concepts and overviews first, browse sample code that uses DRA (Direct Register Access) interface and system header file and steps that describe how it works, etc.
    • Tiva TM4C123GH6PM Datasheet related to the timer and input edge-time mode (input capture); 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.
    • Don’t forget about the PING))) interface introduction slides that give hints about register use
  • Draft the code. It might help to sketch your system. It might help to create an outline and/or flowchart 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.
  • Answer the prelab questions below to receive prelab credit on the lab evaluation form. Bring your answers with you to lab.

Prelab Questions: Answer the following questions in preparation for the lab (refer to the Tiva datasheet, textbook, and/or other resources as needed):

  1. What Timer3 registers are relevant to this lab? [2 points]
  2. Given the difference in timer counts (int delta) between the edges of a SONAR pulse (from sending a sound to receiving it back), what would you multiply delta by in order to get a distance measurement in units of cm? (Hint: The speed of sound is 34,000 cm/sec) [1 points]
  3. What is the difference between the GPTM Raw Interrupt Status Register (GPTMRIS) and the GPTM Masked Interrupt Status Register (GPTMMIS)? Which of these registers is checked by an interrupt handler to determine the source of the interrupt trigger, if multiple interrupt sources are possible? [2 points]

Reference Documents

Reference documents in addition to the Textbook: The latter three are useful tutorials on oscilloscopes for Part 2 of the lab. The last two are more general documents that cover useful concepts and techniques associated with oscilloscopes.

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 timer functions for the CyBot platform.
  • lcd.c/lcd.h: The program file with a number of LCD functions.

Lab 9 Description

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

Cautions

Turn the power to the CyBot platform off before charging. The Launchpad board consumes power and the battery will not charge if the robot is in full_mode (which it enters after calling oi_init, turning the power LED yellow). You will have to turn off open interface. 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