Starting from:
$144

$138

Lab 3 & 4 Solutions

In this laboratory you will use the MSP430 and several of its peripherals to implement a system that measures temperature (using ADC12's internal temperature sensor) and time (using Timer A2) then displays time along with the temperature to the LCD. The main purpose of the assignment is to gain some experience using MSP430's analog-to-digital converter. However, you will have to make use of some elements from previous labs and homework like timers, decimal-to-ASCII conversion and text display of numeric results.

 

 

Assignment:

 

Digital time and temperature displays are a common sight (e.g. banks, shopping malls). In this lab you will make a mini time and temperature display using the MSP430. First, you will implement a UTC -style clock (see Homework 3) with one second resolution. The temperature sensor you will use is the MSP430's internal temperature sensor which is connected to ADC12_A analog input channel 10 (ADC12INCH_10). You will also need to implement the Scroll Wheel (HW#4).

 

Pre-lab (Due in Lab Weds 9/26/18): This pre-lab is to be completed before your lab session. You should have your original pre-lab paper signed and dated by a member of the course staff at the start of lab. They should also sign & date the pre-lab box on your sign-off sheet.

 

READ THE ENTIRE LAB ASSIGNMENT!!
 

Write a displayTime() function which takes a copy of your global time count as its input argument. Your function should convert the time in seconds (which was passed in) to Month, Day, Hour, Minutes and Seconds. It should then create ascii array(s) and display date and time to the LCD in the format specified Step 6 below. Explain why it is important to pass a copy of the time into the function rather than just using the global variable.
 

Write a displayTemp() function which take a copy of the floating point temperature in C and displays temperature in both C and F to the LCD as specified in Step 6 below. This function is just a display function. While it may convert C to F, it should not do the averaging of past temperature readings described below.
 

Requirements:

 

In implementing the time and temperature display you are required to complete each of the following tasks. You do not have to complete the tasks in the order listed. Be sure to answer all questions fully in your report.

 

No welcome screen this time just right to business. As soon as the program is started the systems should start displaying date (month and day), time and temperature.
 

The system will take temperature measurements once per second. Timer A2 should be configured to measure 1 second intervals. Implement a UTC-style clock count capable of holding 1 yr of time (sec). What data type did you use to store your time count? Initialize your UTC count to the last 7 digits of your student ID number. Manually convert that number to date and time to confirm that your code is correct. Include your validation (for both partners' ID numbers) in your report.
 

The system will measure temperature using the MSP430's internal temperature sensor (see User's Guide Ch 28 and class notes).
 

Configure the ADC12 to make single channel, single conversion readings from the internal temperature sensors. Select your reference voltages to achieve the best resolution while being able to measure temperature in the range -40 to 100o Justify your choice in your report. What will the resolution of your readings be in volts and in Co /bit? Convert your ADC readings to degrees C.
 

Store the last 256 readings into 2 arrays: times[] and tempC[]. You should use “circular indexing” with your array index defined to be of type char rather than shifting the arrays around. It's much more efficient. Explain why circular indexing is efficient in your report and why you can use a char as the array index with out any additional index math (other than incrementing the array index).
 

Your LCD should continually display the following items holding the display for 4 seconds between updates. Month should be the abbreviated name not a number. YOU MAY NOT USE sprintf()!! See Intro slides for why.
Date = MMM-DD (i.e. SEP-22)

 

Time = HH:MM:SS (i.e. 16:02:49)

 

Temp (C & F) = ddd.f C / ddd.f F (i.e. 24.7C / 72.3F)

 

 

 

 

IMPORTANT: The readings from the temperature sensor are rather noisy. They jump around a lot from reading to reading. Therefore, the

temperature displayed should be the average of the last 4 temperatures measured. Show TA/tutor exactly how you did this!

 

Implement the scroll wheel (see HW#4). Select your reference voltages and configure your code such that they cover the entire range of voltages than can be generated by the scroll wheel. Explain your choices for the scroll wheel reference voltages. Leave Vref+ for the temperature sensor as it was. Explain where and how your set the reference voltages for the two input channels.
 

When the button S1 on the lab board is pressed the buzzer should sound but the pitch of the buzzer should be controlled by the scroll wheel. When the wheel is turned in one direction the pitch of the buzzer should go up. When the wheel is turned in the other direction then the pitch of the buzzer should go down. Pressing button S2 should turn the buzzer off . How will you map the output of the scroll wheel to buzzer pitch? Explain in your report?
 

Write a high quality lab report answering all the questions in the requirements section!
 

10)BONUS (5 pts): Use ADC12 interrupts instead of busy bit polling to signal completion of ADC conversions. Explain how ADC12 interrupts are configured and what your ISR does in your report.

 

11)BONUS (5 pts): Have your clock toll the hour (like a church tower) using the buzzer. Explain completely how you achieve this in your report.

 

 

 

 

 

WARNING and a HINT on number conversion: Here's a fun(?) issue that students can encounter when converting the time and date, which is related to how the CCS MSP430 compiler handles constant data types. If you type a line like this:

 

long x = 24 * 3600;

 

You'll get a warning reading "integer operation is out of range" because the compiler treats the constants as int's (i.e. as 16-bit integers) before

 

multiplying them, so the multiplication will overflow before the result is assigned. This may seem silly, but it kind of makes sense because our MSP430 is a 16-bit machine. It's default word size is 16-bits and operations on longs are emulated in software. To make the MSP430 actually multiply the numbers as longs, you can either use integer suffixes to tell the compiler that the constants are longs, like this:

 

 

long x = 24L * 3600L;

 

... or cast either of the operands:

 

 

long x = ((long)24) * 3600;

 

Writing a High Quality Lab Report:

 

Your lab should be written in a professional style. It should be an electronically prepared technical document like what you would submit to a co-worker or your boss. The report should include the following:

 

Cover sheet = An appropriate, professional-looking cover sheet with the
 

title of the assignment and the names and ECE box numbers of each student.

 

YOUR SIGN-OFF SHEET!!! Most of the points for the lab are listed on the sign-off sheet. If you do not submit it then you will not receive the points.
 

Introduction = 1-3 paragraphs (1/2 page tops) succinctly stating the objectives of the lab and giving an overview of what you accomplished.
 

Discussion and Results = As many pages as it takes (without padding!). In this section you should thoroughly discuss what you did in each part of the lab. You should describe the approach you took to solving any problems. Include pseudo code descriptions and/or flow charts for any code developed. Results should also be thoroughly discussed. Any measurements should be tabulated, questions (especially those in yellow!) should be answered completely, figures should not be hand drawn, snippets of code may be included where useful but a full code listing is not required or desired. Instead, code should be submitted electronically (see below).
 

Summary and Conclusion = 1-3 paragraphs. Wrap-up and summarize what you accomplished in the lab. This should be a “bookend” to the introduction.
 

Appendices = Include any pre-labs, relevant raw data sheets or reference material, etc.
 

 

 

 

 

 

To submit your code for grading, you will need to create a zip file of your CCS project so that the TAs can build it. You can also use this method to create a complete backup copy of your project, to do this:

 

Right click on your project and select "Rename..."
 

If you are submitting your project, enter a name in the following format: ece2049A18_lab3_username1_username2, where username1 and username2 are the user names of you and your partner. (NOTE: Failure to follow this step will result in points deducted from your lab grade!)
 

Click OK and wait for CCS to rename your project.
 

Right click on your project again and select "Export..." then select "Archive file" from the list and click Next.
 

In the next window, you should see the project you want to export selected in the left pane and all of the files in your project selected in the right pane. You should not need to change which files are selected.
 

Click the "Browse" button, find a location to save the archive (like your M drive) and type in a file name using the EXACT SAME NAME used in Step (2).
 

Click "Finish". CCS should now create a zip file in the directory you specified.
 

Go to the Assignments page on the class Canvas Click Lab 3 Code Submit. Attach the archive file of your project that you just created and hit the Submit button. Only one submission per team.

 

 

 

 

LAB 4 Solution

 

 




Which is better, the SPI Digital-to-Analog Converter or the Built-in Analog-to-Digital Converter. In this laboratory you will gain further experience with SPI by using the MSP430 and the MCP4921 DAC to create a simple function generator. Specifically, your function generator will be capable of generating different DC values as well as a square wave, a sawtooth wave and a triangle wave. You will also investigate the accuracy of both the DAC and the ADC12.




Pre-lab: There is no pre-lab this week but you will use some of the material covered in Homework #5.




Requirements:




In implementing this lab you are required to complete each of the following tasks. You do not have to complete the tasks in the order listed. Be sure to answer all questions where indicated. Your answers should be complete and in complete sentences. There

is no formal report this week. The sign-off, screen shots and the answers to the questions are it! Plus code submission, of course.







This week your welcome screen should instruct the use how to use the function generator. For example, Button 1 = DC, Button 2 = Square wave, etc.



When button 1 is pressed your function generator should produce a DC voltage. The value of the voltage produced should be controlled by the scroll wheel. When the wheel is turned in one direction the DAC output voltage should increase and when the wheel in turned in the opposite direction the output voltage should decrease. How does the MCP4921 LDAC work? Do you have to repeatedly send the code to the DAC to maintain the voltage or do you only need to send the code once then give the LDAC? ______________________






Take a screen shot of your DC output on the oscilloscope.



CONNECT THE OSCILLOSCOPE CAREFULLY. Connect ground first ( on Launchpad J10 jumper). Do not short any other pins to ground when connecting the scope ground! It's very easy to do. Be careful. Then connect the positive lead of the oscilloscope to the DAC Out pin.

Jumper P7 selects the supply voltage for the MCP4921 DAC. The two options are 3.3V and 5V. Exit the debugger and Completely Unplug the lab board and then move the P7 jumper to the 5 volts setting. Reconnect the board an d measure the minimum and



maximum DC voltages your DAC can actually generate when P7 is in the 5V position? Min __________ Max ___________




Unplug the lab board and move the P7 jumper back to the 3.3V setting. IMPORTANT: Use the 3.3V setting for the rest of the lab.




Reconnect the board and measure the minimum and maximum DC voltages your DAC can actually generate when P7 is in the 3.3V position?



3.3V Reference: Min __________ Max ___________







When Button 2 is pressed, the function generator should generate a 80 Hz square wave. Again the peak amplitude should be controlled by the scroll wheel with the minimum voltage=0V. Use the Timer A2 to implement your waveform. Software delays are not acceptable. Take a screen shot of your square wave output on the oscilloscope clearly showing the period. Period __________.






Read up on the performance of the MCP4921 DAC. Specifically, document the following. What is the function of LDAC? How soon is the output voltage available after LDAC is applied? How fast can you effectively change the output voltage?


















When Button 3 is pressed, the function generator should generate a 75 Hz sawtooth wave. Use the information you learned from question (6) above to make the best staircase approximation to a sawtooth that you can. What are your step size increment and step duration? Why? You must justify your step size!! Just choosing a number is not enough.



In this case, your peak amplitude should be the supply voltage (i.e. 0 to Vcc, or as close as you can achieve). Use the Timer A2 to implement the stair steps and period your waveform. Software delays are not acceptable. Take a screen shot of your sawtooth wave




output on the oscilloscope clearly showing the period. Take a




zoomed in screen shot, too, showing your staircase approximation.




Period ___________.







When Button 4 is pressed, the function generator should generate a 100 Hz triangle wave. Again, use the information you learned from question (6) to make the best staircase approximation that you can. What are you step size increment and step duration? Why? Again you must justify your choices. Numbers alone are not enough.



























10)The peak amplitude should again be Vcc, or as close as you can achieve. Use the Timer A2 to implement the period of your waveform. Software delays are not acceptable. Take a screen shot of




your triangle wave output on the oscilloscope clearly showing its period. Take a zoomed in screen shot, too, showing your staircase




approximation. Period __________.







PLUS 10 pts: Have the scroll wheel control the frequency of your triangle wave. The output frequency range should be 50 Hz to 250 Hz. Again, you must use Timer A2 implement the period of the waveform. The amplitude should be Vcc. Take a screen shot of your triangle wave output on the oscilloscope at 3 different frequencies with period clearly shown.









In this part you will test the linearity of the DAC and the ADC. Write a function that will take a single channel, single conversion measurement from the ADC (see lab 3). Use analog input channel A1 (P6.1) for the ADC input and set the Vref+ to be AVcc. Your function should return a floating point value equal to the input voltage on A1. Using the single pin jumper wire provided by the course staff, connect the DAC OUT pin to the A1 (P6.1) input on the Launchpad header.



Modify your code to call your ADC function in your main loop only when Button 1 is pressed. Set a break point after the call so that you can examine the voltage returned by the ADC function and also measure the DAC output voltage on the ocsilloscope. Take at least 10 measurements for DC values across the range from 0 to



3.3V. Tabulate the (1) codes sent to DAC, the (2) the expected DAC output voltage for that code (3) the DAC output voltage from oscilloscope and (4) the voltage returned from your ADC function.

































































































Is the MSP430 ADC12 actually linear? What about the MCP4921DAC?





































What impact do your findings have for a measurement system that relies on either or both or these devices?
To submit your code for grading, you will need to create a zip file of your CCS project so that the TAs can build it. You can also use this method to create a complete backup copy of your project (perhaps to archive or send to your partner) for later. To do this:




Right click on your project and select "Rename..."



If you are submitting your project, enter a name in the following format: ece2049a18_lab4_username1_username2 , where username1 and username2 are the user names of you and your partner. (NOTE: Failure to follow this step will result in points deducted from your lab grade!)



Click OK and wait for CCS to rename your project.



Right click on your project again and select "Export..." then select "Archive file" from the list and click Next.
In the next window, you should see the project you want to export selected in the left pane and all of the files in your project selected in the right pane. You should not need to change which files are selected.
Click the "Browse" button, find a location to save the archive (like your M drive) and type in a file name using the EXACT SAME NAME used in Step (2).



Click "Finish". CCS should now create a zip file in the directory you specified.
Go to the Assignments page on the class Canvas website. Click Lab 4 Code Submit. Attach the archive file of your project that you just created and hit the Submit button. Only one submission per team.

More products