ECE4330 – Embedded Systems Design Lab 2 – A/D Converter

Lab 2 - A/D Converter

This circuit connects a variable voltage to an A/D port on the AVR mcu. Your software running on the AVR mcu will read the digital value and display the percent and raw value of the voltage, VA.

The interface consists of some analog circuitry as well as wiring the analog circuit to the STK500 and running corresponding software on the AVR mcu. Each circuit requires a unique C-routine.

Circuit 2 Input to an A/D Converter via the STK500 (ATmeg16 and AT90S8535 have the same pin layout)

Voltage is measured at the output of the Potentiometer Va. VTG and GND can be obtained from numerous places on the STK 500 board.

Background

A potentiometer can set a variable that is processed and used by the microprocessor. Typical applications include having the potentiometer represent a volume or level of ambient light, although a potentiometer can set just about any reference signal.

There are two basic styles of potentiometers: audio and linear. Audio potentiometers vary logarithmically as the sense of hearing is logarithmic. Recall, the definition of decibels is: . This lab uses a linear single turn potentiometer.

The potentiometer in Circuit 2 is part of an external circuit that provides an input signal to the STK500. The STK500 development board can house most of the ATMEL RISC processors. There are several sockets on the STK500 for different members of the AVR family of processors, depending on the particular pin-out of the microcontroller. The ATmega16 has an eight channel A/D converter and it resides in socket 3100A5 on the STK 500.

The STK500 provides several variable voltage sources, such as VTG and Aref. Developers can use AVR Studio to set these voltage values without having to wire external circuitry. The STK500 also allows external voltage references. VTG stands for VTARGET and can be used to power “target” circuits. VTG delivers up to 0.5A. Notice that all of the I/O port sockets have VTG and GND pins.

A program running on the microcontroller uses the A/D converter to sample and derive a digital value from the A/D port. The signal Aref (analog reference) sets the maximum value of the input voltage to the A/D converter. Without Aref the A/D converter would not “know” how to scale the A/D port’s voltage, VA. Aref is an adjustable voltage reference provided by the STK500 board, although external circuitry can set or define Aref. Regardless of whether Aref is set on-board or through external circuitry its voltage must be less than or equal to VTG.

Pre-Lab Assignments

  1. Read the ATmega16 data book, pages 202 through 220.
  2. Read B,C, and O (course text), section 2.9.
  3. Read the AVR STK500 User Guide, page 3-11 and pages 3-16 through 3-18.
  4. Answer Pre-Lab Questions

In-Lab Tasks

  1. Verify that the ATMEL processor being used for its A/D peripheral is in the correct socket on the STK500. See page 3-11 of the AVR STK500 User Guide.
  2. Construct Circuit 2 as diagrammed onto a prototype or breadboard. However, initially DO NOT connect VA of Circuit 2 to Port A/A0 on the STK500. Use VTG and GND pins from the STK500 to drive your circuit.

a)Use Lab equipment to verify that the potentiometer is functioning correctly.

b)Verify the values of VA. That is, make sure VA does not exceed the specifications for the A/D port of the mega16.

  1. Connect Circuit 2 to Port A/A0 on the STK500. Connect the spare RS-232 cable. Use the two-wire cables with a connector at one end to link the STK500 to your breadboard.
  2. Write a C-routine to read an A/D port and display its value on the simulated terminal. Display the value as a percent and as the raw digital value read from the A/D port. You will need to make a design decision as to how often and under what conditions your program displays the A/D values.

Use CodeVision’s code generator to specify the use of an A/D port converter. Since you are going to use the spare RS-232 port for terminal I/O be sure to generate your code with UART support.

The code generator is a nice tool. However, you must specify or include the peripherals used by your program prior to adding your own code. Adding a new peripheral after your code updates are in place becomes a version control headache. Hint. If you forget to generate code for a device and have already added your own code to a routine, then auto-generate a test project/program for the just the device you forgot and copy the generated code for the new device into your already updated routine.

Hint. The 10-bit ADC can return values that vary by around 3 even for an A/D port that is not changing voltage. To understand why this is possible divide 5V by 210–1 (0x3ff) to compute the V associated with a change by 1 in the ADC’s reading of a port voltage that can range from 0V to 5V. Your code should include averaging logic, truncating logic or variance outside of a range “detection” logic. Construct a data table that relates: analog voltage; digital value; percent of turn on potentiometer.

Record the above items in your data table for several (5 or 6) physical settings of the potentiometer; use the Oscilloscope to measure VA; and record the reported value per software that is displayed at the terminal.

  1. Test the boundary conditions of Circuit 3-1. That is, make sure that the display is correct both when the potentiometer is turned completely off and completely on.
  2. Graph the results from your data table, use linear regression to produce a best-fit line through the data points. It’s OK to use software to do the linear regression analysis. Perform this task offline, away from the lab.

Parts List

  1. A single turn, linear potentiometer.
  2. RS-232 Cable
  3. 2-wire cables with a connector at both ends (3)

Deliverables

Demonstrate to the lab instructor how the output display varies as the potentiometer varies. Write-up an explanation of how you characterized the device, be sure to include your analysis of the values found and graph of your data as the potentiometer was varied.

software requirements as shown in the class note Lecture2-Lab2

Pre-Lab Questions

Name: ______

After completing the other pre-lab tasks answer these questions. Be sure to include your work and show units, as appropriate, on your answers. 2 points each, 10 points possible.

  1. What is the range of an n-bit D/A converter?
  2. Our ATmega16 has an 10-bit D/A converter. What is the resolution if the full-scale input range is 5V?
  3. Briefly describe the two operating modes of the ADC in the mega16.
  4. What are the ADC noise canceling techniques?
  5. What two registers are used by the ADC and what are their purposes?

2-1