Lab 4: Using the Digital-To-Analog Converter
Total Page:16
File Type:pdf, Size:1020Kb
ECE2049 – Embedded Computing in Engineering Design Lab 4: Using the Digital-to-Analog Converter In this lab, you will gain experience with SPI by using the MSP430 and the MSP4921 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. Pre-lab Assignment There is no pre-lab for this lab, yay! Instead, you will use some of the topics covered in recent lectures and HW 5. Lab Requirements To implement this lab, you are required to complete each of the following tasks. You do not need to complete the tasks in the order listed. Be sure to answer all questions fully where indicated. As always, if you have conceptual questions about the requirements or about specific C please feel free to as us—we are happy to help! Note: There is no report for this lab! Instead, take notes on the answers to the questions and save screenshots where indicated—have these ready when you ask for a signoff. When you are done, you will submit your code as well as your answers and screenshots online as usual. System Requirements 1. Start this lab by downloading the template on the course website and importing it into CCS—this lab has a slightly different template than previous labs to include the functionality for the DAC. Look over the example code to see how to use the DAC functions. 2. Your function generator will support at least four types of waveforms: DC (a constant voltage), a square wave, sawtooth wave, and a triangle wave, as described in the requirements below. You will select which type of waveform to generate using the 4 buttons on the lab board. At startup, your “welcome” screen should instruct the user which button corresponds to which waveform, eg. “Button 1 = DC, Button 2 = Square wave, etc.” 3. 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—you can use your implementation from lab 3 to do this. When the wheel is turned in one direction, the DAC output voltage should increase, and when the wheel is turned in the other direction the voltage should decrease. How does the MSP4921 LDAC pin work? (ie, what does it do?) Do you need to repeatedly send the code to the DAC to maintain the voltage, or do you only need to send the code once when it changes? You can view your DAC output by connecting the DAC output pin on your lab board to the oscilloscope. Unfortunately, the pin for the DAC output has not been populated on most lab boards, so you will need to hold the oscilloscope probe to the output pin to measure it. Take a screenshot of your DC output on the oscilloscope. Warning: CONNECT THE OSCILLOSCOPE CAREFULLY! First, connect the probe ground to one of the ground pins on the Launchpad—be sure to not short any other pins to ground while doing this, which is very easy to do. Once you have the ground connected, hold the probe to the DAC output pin to take a measurement. ECE2049: Lab 4 4. Jumper P7 selects the supply voltage for the DAC. The two options are 3.3V and 5V—if you are unsure which is which, you can test the pins using the oscilloscope or a multimeter. For this question, make sure your jumper is in the 3.3V position. If it is not, stop the debugger, unplug your lab board, move the jumper, and then reconnect your board. When jumper P7 is in the 3.3V position, what are the minimum and maximum ranges your DAC can actually generate? (In other words, what happens when you send the minimum and maximum code values?) Min: _______, Max: _______ 5. Stop the debugger, unplug your lab board, and move jumper P7 to the 5V position. Reconnect your board and measure the minimum and maximum DC voltages your DAC can actually generate when P7 is in the 5V position. Does it achieve the full range? Min: _______, Max: _______ 6. When button 2 is pressed, the function generator should generate a 200 Hz square wave. Again, the peak amplitude should be controlled by the scroll wheel---the minimum voltage should be 0V. Use Timer A2 to control the period of your waveform. Software delays are not acceptable. Take a screen shot of your square wave output on the oscilloscope. 7. When button 3 is pressed, the function generator should generate a 200 Hz sawtooth wave. In this case, the maximum amplitude should be as close to the current supply voltage (3.3V or 5V, depending on the jumper setting), or as close as you can achieve. Again, you should use Timer A2 to control the period of the waveform—software delays are not acceptable. Take a screenshot of your sawtooth wave output on the oscilloscope. Also, take a screenshot at a high zoom level so you can see the individual “steps” in the sawtooth! 8. When button 4 is pressed, your function generator should generate a 200 Hz triangle wave using the same parameters as for the sawtooth wave. Take a screenshot of your triangle wave output on the oscilloscope. 9. BONUS (10 pts): When you are done, use the oscilloscope to capture a SPI transmission and examine the data being sent. To do this, we will connect oscilloscope probes to the pins on the Launchpad board, which provide a convenient way to look at all of the signals on the lab board. Start by looking at the development board schematic and identify which pins on the Launchpad headers correspond to the CS, SCK (aka, SCLK), and SDI (aka, MOSI) for the DAC. Each Launchpad pin is shared with a Digital I/O pin—the Digital I/O pin name is used as the label on the Launchpad board. For example SCLK for the DAC is connected to P3.2/UCB0CLK1, so you should connect a probe to the Launchpad pin labeled P3.2. Note: If you are working in AK113, you can use the oscilloscope’s digital probes to examine all three signals at once. Please ask the course staff for help connecting the oscilloscope and using the digital probes. Once you have all of the probes connected, we can capture a SPI transmission. The best way to do this is to set the oscilloscope to trigger on the falling edge of CS, set the oscilloscope to “Normal” trigger 1 UCB0CLK refers to the CLK signal output from UCSCI module B0, which is one of the hardware peripherals on the MSP430 that performs SPI. ECE2049-E16 (Instructor: N. DeMarinis) Page 2 of 4 ECE2049: Lab 4 mode, and press “single” to acquire one screen’s worth of data after the trigger is reached. When you have the picture aligned correctly, take a screenshot of the data and identify the DAC code being sent. 10. BONUS (5 pts): Use the scroll wheel to control the frequency of your triangle wave. The output frequency should be in the range 100 Hz to 10 kHz. Again, you must use Timer A2 to control the period of the waveform, and the max amplitude should be the current supply voltage for the DAC. Take a screen shot of your triangle wave output on the oscilloscope at 3 different frequencies. 11. BONUS (10 pts): Implement a sine wave with an amplitude range between 0V and the current DAC supply voltage. The frequency of the sine wave should be controlled by the scroll wheel, with an output frequency range between 100 Hz and 10 kHz. Does the quality of your sine wave depend on the frequency? (Should it?) Explain how your implemented your sine wave. Is your sine wave approximation any good? Take two screenshots of your sine wave at ~500 Hz: one of a full period, and another at a high enough zoom level to see the individual steps. Good luck and have fun! ECE2049-E16 (Instructor: N. DeMarinis) Page 3 of 4 ECE2049: Lab 4 Submitting your Work When you are done with your report, you will submit it and your code on Canvas for grading. In order to receive a grade, you must submit both your code and your report online—even though you did not write much code for this lab, we will start the submission process now. Only one member of your team needs to submit files for your lab. In addition, you must turn in your signoff sheet to the course staff—usually, you will do this when receiving your last signoff. If not, you can turn it in by placing it in the box in the ECE office, or handing it to a member of the course staff. To submit your code for grading, you will need to create a zip file of your CCS project so that the course staff can build it. You can also use this method to create a complete backup copy of your project (perhaps to send to your partner or save for later). Unfortunately, the only reliable method for doing this is from inside CCS using the instructions below—do NOT attempt to just create a zip file of your code. To export your code: 1. Inside CCS, right click on your project and select "Rename..." 2. If you are submitting your project, enter a name in the following format: ece2049e16_lab4_username1_username2, where username1 and username2 are the user names of you and your partner.