0% found this document useful (0 votes)
41 views6 pages

Sensors

This document provides instructions for an assignment involving programming a microcontroller to display time on a 7-segment display and measure distance using an infrared sensor. Students will use shift registers to control the display and sample an analog sensor to measure distance, performing filtering before displaying the output. Code submissions and demonstrations are required.

Uploaded by

githexs.comm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views6 pages

Sensors

This document provides instructions for an assignment involving programming a microcontroller to display time on a 7-segment display and measure distance using an infrared sensor. Students will use shift registers to control the display and sample an analog sensor to measure distance, performing filtering before displaying the output. Code submissions and demonstrations are required.

Uploaded by

githexs.comm
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

15-348 Homework 5 Page 1 of 6

15-348: Embedded Systems, Fall 2022


Homework 5: Gettin’ Shifty With It
Due: Thursday, October 13th, 2022 by 10:00pm

Part Quantity
Launchpad 1
SHARP 2Y0A21 infrared (IR) proximity sensor 1
4-Digit, 7-Segment Display 1
220Ω Resistor 4
1KΩ Resistor 4
2KΩ Resistor 1
2N3906 Transistor 4

Introduction
This is a programming homework. You must submit your code to Gradescope by Thursday,
October 13th, 2022 by 10:00pm. Only submit the files indicated below. You should also
demo your code to the one of the course staff members on or before Monday, October 17th
during one of the available slots. You can only demo once. More instructions about the demos
will be announced during class and on Piazza.

Learning Objectives:
Learn the proper use of shift registers.

Getting Started:
1. For each task, create a new project in CCS, as explained in the tutorial on the website.

2. Submit only the source code files that you modified (i.e., not the entire project, binaries,
etc).

Some Important Notes:


1. You should read the entire assignment before starting. This will help you predict what
your final circuit will look like, what sort of functionality your software will need, etc.

2. We expect that your implementation exactly matches the specifications indicated below.

3. Although we might be lenient with unspecified behaviors, you should justify your imple-
mentation choices.

4. If you are unsure about the specifications, you should ask questions on Piazza or directly
to the course staff.

5. Reading, understanding, and eliciting the requirements and specifications is also part of
the assignment.

1
15-348 Homework 5 Page 2 of 6

Task 1: Telling Time (30 pts)


Use the 4-digit 7-segment display to show time as a clock. The first two digits should display
the hours. The second two digits should display the minutes. The two dots in the middle
should blink continuously - turning on for one second and off for one second.
You should display the time in 12-hour format. Your code should always start at 12:58
pm. The initial value of the time can be hardcoded in your program.

About the 7-Segment Display


7-segment displays are 7 specially arranged LEDs that can be used to display digits. We will
be using an LED display that has 4 digits – basically a 4-digit, 7-segment display. In addition
to the 28 LEDs that constitute the segments, our display has LEDs that can display points
between the digits. In particular, we will use two of these LEDs to display a colon between the
middle digits. The datasheet can be downloaded from:
http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AB4B-35.pdf
There are 16 pins in this component. From a top-down view, the pin on the bottom left is 1,
and the pin on the top left is 16. A diagram of how the pins are laid out (from the top-down),
as well as the labels for each LED segment, is:

Image courtesy of http://www.theengineertutor.com/blinkie-improved-part-3-of-3/

There are two types of single-digit 7-segment displays: common anode and common cathode.
In common anode displays, the anode of the LEDs is connected to one pin (usually connected to
a power source). In common cathode displays, the cathodes are connected to one pin (usually
connected to ground). Our display is common anode. There are six input pins (power pins)
that serve to power each digit and the extra points. The other 10 pins are “ground pins”,
meaning that when connected to ground, the corresponding LEDs light up.

2
15-348 Homework 5 Page 3 of 6

As you can see in the image above, the display has:

• 1 power pin for each digit (pins 1, 2, 6, and 8)

• 1 power pin for the colon (pin 4)

• 1 ground pins for each segment (A-G) (pins 14, 16, 13, 3, 5, 11, and 15)

• 1 ground pin for the decimal point (pin 7)

• 1 ground pin for the colon (pin 12)

• 1 power and ground pin for the apostrophe (pins 10 and 9).

Using the Shift Registers


You will need to control at least 12 pins of the display (all except the pins associated with the
apostrophe and the power pin of the colon). Our board could in principle handle that many
outputs, however, it is always convenient to save the pins for other tasks. For this reason, we
will use two shift registers, connected in series, to generate the desired, synchronized output to
the display.
Connect each power pin to the collector of a 2N3906 transistor. The emitter of each transis-
tor is connected to the 3.3V pin of the board through a 220Ω resistor (this acts as the current
limiting resistor for the LED segments). Connect the base of each transistor to one pin of the
shift registers through a 1KΩ resistor (you need a resistor between your pin and the base). In
this way, we can control the flow of current to the anode pins of the display. The 2N3906 is, by
default, in the ON state. If we provide ground (pin LOW) to the base pin then the transistor
will be turned ON. If supply is provided to the base pin (pin HIGH) it stops conducting current
between emitter and collector and is said to be in an OFF state.
Connect the power pin (4) of the colon (:) to power using a 2K resistor. Connect each
ground pin of the segments, and the decimal point, to a pin of the shift registers. Connect the
ground pin of the colon to a pin of the shift register.
The following figure shows an example circuit:

3
15-348 Homework 5 Page 4 of 6

How to Display Digits


To display a number in a specific digit, we must provide power ONLY to that digit through its
respective pin. So, if we want to write the number 3 in the first digit we make pin 1 HIGH and
pins 2, 6, and 8 LOW. This enables the flow of current through transistor T1 and disables T2-4.
We now set all segments for digit 3 LOW, and not used segments to HIGH. Ground pins work
with negative logic, so writing a LOW enables them. All these values should be provided by the
shift register, which in turn gets these values from the board. Your code should clock (shift) all
the values associated with the output pins connected to the display inside the register. Each
bit value is shifted one by one. Once done, use the ST CP pin to send the output to the display.
What about the other digits? You might notice that there are 35 LEDs (28 segments and
7 points) in our display. How can we control 35 LEDs using only 16 pins? The answer is
multiplexing. You can switch on only one digit at a time but do it so fast (at least 100 Hz)
that all the digits appear to be on simultaneously.

4
15-348 Homework 5 Page 5 of 6

Task 2: Proximity (20 pts)


In this task, we will use the SHARP 2Y0A21 infrared (IR) proximity sensor.
An IR sensor uses a beam of IR light to reflect off an object, and by measuring
the reflected signal, it estimates the distance to the object. The 2Y0A21
sensor provides an analog output that varies from 3.1V at 10cm to 0.4V at
80cm. You must use the ADC of the LaunchPad to translate the value of
the analog output signal to the distance value in millimeters to any object
placed in front of the sensor.
The relationship between the analog voltage output and the measured distance is approxi-
mated by this curve, taken from the sensor’s datasheet:

The formula for the curve is roughly:

Distance (cm) = 29.988 ∗ V0−1.173 (1)

The complete datasheet can be found at:


https://global.sharp/products/device/lineup/data/pdf/datasheet/gp2y0a21yk_e.pdf
The sensor has 3 pins: VCC, Ground, and Data. You will need 5V to power the IR sensor.
Ground should be connected to the LaunchPad as usual. The data pin is the one that provides
the analog output that must be converted, therefore you should wire it to one of the ADC pins.
Your task is to configure ADC to read the value of the analog signal, translate the analog
voltage into a distance value in mm, and display that value (with an accuracy of one decimal
place) on the 7-segment display. The sampling rate should be 20Hz. You should update the
value on the display at a rate of 1Hz (the displayed value is updated once every second).
You will notice that the signal is noisy. Therefore, you should implement data filtering by
calculating a running average of the last 20 readings. (This means that every one second, the
display will update with the average distance measured over the last one second.)

5
15-348 Homework 5 Page 6 of 6

Additional Guidance
Hardware Testing
This lab includes multiple components that are interfaced together in ways that can be tricky
to get right. Make sure to test each functional unit separately. For example, connect the
power lines from your display to the transistors, connect all the ground lines to ground, and
try turning on individual digits by manually connecting a transistor base to low.
If you build the entire circuit and then try to use it, things are unlikely to work and you
will spend many, many hours looking for the mistakes.

General Tips
• Work incrementally, testing each small piece of functionality as you go. For example,
your first step might be simply seeing if you can toggle an output pin from 1 to 0 and see
the voltage change on the multimeter.

• If you spend too long debugging something, and can’t find the problem, start over. Rewire
your circuit and rewrite the code from scratch. It shouldn’t take you that long the second
time, and you may be surprised to find that it works.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy