AME 3623: Project 3: Analog Processing and Interrupts

Many embedded systems must face the problem of how to process sensory data that is encoded using a continuous voltage. In addition, sensory processing can include the production of control signals that are coordinated in time with the sensor "reading."

In this project, we will sense the orientation of a "weather vane" so that we can drive the robot toward a wind source. We will use a sensor called an encoder to infer the current orientation of the vane. Unlike many encoders, its state is presented as an analog signal (most encoders use a pair of digital signals).

The learning goals for this project include:

Project Due Date

Robot Task

In the full task, the robot will orient toward and then drive into "the wind" (provided by a fan). When a beacon is observed to the left, the robot should stop.

Design Process

Part 1: Encoder Processing

Due: Thursday, April 11th at 5:00pm. Note that this is a soft deadline (in order to complete the project on time, you should have this done by this date, but there are not penalties for missing the deadline)

The Encoder

Your encoder has two signal lines. Connect one line to ground and one to an analog input pin (PC0 ... PC5). Note that you may need to re-assign one of your digital pins from project 2. For these sensors, it does not matter which line is connected to ground (pretty cool). Make sure that you include a pull-up resistor of 10Kohms on your analog input pin.

Before reading the sensor state, it is necessary to charge up a capacitor contained within the encoder (this will provide power to the encoder for a brief amount of time while we are reading its state). To take this first step, you must configure the pin as a digital output pin and bring it to +5V. After a delay of at least 3ms, the capacitor is charged. Re-configure the pin so that it is an input pin and set its state to 0V (both steps are necessary). After a delay of 4us, you are free to read the analog value (note that you will need an ADC prescalar of 32 in order to get the timing right).

The sensor will produce analog values of approximately 2.6V, 1.7V, 3.9V, and 4.5V (we will refer to these as integer values 0, 1, 2, and 3, respectively). When the shaft is turned in one direction, you will observe this sequence of voltages; when the shaft is turned in the other direction, the voltages will pass through the opposite sequence. For each complete turn of the shaft, the encoder will pass through this sequence of 4 steps 4 different times (so we have a resolution of 22.5 degrees per step).

Since we will be using this as an orientation sensor (for which it is important to distinguish the 16 possible orientations), it is necessary to keep a count of how many times you move through the sequence of 4 voltages. In particular, you will need to increment a counter every time the sensor passes from 4.5V to 2.6V, and decrement the counter every time it passes from 2.6V to 4.5V.

Important notes to keep in mind as you are designing your FSM:

For more details about the sensors see (these are good sources of information, but note that they are incorrect in their report of the sequence of voltages):

Coding Steps

This part requires the following:

Part 2: Interrupts and Control

Due: April 18th at 5:00

You must complete the following steps:

  1. Embed your FSM step function into an interrupt routine (function) and configure the timer so that it is called every ~4ms.

  2. Write a main program that first orients the robot toward the wind source and then drives to it. The robot should stop when it observes a beacon to its left.

  3. Demonstrate your working program


What to Hand In

Project Report

Your report should include the following: The reports are due at 5:00 on April 13th. Please turn these in using the D2L dropbox (one copy per group) in either postscript or pdf format.

Personal Reports

Your personal report must include the following information: The personal reports are due at 5:00 on April 13th. These must be turned in via D2L in raw text format.

fagg at

Last modified: Sat Apr 8 18:39:21 2006