Lab 2: Building an A/D Converter Circuit with AVR mcu, Study notes of Computer Science

A lab exercise where students build an analog-to-digital (a/d) converter circuit using an avr microcontroller (mcu) and a potentiometer. The goal is to read the digital value of the voltage input from the potentiometer and display the raw value and percentage. Background information on potentiometers, the stk500 development board, and the a/d converter. Students are required to read pre-lab materials, construct the circuit, write a c-routine, and test the circuit. The document also includes pre-lab questions and a parts list.

Typology: Study notes

2012/2013

Uploaded on 03/22/2013

dhritiman
dhritiman 🇮🇳

4.7

(6)

106 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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:
( )
ratioratio 10
log10dB =
. 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
Docsity.com
pf3
pf4

Partial preview of the text

Download Lab 2: Building an A/D Converter Circuit with AVR mcu and more Study notes Computer Science in PDF only on Docsity!

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: ratio dB = 10 log 10 ( ratio ). 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/A 0 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.
  3. Connect Circuit 2 to Port A/A 0 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.
  4. 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.

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?