Useful links


EXPERIMENT #8 PRELAB


So far in lab and in lecture we have considered components that are either analog components (resistors, diodes, transistors...) or digital components (logic gates). An admittedly cursory attempt to connect two was tried in lab 5 when you experimented with using transistors to implement digital logic. The digital world is built on a convenient abstraction which we apply to the behavior of our chips that hold the logic gates. If we are using a chip which performs a logical inversion function we expect that it behaves exactly like our abstract inverter. But the chips we use are actually analog circuits - and some designs exist that actually use the chips not for their digital function but for their analog components.

We can now think of our TTL devices using our abstract 2-state logic concepts (except of course when something goes wrong and the analogness of the chips that hold the hardware logic gates become apparent). But, for many applications, the digital circuitry (in our case the circuit that navigates the car along the track) needs information from the non-digital or analog world - in our case, the output of the IR sensors that will be the "eyes" for your vehicle. In this digital age, interfaces between the analog world of music, monitors, sensors, humans typing, etc... to the digital world of a binary stream of numbers are very common. The hardware used as the Analog-to-digital interface is called (surprisingly enough) the Analog-to-Digital (or A/D) converter. An analog voltage is applied to the A/D converter module and out comes a stream of numbers that describe the analog signal.

As an example, suppose we want to convert music to a stream of digital numbers that can be stored in an MP3 file and replayed. In the analog world - the instruments, or voice, or speaker that is making the music/noise moves the molecules of the air to create the sounds that in turn cause small bones inside our ear to vibrate causing the sensation of music. It is this air motion that we want to convert into a stream of binary numbers. The A/D converter takes as an input an analog voltage - not the vibrations of the air molecules - so somehow we need to first convert the motion of the molecules to an electrical voltage - and we have such a device - the microphone. The microphone is a TRANSDUCER (a device that converts one type of energy into another) in the case of sound the microphone changes the vibrational motion of the air to an electrical signal. Once the sound of the music has been converted into a voltage the A/D converter takes over.

Pasted Graphic 7

The A/D converter has the ability to take the analog signal and compare it to a set of other signals of preset voltages levels. By combining the results of the comparisons, it can associate different voltages with a digital number. The simplest type of A/D converter is called a 'flash' A/D converter. So named because it converts the voltage to a binary number very quickly compared to other designs by comparing the analog signal to many thresholds simultaneously. Below is a block diagram of a simple A/D converter that takes in a analog input v(t) and compares it to a preset threshold output either a 0(low voltage) or a 1(high voltage).

Pasted Graphic 8

This one bit A/D simply looks at the input voltage V(t) and decides whether or not the voltage exceeds some prespecified threshold. If it does then the output of the A/D converter will be a 1 (high voltage) otherwise the output is a 0 (low voltage). The analog voltage is now a string of bits encoded as a voltage. If this A/D converter were used to encode music, the music would not sound very pleasing. Most sound cards in a typical PC encode the sound using 24-bits.

When the music is to be replayed, or the digital image is to become a picture, we can reverse the process using a D/A converter that transform the stream of binary numbers back into an electrical voltage that drives a different transducer that works the other way, taking a digital string and converting it into analog signals. Your sound card does this for the speakers and the video card for the monitor.

During this lab we will implement a simple A/D converter that compares the voltage received from the IR sensors (which are the transducers - changing the EM radiation to a voltage) to several different thresholds and changes it to binary signals that you can use in your design. So let’s see how we would go about converting an analog signal to a series of numbers. A convenient place to begin is to look at a triangle wave to see how we would encode this simple signal into a list of numbers. This will show us the many things that need to be considered in the conversion process.

Consider a triangle wave with a peak-to-peak amplitude of 10V and a DC offset of 5V. We all know what this looks like.

Pasted Graphic 4

Suppose we want to represent this as a series of number, assuming for the moment that we can know the voltage at any point in time with perfect accuracy. There are infinitely many ways to do this. The most important decision in this process is how often to sample the function, recording the value of the voltage at uniform (occasionally non-uniform) time intervals. The figure below shows three possible sampling interval choices. The top one has decent resolution, good enough so that by looking at a list of numbers representing this function you would guess that it is periodic and you would be able guess which are the rising edges and which are the falling edges. It would be difficult to interpret a list of numbers generated by recording the voltage at each time indicated by a blue circle on the center graph. How about the bottom plot?

Pasted Graphic 5

  1. Make a table that holds the value of a triangle wave with 10V peak-to-peak amplitude and a DC offset of 5V for a sampling interval of 8 per period [t=0, .125T, .25 T, .375T, .5T, .625T, .75T, .875T], 2 per period [t=0, .5T], and 1 per period [t=0]. T is the period.
  2. For the second and third sampling period - 2 and 1 time per period, what other functions would match the same list of numbers. One that I can think of for the list generated by sampling twice per period is a square wave. Think of others.

    As you can see, the rate at which you sample is an issue even if you could sample perfectly, obtaining an exact value for the voltage at each point. But as you might guess you cannot even determine the value of the voltage exactly. All A/D converters that I am aware of compare the voltage of the time varying signals to reference voltages and determine whether the signal voltage is larger or smaller than this reference. So at best the voltage is estimated to within a predetermined range. If many, many reference voltages are chosen then the digitized estimate of the voltage can be quite close to the correct value. In the figure below are two plots showing the triangular wave and reference voltages. On the left is the simplest scheme, a single voltage threshold is provided so the incoming signal's voltage is either greater than or less than this threshold. A single bit would suffice to convey this information. For example, sample sequence of the exact voltages might be - [0, 5,10,5,0,5,10,5,0...] if the function were sampled 4 times per period. With only one reference voltage of 5V, the digital representation of the same function might be [0,0,1,0,0,0,1,0...] assuming that the comparator evaluates voltages greater than the preset threshold as a 1 at the output and voltages below the preset threshold as a 0. A slightly more accurate series can be obtained using 3 thresholds which divides the 10V range into 4 possible bins. These bins can be mapped onto the digital numbers V<2.5V => 00, 2.5V =>  01, 5V => 10, V>7.5V => 11 or any other combination. For example, using these three thresholds the following digital representation for the function triangle function is obtained - [00, 01, 11, 01, 00, 01, 11, 01...]. What mapping was assumed?

Pasted Graphic 6Pasted Graphic 7

 

  1. Assume that a 4-bit A/D conversion scheme is desired. How many thresholds are needed? Specify one possible set of thresholds that would divide the interval from 0-10V into the 16 intervals that can be mapped onto a 4-bit binary numbers.
  2. Map one of the four-bit binary numbers (0000-1111) onto each interval. The least creative mapping is always the simplest, but your mapping can be your own, simply keep track of it so that you can actually do the mapping in the next question.
  3. Generate the list of numbers you would get if the triangular wave were sampled 8 times per period and the real voltage were mapped onto the binary numbers from 0000-1111 using the mapping scheme you specified in the previous part.

    During the lab you, are going to build a logic circuit that outputs a high voltage whenever an arrangement of sensors 'sees' a particular pattern. This is the circuit that will detect the presence of a split in the path. The path will always look like this with (left) and without (center) colored tape at the fork -

Pasted Graphic 1Pasted Graphic 3Pasted Graphic 2

except that it will be white on black. You will dedicate one sensor bar - for this lab, you may change this design on your own - to detecting the split as shown in the figure to the right. The sensor bar has four sensors on it. The figure shows how the sensor bar is situated over the split (as seen from above assuming that it is attached to the front of the vehicle which is not shown) and what the sensors are 'seeing' when a unique 'split' pattern is perceived. The two outermost sensors see white and the innermost see black. The sensors should only see this pattern at a split.

  1. Design a logic circuit that accepts as input the output of the four sensors - label them as you wish - and outputs a high signal (a 1) IF AND ONLY IF the sensors see the split pattern.



To navigate the split the circuitry that you will build must perform a simple A/D function to determine the presence or absence of colored tape at the split AND it must detect the split. The A/D part is performed using a simple voltage comparator - two actually because you need to discriminate between 3 intervals - the higher voltages will indicate the presence of WHITE tape and the lower voltage interval the presence of BLACK table which would be enough if you were just interested in navigating the vehicle along the track. But you also need to be able to detect the presence of another color which causes the sensors to output an intermediate voltage. You will be essentially designing a 2-bit A/D converter. You will be setting two thresholds and using some external logic to determine whether or not what the sensor is seeing is the colored tape, or the white path tape, or the black table. As shown in the figure below right, the output of the sensor is put into one of the inputs of two different voltage comparators. The comparator compares this voltage to a preset threshold. One threshold - say Vref1 - is set to a value between that returned by the white tape and that returned by the colored tape. The other threshold - Vref2 - is set to a voltage between that returned by the red tape and that returned by the black table. The output of the voltage comparator (NOTE this type of comparator is DIFFERENT from the logical comparator which you will study in lecture and play with in the final lab) is a 1(high voltage) if the input voltage is GREATER than the reference and a 0 (low voltage) if the input voltage is LESS than the reference voltage.

lab9_setting_threshold_for_redPasted Graphic

  1. Given that the comparator behaves as described above, design logic that outputs a 1 IF AND ONLY IF the sensor sees the colored tape.

    After you have successfully built the comparator circuit and your split detecting circuit the outputs of these circuits need to be integrated so that signals which drive the motors at a split, signals that override, the normal navigation circuitry are provided. You should design this circuitry to turn right only when colored tape is present at the fork, otherwise turn left.
  2. Write down in words how this circuit should work. For example, we know when split is detected but no colored tape is present the vehicle should turn left. What happens when color is detected? Describe in detail what the motors should be doing during the split navigation.
  3. Now translate your description into a logic table. Entries are filled in for the signal that drives the left motor through the split. Fill in the entries that drive the right motor.
  4. Write the logic equations for both signals - L and R.
  5. Draw a circuit diagram of the logic equations.

lab9_split_table


EXPERIMENT #8


A/D conversion - seeing colors

The comparator module will be used as a simple A/D converter to distinguish between the different voltage levels obtained from the sensors when looking at white tape, black tape, as well as other colored tape. You will investigate the behavior of this module in this part of the lab. A photo of the module is shown with different devices labeled. The heart of this module - the LM339N chip - is a voltage comparator. It actually contains 4 voltage comparators. A schematic of one of the comparators is shown below. It compares the two voltages on the inputs (+ and – differential inputs) and it outputs a logical 1 (HIGH) if the voltage on the – input is larger than the one on the + input and a logical 0 (LOW) if the voltage on the - input is smaller than the one on the + input.

Pasted Graphic 3

Parts of the comparator module:

i) comparator chip LM339N - holds 4 comparator circuits identical to that shown below with different pinouts.

 

ii) potentiometers (variable resistors) - the blue devices with the small set screw which is used to change the resistance. They are connected to Vcc and the + terminal of each of the comparators on the LM339N chip. Notice there are 4 of them. You can set the voltage at the + terminal of each comparator individually when the jumpers are in the correct setting.

 

iii) jumpers - the black devices with the removable jumper. In one position, you can change the threshold of each of the + terminals of the comparators manually. In the other position, the module is connected so that the voltages at the + terminals are preset to behave like a real 3-bit A/D converter.

 

iv) test points - silver posts. These are connected to the variable resistor which is connected to the + terminal of the comparators so that you can monitor the voltage threshold as you work with the potentiometer. You can also monitor the corresponding pins of the 16-bit socket, which ever is easier for you.

 

Pasted Graphic

 

a) experiment with setting the reference voltage -

Lets see how the comparator works by inserting a known signal - a sine wave - into the POSITIVE terminal of one of the comparators. The NEGATIVE terminal of each comparator will be connected to a reference voltage against which the sensor voltage will be compared. Connect one of the comparators as shown in the circuit below. REMEMBER to connect power and ground. NOTE: pin 12 is GND and pin 3 is connected to Vcc=5V which is a non-standard way of connecting power and ground. One of the inputs of the voltage comparator is connected to a potentiometer (a special kind of variable resistor) – this is the blue thing on the module (it is often called a pot) providing a reference voltage Vref. The other input is connected to the function generator outputting a sine wave with peak-to-peak amplitude 5V and a DC offset of 2.5V. TP1 (test point 1) refers to the silver post on the module where you will monitor the reference voltage from the post to ground. (Alternatively you can measure the voltage at pin 6 which ever measurement point is easier for you). The voltage comparator compares the input voltage (in this case the input from the function generator) to the reference voltage set by the variable resistor. NOTE: all pin numbers assume you are using a certain comparator on the chip - you may use any one of the four available BUT you must make certain that the jumpers are all horizontal or the potentiometer will be ineffective. Check with your TA about the correct settings.

Pasted Graphic 2

 

    1. Record the initial reference voltage before you change anything.
    2. Now fiddle with the screw on top of the blue component. Explain what is happening to the reference voltage as you turn the screw.
    3. Look at the output of the function generator on channel 1 of the oscilloscope – this is input signal to be compared to the reference voltage.
    4. Look at the output of the comparator (pin 1 - for comparator 1) on channel 2. Draw the outputs on top of one another along with a line indicating the value of the reference voltage. Now change the reference voltage by changing the setting of the potentiometer. What happens to the output signal? Explain your results



b) detecting colors -

How will we use these devices in our designs? The path that your vehicle will be required to navigate is mostly a white piece of tape on a matte black table. The path consists of curves gentle and not so gentle. Occasionally, there will be a split in the path and - depending on the color of the tape making the split your vehicle must go right or left. So we need to distinguish other colors besides just black and white. As you can see this is a very simple case of A/D conversion. With only the black and white tape the A/D conversion is automatic because the low and high values from the IR sensors correspond the low and high values of TTL gates. Now we need to detect an additional state - that of the sensor seeing a color. For this, we will need two of the voltage comparators on our module. We use one to compare the output of the sensor to a reference voltage level between the nominal voltage levels of black and the other color (in this case red). We use the other to compare to a reference voltage level between the nominal voltage level of white and the other color.

lab9_setting_threshold_for_red

The circuit below will accomplish this using two of the comparators. Connect BOTH of the inputs to the two negative inputs on the two comparators to the voltage coming from the sensor on the sensor bar (see figure below). Now set the first reference voltage Vref1 to be 3.2V which is a value between red and white and the second reference voltage Vref4 to be 1.6V which is a value between red and black.

 

Pasted Graphic 1

 

  1. Put a red strip under the sensor when the vehicle is sitting on the table. Measure the voltage coming from the sensor. Adjust the sensor bar height so that a white strip reads >3.7V, a black strip reads <.7V, and the red should read ~2.6V.
  2. Record the voltages at the output of the comparator OUT1 and OUT2 and their equivalent logic states (0 or 1).
  3. Fill in the following table – you may use white, black, and colored strips to fill it in or you can guess what should happen.

Pasted Graphic 4

 

  1. Design a combinatorial logic circuit that will accept as inputs OUT1 and OUT2 from the comparator circuit and output a 1 (or HIGH) if the sensor senses red and 0 (or LOW) if it sees white or black. If you have time build this circuit to see if it behaves as you expect. This will be the circuit you use to detect red for the challenge.


    DO NOT DISASSEMBLE THIS CIRCUIT.

    Split detection and navigation

    To complete the design challenge your vehicle must successfully navigate a track that contains 2 splits. The vehicle must autonomously decide to turn right or left depending on the presence or absence of colored tape. In addition to the track navigating circuitry that we have built in a previous lab now we need a different circuit to help us navigate the splits. Lets see how each of the designs handles the split with no external circuitry.

    a) investigate the behavior of the car when it meets a fork -

Pasted Graphic 6

Use the track following/avoiding/seeking circuitry that you have already built on your protoboard in lab 7. Arrange the sensors on the sensor bar as shown in the figure below. Place two sensors in the center of the bar to look at the tape and two more THREE sensor positions away to look at black. Use the appropriate sensors for each navigating scheme as before.

 

  1. Using the tape avoiding circuit, run your car along the track towards the split in the path. When the car reaches the split what happens? Look carefully at how the sensors are looking at the path. What does each sensor see when it stops (if it does)?
  2. Repeat for the other two navigating schemes.

    You should have noticed that once the vehicle came to the fork the sensors on the outside saw white and the sensors in the middle saw black. The tape seeking and tape avoiding algorithms should have just stopped the vehicle and the tape seeking algorithm should have unconcernedly turned either right or left depending on which side you have put the sensor. The logic needs to override these natural tendencies by i) detecting the split, ii) detecting the presence (or absence) of colored tape, and iii) override the normal navigation logic. We will go through each stage seperately.

    b) build a split detecting circuit -

 

Insert another sensor bar onto the car in front of the one that you are using to navigate. Create an identical constellation of sensors. These sensors will be dedicated to detecting the split.

 

  1. Using the output of the 4 sensors S1, S2, S3, and S4, implement the logic you designed in the prelab that creates a signal that is high when the car reaches a split and is low otherwise. Put an LED on the signal that you have created and let the car run on the track until it reaches the split. Is the LED on – indicating a high value? Draw the circuit diagram in your lab notebook.

    This is one part of the circuit that you will need so DO NOT DISASSEMBLE this circuit.

    c) add the circuit detecting the presence of the colored tape -

 

Add a sensor bar close to the vehicle and put one sensor in the middle for detecting the colored tape. Use the comparator module with the threshold settings to detect the colored tape and the logic to discriminate it from white and black. Put an LED on the output of this circuit.

 

  1. Let the car run until it reaches the split. Does this signal behave as you expect when you put colored tape at the split and when you take it off?


    d) add split navigation circuitry -

    At this point to continue navigating the path you have to have some kind of decision making circuit that tells the motors how to turn left or right at the split depending on the status of the control signals S and C. We are going to assume that when your circuitry detects color at the split then the vehicle will turn right.
  2. Generate the L and R signals that the color/split circuit generates to navigate the vehicle along the correct direction at the split. The L signal truth table is filled in - fill in the R signal truth table. These are the signals that will need to take over navigation for a little until the car successfully navigates the split and gets back on track. The L signal the one controlling the left motor is only enabled when the signal S (split detection) is high. Then depending on whether the color is present or not (C=0 no special color, C=1 special color present). If there is color (C=1) turn right, if there is no color (C=0) turn left, if the split detection signal is low you can choose what you want the motors to do - the X in the table means don't care. You should have done this in prelab- put the table in your lab notebook.
  3. Build this circuit on your protoboard, integrating the signals from the split detecting circuit (S) and the color detecting circuit (C) that you built in previous parts. Put the car on the table and let it navigate the split for one of the navigating strategies. Explain the behavior. What worked and what did not. Repeat for the other two strategies.

lab9_split_table