Checkoff requirements

  • Demonstrate function of line sensing circuitry and ADC

  • Detect whether on left or right side of track

  • While sensors are moved from left to right, the steering servo steers in the correct direction of the track

Note Clarification: The sensing circuitry may be built on a breadboard. There will be no drop test for this week.

Line Sensing Notes

The links on the Resources page will be helpful. Of note are two links reproduced below:

Analog to Digital Conversion

The ADuC7020 — and most modern microcontrollers — have built-in ADCs or Analog-to-Digital Converters. These read a voltage (an analog value) and convert it into an integer (a digital value) which can be used by software.

Here is some example code which uses the ADC to read the ADC0 input.

int leftSense;

ADCCP = 0x00; // Select ADC0 as an input
REFCON = 0x01; // Connect internal 2.5 V reference
ADCCON = 0xE4; // Continuous conversion               1

while (!ADCSTA) {}; // Wait for the end of conversion 2
leftSense = (ADCDAT>>16); // Get ADC value            3
printf("ADC0 value is %d\n", leftSense);
Note ADC documentation can be found in page 25 of the datasheet.

Reading the datasheet we can see that the ADC value is a 12-bit integer. This means that in single-ended operation the range of values is 0-4095. The reference voltage is 2.5 V, meaning that the max value 4095 corresponds to a voltage >= 2.5 V.

In the line marked <1>, we set the ADC to operate in single-ended mode and do continuous conversion. That means the ADC is actually continuously operating in the background. At <2> we wait for the first conversion to finish then read the value from ADCDAT in <3>.