Logical Input

Purpose

To track the motion of a shaft and use it to control an analog signal:

Due dates

You must hand in your answers to the design questions at the beginning of your laboratory session on Thursday, November 20. This part of the assignment is worth 10 points.

You must be prepared to discuss your work at the beginning of your laboratory session on Tuesday, December 2, and to demonstrate your program to your TA during that period. This part of the assignment is worth 25 points.

Background

In previous assignments, a D/A converter was used to play samples of a waveform. These samples were either provided as an array of values, or taken from periodically sampling an A/D converter. In either case, the waveform was played back through a set of headphones.

The volume of the signal, heard through the headphones was determined by the input values. That is, the waveform was not changed before being sent to the D/A converter. If the waveform samples are scaled in some way, made larger or smaller, the output volume will change.

To increase the volume of the signal, we must multiply the value of each sample by a number greater than 1; to decrease the volume, we must multiply the value of each sample by a number less than 1. Remember, however, that there are limits on the accuracy of the samples. An attempt to change the volume of the signal by a really large amount in either direction would simply result in random noise. Thus we want to multiply each sample by a value relatively close to 1, requiring that we deal with operands that are not integers.

We are used to using a rotating knob to control volume, and thus we would like to have the computer sense the motion of a shaft and use that motion to set the value of the multiplier. A shaft encoder is the appropriate device for this purpose.

Fixed-point multiplication

The term fixed-point multiplication is used to describe a situation in which the radix point is at a specific location in each operand. (A radix point for decimal numbers is called a ``decimal point'', and a radix point for binary numbers is called a ``binary point''.) For example, integer multiplication is actually fixed-point multiplication with the radix point at the right end of each operand.

The position of the radix point in the result of a fixed-point multiplication is determined by the assumed positions of the radix point in the two operands. If both operands are assumed to have their radix points at the right end, then the result will have its radix point at the right end. If both operands have their radix points at the left end, then the result will have its radix point at the left end. Suppose that one operand has m digits following its radix point, and the other operand has n digits following its radix point. The result will then have m+n digits following its radix point:

   400		   .400		   4.00		   .300		   3.00
 * 500		 * .500		 * 50.0		 * .200		 * 20.0
   ---		   ----		   ----		   ----		   ----
200000		.200000		200.000		.060000		060.000

The MC68000 signed multiply instruction multiplies two 16-bit, 2's complement values to get a 32-bit, 2's complement result. We can make any assumptions that we wish about the position of the binary point in each of the operands, and then deduce the position of the binary point in the result. Suppose that we assume the binary point to be at the right end of the multiplicand, and assume that the multiplier is a positive number that has eight bits to the right of the binary point:

			        xxxxxxxxxxxxxxxx.
			      * 0yyyyyyy.yyyyyyyy
			        -----------------
		zzzzzzzzzzzzzzzzzzzzzzzz.ffffffff
Now if the multiplicand is the value of a sample, expressed as a 16-bit, 2's complement value, and the multiplier is a value controlled by a shaft encoder, then the result is the ``volume controlled'' value of the sample. Because the sample is defined to be an integer, we discard the bits of the result labeled f.

Each sample is an 8-bit value in the range 0-255. Since a sample value of 128 represents 0, we convert the sample value to a 16-bit, 2's complement value by first making it a 16-bit value in the range 0-255 and then subtracting 128. After multiplying and discarding the fractional part of the result, the value must be converted back to a sample by adding 128. If the result is greater than 255 it must be set to 255; if it is less than 0 it must be set to 0.

Shaft encoding

On the MB5, bit 1 (Figure 2.4, page 30 of the text) of the byte read from location $700001 is the A bit from the shaft encoder, bit 0 is the B bit. By comparing two successive values of AB, you can determine whether the shaft is being turned and the direction. (Click here for details.)

Task

Add a volume control to your sound storage and playback program. (If you wish, you can use another group's sound storage and playback program as the basis for this assignment.)

The shaft on the MB5 must control the volume of your headphone output. You must be able to both increase and decrease the volume. It must not be possible for the multiplier to become negative.

If a user types the character 1 on the HP keyboard, the volume control's multiplier must be set to 1. Pressing this key should not change the state of the sound storage and playback program. (This requirement conflicts with the original specification.)

Questions

  1. (5 points) Suppose that you constructed a 4-bit number, with the two most significant bits being the two least significant bits of byte $700001 from the last time that byte was read and the two least significant bits being the two least significant bits of byte $700001 from the current read. With each of the 16 possible values of this number, associate a value in the range 0-2. The value 0 indicates that either the shaft has not been moved or the direction of movement is unknown, the value 1 indicates that the shaft has turned clockwise, and the value 2 indicates that the shaft has turned counter-clockwise.

  2. (5 points) Can you guarantee that your answers to (1) are always correct? Explain briefly.

Demonstration

You must demonstrate your program to your TA on one of the machines in the Microlab.
Instructor Revision 1.9 (2007/08/27 00:15:44)