Lab 10: ADC, DAC Experiments

This lab has you explore the on-chip ADC, a SPI DAC, and a temperature sensor.

Prelab (20)

Use a long wire or a jumper (if you have one) to connect the potentiometer wiper to AN0, since you'll have to remove and replace this connection several times during the lab.

3. The pins of the LM60 are shown below. Connect VDD to 3.3V and GND to ground. If you reverse VDD and GND, the LM60 will get very warm because it is drawing too much current and you may damage it. Don't connect the middle pin, VOUT, to anything yet. Just insert it into a free row of your breadboard.

4. Open the chap11/adc_spidac_test project and save adc_spidac_test.c as my_adc_spidac_test.c. Exclude the original C file from the project and add yours. Build the project and upload to your PIC. When you run it, you should see something like this in BullyCPP:

"ADC in" voltage will depend on the potentiometer setting.

5. Turn your potentiometer as far as it will go in both directions. At one extreme you should see 0 V for "ADC In". At the other you should see about 3.3 V.

6. Unhook the wire connecting to the potentiometer wiper. (Leave the other end connected to AN0.) Connect this to VOUT of the LM60. BullyCPP should still be showing an image similar to the above screenshot, with an ADC In of something like 0.578 V.

Prelab Checkoff

Task 1 - ADC to DAC Test (20)

Connect AN0 to the potentiometer. The adc_spidac_test project reads a 12-bit value from the PIC ADC input, whose voltage is set by the potentiometer, converts this to an 8-bit value by dropping the last four bits, then writes this to the MAX548A DAC using the SPI port. This means that the DAC output voltage follows the potentiometer voltage (POTV) as you adjust the potentiometer. Make a table like the following: 

Take measurements to fill in the table. If you like, you can use the meter on VirtualBench so you don't have to move your multimeter probes back and forth. If the values in Bully oscillate too quickly to read even when you're not fiddling with the pot, you have two options:

A. Connect a 0.1 or 1uF cap between AN0 and ground.

B. Take your voltage readings with your meters (which shouldn't change as much), turn off your board, read the line of Bully output, then turn your board back on.

TA Checkoff

You've filled out a table with your measurements and calculated your percent error.

Explanation

If you are confused by what you just measured, or would like help on Task 2, consult the FAQ.

Task 2 – LM60 Temperature Sensor (40)

The LM60 output increases by 6.25 mV for every degree Celsius increase in temperature, with a DC offset of 424 mV. Therefore, 25 C produces a voltage of (6.25 mV/C * 25 C) + 424 mV = 580.25 mV. 

To convert Celsius to Fahrenheit, multiply degrees Celsius by 9/5 then add 32. 

Modify my_adc_spidac_test.c to print temperature in degrees Fahrenheit (with two digits to the right of the decimal point) between ADC In and DAC Out. The output should look like this:

Hints:

Once you have done this, record the temperature of the LM60. Now squeeze it between your fingers for a minute or so and try to get it up to about 90 F. Record the highest temperature you get.

Round the low temperature down to the nearest integer and subtract 2. Round the high temperature up to the nearest integer and add 2. Record these new values. Find the range between them by subtracting.

Our goal is to map the temperature values to DAC output voltages such that the midpoint temperature is represented as ½ VREF, or 1.65 V if VREF = 3.3 V. This way, we will get a wider voltage swing for this limited temperature range and our PIC will act like a digital amplifier.

Now, modify your program to map the temperature that you calculate as a percentage of this range:

Percentage = (measured temp – new low temp) / range

Note that if the input temperature is the midpoint, this calculates as 0.5.

Convert this to a voltage between 0 and 3.3 V, using the formula:

(Desired DAC Voltage) = 3.3 V * percentage.

Multiply by 256 (2^8), to get the 8-bit hex code to write to the DAC so that it outputs the desired DAC voltage. 

Modify the print statement in your loop to print the desired DAC voltage and its hex code, as shown below:

Use a voltmeter on the DAC output to check that your onscreen value for DAC output approximately matches what is on the meter. Capture a screenshot of your Bully output, showing a range of values, including your midpoint temperature.

Distance students only: Take a photo showing your meter measuring DAC output next to your BullyCPP output. The DAC output in Bully should approximately match what is being shown on the meter.

TA Checkoff

When you force the temperature sensor to approximately the midpoint temperature, the DAC output voltage is at the midpoint voltage (about 1.65 V) – have a voltmeter hooked up for the demo. 

Congratulations, you have completed the last lab. You won't need your breadboard anymore*: Display it proudly on the wall of your apartment, give it as a gift to someone you are trying to impress, or bring it to your next job interview. 

Report

Verify manually that the ADC and DAC codes in the 1.6 V table row equal approximately 1.6V, using your measured VDD as the reference voltage. For example, I got 0x07c2 for ADC In. Is that supposed to be ~1.6 V? Or am I way off? Do the same for "To Dac". Show your calculations. See Lab 6 for adequate calculations. You do not need to show how you convert hexadecimal numbers into decimal.

Grading

If you do not successfully complete a task and your report fails to mention or glosses over this fact, you will receive a zero for the report portion of your grade as well as for the task. If you attempt to deceive the grader, e.g. by including screenshots not generated by the code you submitted, your instructor will be notified and you will be recommended for an Honor Code violation.

The report is worth 20 points for neatly and coherently presenting your information to a reader. The following non-exhaustive list of errors will result in losing credit from the report portion of the lab grade:

The tasks are worth 60 points. If your report indicates that you did not successfully complete or do not understand a task, you will lose credit, even if you performed it during the lab. The same is true for tasks performed during the prelab. There are two tasks. The first task is worth 20 points. The second task is worth 40 points. The following non-exhaustive list of errors will result in losing credit from a task:

Lab reports that flagrantly violate submission policy (wrong lab, no screenshots, no title page, no text besides headings/labels, mostly blank, code pasted into pdf, paragraphs of lab text pasted in, extremely sloppy/unprofessional, missing code etc.) will not be accepted. The student will receive a zero for the lab and may resubmit with late penalty.

* Unless you have a grade of D or lower and/or are planning on becoming a TA. In that case: click here