The AVR Starter Kit 500 (STK500) Is a Prototyping/Development Board/System

Total Page:16

File Type:pdf, Size:1020Kb

The AVR Starter Kit 500 (STK500) Is a Prototyping/Development Board/System

ECE4330 – Embedded Systems Design Lab 3 – Optical Sensor Lab 3 - Optical Sensor This circuit detects when a light path is interrupted and when it is completed. Uses typically include counting objects or events such as computing RPM’s of a rotating shaft with a “blade” that interrupts the light path every 1 or ½ cycles. Circuit 3 An Optical Sensor that Reports ON/OFF

Background

Light incident at the base of the optical sensor/transistor causes a much larger current Ic to flow. The transistor is appropriately doped so that when its base is exposed to light (visible or IR depending on the device) the incident photons generate a base current. When the NTE3100’s light path is not blocked it produces +5V at Vc. R1 is a current limiting resistor. The concept of a buffer is interesting. In a circuit it is possible that one component operates over a range of voltages that differs from other components. For example, a sensor might operate from 0V to 10V where any voltage above 5.0V is considered “1”. However, TTL devices operate from 0V to 5V, where “1” is 1.75V or greater. So a sensor value of “0” (4.5V) would be considered a “1” by TTL chips. The solution to this mismatch is a buffer. This is a device that translates digital signals from one protocol to another. Just to confuse the issue, the term buffer is also used with regards to op-amps. An ideal op-amp has low (zero) output resistance and high (infinite) input resistance. The low output resistance ensures that later circuits only “see” the op-amp’s output voltage looking back into the op-amp. That is, the output resistance of an op-amp is usually in series with the input resistance of the next downstream device. This relationship forms a classic voltage divider. Minimizing the op-amp’s output resistance maximizes the amount of input voltage seen by the next device. A typical use of an op-amp buffer is to magnify by 1 a signal from a device with high output resistance into a low output resistance signal. Later circuits can then reference that signal as a low output resistance voltage source with minimal signal loss.

3-1 ECE4330 – Embedded Systems Design Lab 3 – Optical Sensor Figure 3- – Transfer Diagram of a Hex Buffer

Input V DD

Voltages Output V CC

0V

0 15 Time(ns) x x+10

In reality the corners of the Input and Output signals are not so square. If interested wire- up a hex buffer. Use a function generator to drive the buffer, an oscilloscope to observe the input and output signals and a power supply for the rail voltage. Figure 3- – Transfer Diagram of a Schmitt Trigger

Input Volts

V+

Output 5

V -

0V

0 15 Time x x+10

A Schmitt Trigger or Hex Schmitt Trigger is another type of buffer. Consider Figure 3- and estimate how the output would behave if the input had a “debounce” problem. That is, if the input quickly rises and falls several times then the output would also rise and fall. A Schmitt Trigger handles a partial loss of an input voltage by having two thresholds: V+ where any voltage above this value turns the Schmitt Trigger ON; V- where any excursion less than V- turns the trigger OFF. The input to a buffer is a signal from a transistor. The transistor is half of a photon coupled interrupter switch (NTE3100). The other half is an infrared emitting diode. A specification sheet for the NTE3100 is available on the course web site. Print this sheet and read it. The following background material should remind you about the basic principles of diodes and transistors. You will need to correlate the specs (which are sparse at best) to the actual device and you will need to design supporting circuitry. Recall, diodes are non-linear devices. A forward biased diode exhibits a linear relationship between current and voltage until a threshold voltage is impressed across a diode, at which point current flows virtually un-impeded. The polarity of the threshold voltage determines if a diode is forward or reversed biased.

3-2 ECE4330 – Embedded Systems Design Lab 3 – Optical Sensor Figure 3- – A Prototypical Diode I +V f

+ - V Vd R d R - 1 + 1

Ir +V

a) Forward Biased b) Reverse Biased

R1 limits the current flow through the diode. An infrared emitting diode simply emits photons as well as enforcing a one-way flow of current. Your electronics textbook should have a pro-forma graph of a diode’s I-V relationship. This graph should show at what voltage a typical forward/reverse biased diode starts to allow forward/reverse current to flow unimpeded. Also, data sheets define the forward and reverse thresholds. While a diode implements one-direction flow of current, a transistor acts as a multiplier or valve of current. When correctly biased a transistor can function in either its cutoff or its saturation region and exhibit switch like behavior. In the NTE3100 little or no IR light on the base of the detector (transistor) allows no current to flow through the transistor. Therefore, its output at Vc presents a voltage equal to ground. Circuit 3- - Electronic Devices in an Opto-Isolator Switch +5V

+ ICE Vd R - 1

VE

VC

R2

If the base of the transistor detects IR photons then current flows through the transistor and the biasing resistor (R2 in Circuit 3- on page 3-1) develops a voltage. This voltage represents the ON-signal. The obverse is possible with a resistor at the transistor’s emitter. Circuit designers must match polarities of bits as they flow through a circuit. That is, a “1” at device A might be 0V while the same “1” at the next device B might be 5V. Again, the transistor can be configured so that OFF is  5V and ON is  0.7V.

3-3 ECE4330 – Embedded Systems Design Lab 3 – Optical Sensor The next step is to decide if the logic state is derived from Vc or Ve. This in turn determines the placement and value of R2. Also, the value of R2 is constrained by the current ratings defined in the NTE3100 specifications sheet. This has been completed and is shown in Circuit 3-4.

Circuit 3-4

Pre-Lab assignments 1. Read B, C, and O (course text), chapter 2. 2. Read the data sheet for the NTE3100 on the course web site. 3. Complete the Pre-Lab Questions In-Lab Tasks 1. Design and build the supporting circuitry for an interrupter module. Do not connect it the STK500. Test the interrupter module as standalone circuit.

2. Wire a buffer and connect the interrupter to it. Verify that VC has appropriate voltages when the light path is both blocked and unblocked. Repeatedly block/unblock the light path. Is there a “debounce” problem? If the light path is not blocked, use the oscilloscope to measure VC. Hint. Ground all unused pins on the buffer.

3. Now, complete Circuit 3-4 by connecting it to Port B/B0 and use the VTG/GND pins on the STK500 as the circuit’s power supply. 4. Write software for the ATMEL 8535 that counts the number of times the optical sensor is blocked/unblocked. Use a software loop to poll the input pin, Port B/pin B0. Your design should include hardware and software so that the user can indicate when to start and stop the count. Also, the user should “know” when the counter is operating.

3-4 ECE4330 – Embedded Systems Design Lab 3 – Optical Sensor One solution is to designate and read start/stop buttons and status LED’s on the STK500. Again, when using CodeVision to generate code be sure to specify all of the ports that you are going to use and whether they function as input or output pins. Once you see how CodeVision sets the various control registers then you can start to write your C-code from scratch. Hint. When using the code generator be sure to update the Program Information tab. The text you enter is automatically inserted into your code. 5. Refer back to Lab 1 for details on the strappings necessary to use the STK500’s switches and LED’s if you want to use them. Parts List 1. Hex Buffer or Schmitt Trigger 2. Interruptible Light Path 3. 10-wire cable for STK500 I/O (2) 4. RS-232 Cable 5. two-wire cables with a connector at one end (2) Deliverables Demonstrate to the lab instructor how your device functions as it is activated/deactivated and as the light path is blocked/unblocked. Your write-up should include how you characterized the interruptible light path and it should document the meanings of status LEDS and of start/stop buttons. Software requirement as described in class notes Lecture2-Lab3 Software design needs to support (1) a start button (2) a stop button (3) a reset button to reset counter (4) counter recording number of objects blocking the light. (5) a heartbeat signal on LED0 (6) LED7 toggles when a block is detected.

3-5 ECE4330 – Embedded Systems Design Lab 3 – Optical Sensor

Pre-Lab Questions Name: ______Answer the following questions based on pre-lab assignments. These questions will help you to complete the programming assignments. Be sure to include your work and show units, as appropriate, on your answers. 3/3/4 points each, 10 points possible. 1. Write a fragment of c-code to initialize the Port C pins so that the upper nibble can be used for input and the lower nibble can be used for output (Section 2.6)?

2. Write a fragment of c-code to initialize Port A and the least significant bit of Port B to be an input, and the balance of Port B to be output (Section 2.6)?

3. Write a c-code function that reads from port B, bit 0 and returns the value.

3-6

Recommended publications