Lab6

pdf

School

University of Illinois, Chicago *

*We aren’t endorsed by this school

Course

266

Subject

Electrical Engineering

Date

Apr 3, 2024

Type

pdf

Pages

7

Uploaded by MinisterMusicAnt88

Report
Lab #6 Ambient Sensing (ADC) Spring 2024 Week 8 (2/27 or 2/29) Lab location: 3268 SEL Lab Times & TAs Tuesday, 8:00am-9:50am, with TA Maeesha Binte Hashem Tuesday, 12:00pm-1:50pm, with TA Trung Le Thursday, 8:00am-9:50am, with TA Yaroslav Popryho Demo Due: The beginning of your lab in the Week 9 (3/5 or 3/7) Submission Due: Friday, Week 9, 3/8 Introduction The goal of this lab is for you to have hand-on experience with the on-chip ADC (Analog-to-Digital Converter) of Tiva C. The learning objectives are: Learn how to program an ADC of Tiva C Learn how to use analog sensors with ADC Continue to exercise interrupt I/O programming Continue to exercise mixed C and Assembly programming Note: You will study ADC design in Week 13. This lab will help you understand ADC design. This lab has starter code. It prints out the readings of a temperature sensor inside Tiva C. You will extend the starter code to do the following: 1. Integrate the 7-seg into the system to show sensor readings (C programming) 2. Extend the system to show the readings from a light sensor (C programming) 3. Convert your C code for the light sensor to assembly (Assembly programming) Important : Before you start on Part 1, read through the lab manual, the lab slides, and the starter code. Do the readings in the prelab. Then, discuss with your partner about the approach, identify tasks, and assign the tasks to partners. There will be a bonus part related to this lab. It will require you to re-write your code for the light sensor using ADC I/O registers access, without using any TivaWare function. The bonus part will be released during the project time.
Prelab Read textbook, Ch. 20 “Analog-to Digital Converter”, the introduction and Ch. 20.1 (pages 481-483). Note: Tiva C uses the successive-approximation (SAR) architecture. Read Tiva C Datasheet, pages 799-803 (to the end of Sec. 13.3.1) and pages 807- 809. Note: Pay attention to Figures 13-1 and 13-2, and Tables 13-1 and 13-2. Read TivaWare Datasheet (User Guide), Ch. 4 “Analog to Digital Converter (ADC)”. Note: Read the introduction (page 21) carefully, then scan the rest of the chapter, and then read the programming example on page 46. Print out a copy of the lab grading form (“Lab6GradeForm.docx”). Fill the form and give it to your TA before your demo. Answer the lab questions in the appendix. This is an important step. Do not skip. Tiva C Datasheet and TivaWare Datasheet can be found in the “Resources” section on BlackBoard. Background ADC is used in many embedded systems with analog sensors or devices, e.g., analog temperature sensor, analog sound sensor, microphones, image sensors, and so on. An ADC converts the voltage of an electrical signal to a digital number. For example, assume that an ADC uses a reference voltage range from 0.0V to 3.3V and yields a 12- bit digital output (0 to 4095). If the voltage of the analog signal, denoted as a , is 1.0V, then the digit output d will satisfy: a /3.3V @ d/4096 d = floor ( a /3.3V * 4096) = 1365 Exercise : What is the digit output d if a = 2.5V? This lab uses two analog sensors: 1) a temperature sensor inside Tiva C, and 2) a light sensor in the Gove box. They convert temperature and light intensity to voltage, respectively. Preparation The following is to be done by one partner: 1. In your ECE 266 lab working folder, create a new folder named Lab6. Download lab6_main.c, temp_sensor.h, temp_sensor.c, and temp_sensor_asm.asm into this folder. 2. Switch to CCS. Create a CCS project named Lab6 with an external reference to the Lab6 folder, add the include paths and library paths, and change the stack and heap sizes as in previous labs. Build the system, run it, open the terminal, and verify that the temperature readings are printed to the terminal.
3. Switch to GitHub Desktop. Commit the above changes to your local repository, then push the changes to GitHub. Verify at https://github.com that the new changes appear in the GitHub repository. Then, the other partners may pull the changes (in GitHub Desktop) and create the CCS project (in CCS) with the same configurations. Use the following hardware configuration through the lab: 1. Attach Tiva C LaunchPad to the Grove baseboard 2. Attach the 7-seg to jumper J10 of the Grove baseboard 3. Attach the light sensor to jumper J5 of the Grove baseboard Part 1: Integrate 7-Seg The starter code reads the temperature sensor of Tiva C and then prints the reading on the CCS terminal. Your code should the 7-seg show the reading. Copy all 7-seg related codes from Lab 3 to this lab. Then, study the starter code in more detail. Note the following: temp_sensor.c provides functions to 1) configure ADC for the temperature sensor, 2) trigger ADC sampling, 3) check if data is ready, and 4) get the most recent data. Additionally, it has an ISR that reads data from the sensor to memory variables. lab6_main.c contains a callback function that triggers the reading of the temperature sensor periodically (every four seconds). When the data is ready, an interrupt signal is sent to Tiva C, and another callback function is called to convert the reading to Celsius and print the result to the CCS terminal. Revise “lab6_main.c” so that the reading is also shown on the 7-seg as follows: The temperature is shown in Fahrenheit on the leftmost three digits of the 7-seg digits. The rightmost digit should be turned off. The two digits on the left should show the integer part of the reading, and the next digit should show the fraction. The colon should be turned on. The following is an example for a temperature reading of 66.9 F:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Part 2: Read the Light Sensor Overview . In this part, you will extend the system to show the readings from the light sensor. Create two new C program files named light_sensor.c and light_sensor.h. You may use temp_sensor.c and temp_sensor.h as the templates. Create/revise data structure and the functions in “light_sensor.c” to: 1. Configure ADC for the light sensor (see below). 2. Trigger ADC sampling for the light sensor. 3. Upon callback from ISR, show the light sensor reading on the 7-seg (see below). 4. In an ISR, read the light sensor and record the reading in the data structure. ADC Configuration . Use sequencer #1 of ADC0 for the light sensor. Sequencer #0 of ADC0 has been used for the temperature sensor. You need to enable interrupt on sequencer #1, otherwise the ISR will not be executed. ADC Channel . You need to know the ADC channel number for the light sensor. You need to track the marks on the sensor module, the Gove base board, and the Tiva C board to find out the GPIO pin being used. Then, check out the Tiva C Data sheet, Table 13-1 (pages 801-802), to find out the corresponding ADC’s pin name. The pin name is in the form of AIN x , where x is the ADC channel number. Then, find out the name for the ADC channel in the TivaWare datasheet, Ch. 20 “Analog-to Digital Converter”. That is the name you will use in programming. Revising “lab6_main.c” . Revise the code so that the system behaves as follows: The light sensor is sampled every four seconds. Print the raw readings on the terminal. A valid reading should range from 0 to 4095. Show the light sensor reading on 7-seg, using all the four digits, with the colon turned off and any leading zeros removed. The following is an example: The 7-seg should show the temperature reading for two seconds, the light sensor reading for two seconds, and repeat. Part 3: Assembly Programming Create a new file light_sensor_asm.asm. Re-write all your functions in light_sensor.c in this assembly program file. Exclude light_sensor.c from the project, so that you don’t have to delete it from the project, by right-clicking on light_sensor.c and then choosing “Exclude from Build” (see below).
Build your project. Fix any errors and bugs that may appear. Your system should behave the same as in Part 2. Demo Requirement Demo your system to your TA. If you can demo Part 3, you don’t need to demo Parts 1 and 2. For Part 3, you must show to your TA that “light_sensor.c” is excluded from the build. During the demo, heat the temperature sensor to cause temperature change (e.g., by putting your finger on the Tiva C chip), and change the light intensity on the light sensor. The readings shown on 7-seg should change accordingly. Explain your code to your TA. If asked, each of you may have to answer questions from your TA, and you must show a good understanding of how your code works. Your answer may affect your grade individually. Lab Report Your group should write a lab report that includes the following contents. A template for the report has been provided in the attachment of the lab assignment. 1. Describe the responsibility of each person in your group, and estimate the breakdown of contribution in percentage (e.g., 50% and 50% for a two-person group, or 33.3%, 33.3% and 33.3% for a three-person group). Note: If a partner contributes 40% or higher in a two-person group or 25% or higher in a three-person group, the partner may receive the same grade as the group gets. 2. Describe how you implement the functions in “light_sensor.c”. 3. How much flash memory does your program take? How much SRAM memory? 4. Estimate how many hours in total you and your partners have worked on this lab and discuss any challenges you have had. 5. Answer the lab questions in the Appendix. Coding Style To receive full credit, double check that your source code in C follows a revised version of the Google C++ Style Guide: See https://gist.github.com/davidzchen/9187878 for a sample of the style guide
simplified for C programming. See https://google.github.io/styleguide/cppguide.html for the full detail of the guide. Revision of the style guide: Use indentation of 4 spaces instead of 2 spaces. That is because the CCS auto-formatting feature uses indentation of 4 spaces by default. In CCS edit perspective (see CCS menu, Window => Perspective), you may auto- format your code as follows: Select a code area that you want to auto-format, then press shift-command-F. You may also explore the right-click menu. Your assembly code should also be well formatted with good comments. If your code does not follow the above guidelines, your group may lose points on “ Lab report, coding quality, GitHub update” (see the grading form). Hint : In CCS, you may use Command-Shift-F to automatically format a selected area of source code. Lab Submission Push the latest version of your code into your group’s repository on GitHub. This step is required for you to get the grade. Submit the following items on BlackBoard under Lab 5 assignment: Revised lab6_main.c light_sensor.c light_sensor.h light_sensor_asm.asm The completed lab report
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Appendix: Lab Questions 1. How many on-chip ADC modules does Tiva C have? 2. What is the ADC precision (resolution) in number of bits? 3. What is a sample sequencer? Give the best answer based on your understanding. 4. How many sample sequencers does each on-chip ADC module have? 5. How many ADC channels in total does the microcontroller support? Note: Your answers will be graded by the effort level (same requirements as in homework grading). If you need help, contact your TA or the instructor for help.