Iowa State University

CPRE 288 Laboratory

Lab 6: I/R Distance Measurement via A/D Conversion

Lecture - Lab Connection

In lecture, you have studied the use of analog to digital conversion. In this lab, you will use those hardware features to build a simple range finder.  This lab will have you explore configuration settings of the Tiva TM4C123GH6PM A/D conversion functionality.


  • Read through this lab description. Think about the functionality. The ADC is a complex subsystem, although this lab uses a relatively small subset of functionality.
  • Review the readings assigned in preparation for Lab 6, including:
    • Textbook, Chapter 7, Section 7.5 (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 section related to the ADC; don’t read everything, look for basic concepts and overviews first, ignore things that seem outside the scope of the lab (even if you realize you later need it, for now, ignore it, such as digital comparators, differential mode); browse steps given for initialization, sample sequencer configuration, etc.
    • Review the lecture slides that discuss the ADC registers.
    • Another resource that gives a nice overview and details of the ADC is Valvano and Yerraballi, Chapter 14: Analog to Digital Conversion, Embedded Systems: Introduction to ARM Cortex-M Microcontrollers, 2014 ( Chapter 14 )
  • Review the data sheet for the I/R distance sensor to grasp how it operates.
  • Draft the code. It might help to sketch your system. 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 following questions in preparation for the lab (refer to the ADC in the Tiva datasheet, textbook, and/or other resources as needed):

  1. Which A/D registers should be configured for this lab? [2 points]
  2. How will you do sample averaging? [1 points]
  3. How many ADC clock cycles are necessary for the first conversion (hint: see successive approximation conversion technique)? [2 point]
  4. Suppose your program uses polling to wait for the ADC to complete the conversion. The ADCRIS register bits may be polled by software (your program) to look for conversion-complete conditions without generating an interrupt (i.e., no interrupt is sent to the NVIC interrupt controller). Recall textbook Figure 5.8 and the local device RIS and IM registers (the figure depicts a GPIO port but is applicable to other I/O modules). Instead of polling, suppose you want an interrupt to be sent to the NVIC for further processing. How is an ADC interrupt locally enabled? [1 point – extra credit]


Reference Files

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

  • 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 6 Description

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


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
Documentation on printf Documentation for the lprintf and printf function.
Lab Evaluation Form Evaluation form for Lab