## Digital Voltmeter

Introduction.

You will build a digital voltmeter with user-selectable functions for measuring voltage and resistance.

Procedure:

NOTE: The STK-200 board has different pinouts on the header connectors. Pin 10 on the i/o connectors is Vcc, not ground as it was on the green boards.

The DVM project requires that you use the STK-200 board. Note that the cpu is an AT90S8535. The main differences from the 4414 are

• TIMSK bits are redefined.
• Twice as much FLASH, RAM and EEROM
• 8 channels of 10-bit analog to digital conversion
• a third clock

You will need to figure out a way to measure resistance. There are several possibilities:

• Construct a constant current source and measure the resulting voltage across the unknown resistor.
• Make a voltage divider with one resistor being the unknown and measure the resulting voltage across the unknown resistor, then do some arithmetic.
• Use a 555 timer or 74121 one-shot to generate a pulse (with duration proportional to a resistance) and measure the pulse-length.

A short code shows how to read the analog-to-digital converter using the timer 1 matchA function to pick a rate. Be sure to adjust the ARef pot on the STK-200 board so that ARef=4.096 volts. Setting ARef to 4.096 volts means that each count of the 10-bit ADC is equal to 4 millivolts, so conversion to voltage is easy. Pin 10 of the analog port is ARef. Do NOT connect anything (except the DVM) to ARef. It has very limited current drive capability. ARef also appears to drift as much as 0.4 volts after the board is turned on. Check it a few times.

The diagram below shows the test circuit for this code. If you set the trimpot so that the input voltage to the analog port is greater than ARef (but less than or equal to Vcc), you will read back all ones from the analog to digital converter. If you somehow put a voltage greater than Vcc on the analog input, you will destroy it.

As in Lab 5, the Keyboard:
You will need to get user input from a keypad with the following configuration.

```Pin 1  -- row 1 2 3 A
Pin 2  -- row 4 5 6 B
Pin 3  -- row 7 8 9 C
Pin 4  -- row * 0 # D

Pin 5  -- col 1 4 7 *
Pin 6  -- col 2 5 8 0
Pin 7  -- col 3 6 9 #
Pin 8  -- col A B C D

(a) Each switch shorts one row to one column.
(b) Each pin should be connected to one
bit of an i/o port.
(c) The i/o port pins will be used both
as inputs and outputs. When they are inputs,
they should have the pullup resistors
activated.
```
As in lab 5, the Liquid Crystal Display (LCD):
A 16 character, one line (16x1), LCD display will be the output for your capacitance meter. The display we are using has an industry-standard interface. A data sheet for a similar display shows the connections. There are several aspects of the display you should note:
• Connecting the power incorrectly will destroy it instantly. Always check the polarity be connecting the display.
• The power supply should rise very quickly from 0 to 5 volts. Since the display only draws about 1-2 mA, use a port pin for power. You will need a 10k or 20k trimpot to adjust display contrast.
• The LCD setup code is long but using it is straightforward. You can also use the code to test your LCD connections. The code assumes a 4-bit interface. Lines 7,8,9 and 10 on the display are not used and should be left unconnected. The code shows how to initialize the LCD, issue commands, and write characters.
```LCDpin 	Connection
------  ----------
1	gnd - Port A
2	+5 volts - PortA7
3 	trimpot wiper
4	PortD6
5	PortD5
6	PortD4
7-10	no connection
11	PortD0
12	PortD1
13	PortD2
14	PortD3
```
• The character representation is identical to ASCII codes for numbers, letters and most symbols. Refer to the data sheet above for a complete listing.

Assignment

Write a program and construct a circuit which will

• Measure a voltage at the input to the DVM of zero to 4.096 volts with an accuracy of 10 millivolts.
• Measure a resistance of zero to one Kohm with an accuracy of five percent.
• Scan the keyboard for one of two commands (which could be single keystrokes):
• Measure Voltage
• Measure resistance
• Format the resistance or voltage as an ASCII number and display appropriate messages on the LCD.
• For extra credit add a capacitance measuring circuit to your DVM. See the spring 1999 lab 4.

You will demo the DVM to your TA.

Your written lab report should include:

• A schematic of the circuit you built.
• A summary of the accuracy of your measurements (for the DVM).
• A heavily commented listing of your code.