D/A & A/D Convertors
Make sure you read the lab rules about keeping the lab clean. In particular, put away all components, wires and connectors when you are done. If you need to leave a circuit set up on a breadboard, put the breadboard in one of the cabinets or drawers when you leave.
D/A and A/D convertors
In this lab you will be working with Digital to Analog (D/A - read as "D to A") and Analog to Digital (A/D - "A to D") convertors.
D/A convertors are used to generate an analog voltage from a number stored in the microcontroller. For example a three bit convertor with a range of 0-3.3 volts would have the following outputs. Note that the highest output is actually 3.3V*(2N-1)/2N (where N is the number of bits, 3 in this case). A binary value of 110 (decimal=6) would result in 2.475 Volts.
|
Input |
D/A Output | |
Decimal |
Binary |
|
0 |
000 |
0 V |
1 |
001 |
0.4125 V |
2 |
010 |
0.8250 V |
3 |
011 |
1.2375 V |
4 |
100 |
1.6500 V |
5 |
101 |
2.0625 V |
6 |
110 |
2.4750 V |
7 |
111 |
2.8875 V |
An A/D convertor performs the opposite operation, it takes an analog voltage and converts it to a binary equivalent. A voltage between 2.475 and 2.8875 volts will result in an output of 110 (decimal=6).
A/D Input |
Output |
|
Decimal |
Binary |
|
<0.4125 V |
0 |
000 |
0.4125-0.8250V |
1 |
001 |
0.8250-1.2375V |
2 |
010 |
1.2375-1.650V |
3 |
011 |
1.650V-2.0625V |
4 |
100 |
2.0625-2.4750V |
5 |
101 |
2.4750-2.8875V |
6 |
110 |
>2.8875V |
7 |
111 |
For this part of the lab, use your daughterboard on a breadboard. With Vcc and ground applied.
The first task this week is to build a simple D/A convertor and evaluate its performance. Connect the circuit shown with R=10kΩ. Keep the resistors separate from the op-amp because we will be swapping in a different op-amp later. Wire neatly (make the breadboard look like the schematic and things should go quickly.
Use a TLV2772 opamp powered from 0 and 5 volts. The pinout is given below. Write a program that sets P3.1, P3.2 and P3.3 as outputs. Create a variable "i" that increments in a loop at about a 100 Hz rate. In the loop use the statement "P3OUT = i;". This will increment the output of the D/A converter (note: only 3 bits of "i" are important to the circuit, so there is no need to limit the range of "i").
Predict and measure the output voltages as i varies. Note: you can pause the program, go to View→Locals, and change the value of i directly (or go to View→Registers, and change P3OUT manually).
Get a screen shot of the output as the program runs clearly showing the discrete analog voltage levels.
Replace the TLV2772 with an LF411 op amp, but keep power at +5V and ground (you'll have to rewire because they have different printouts), and redo the screen shot (note: it won't be nearly as good).
![]()
Download the following code (E72Lab5Template.c); don't worry at all about the function "init_1232_e72". Also, I have used some C syntax we did not cover in class; let me know if any of the code is not clear. Compile and run the code.
The code takes the input from the potentiometer on your microcontroller board which is connected to pin 2.0 and converts it with a 10 bit A/D converter. You can vary the voltage by turning the pot and use a voltmeter to measure the voltage on the appropriate pin. You can check the value of the conversion using by stopping the program and examining the value of the variables. Take several measurements (at least 10) as the voltage is varied and fill in a table like the one below:
Measured Voltage Expected A/D Value Measured A/D Value *IMPORTANT* Make sure you don't apply more than 3.3 volts to any input on the microcontroller, this can destroy the chip.
Another way to make a D/A convertor is more complicated conceptually, but only takes one pin on the output. It is based on a technique called pulse width modulation or PWM. Three pulse width modulated signals are shown below. It also has some significant advantages in terms of efficieny in high power circuits and is commonly used in those applications.
The top signal shows an output of 0.5, because the input is high 50% of the time. The middle one shows an output of 0.1, and the bottom one is 0.9. An output of 0.0 would be always low, 1.0 would be always high. Note that the frequency doesn't change, and that the amplitude is unimportant; only the duty cycle matters.
The MSP430, fortunately, is set up to do this kind of modulation. Run the code. You can pause it and change the values of pwm1val and pwm2val (from 0 to 16). Measure the PWM outputs on pins P1.2 and P1.3 and verify that it behaves as expected.
Connect pin P1.2 to the circuit shown below with R=3.3kΩ and C=0.1μF. Measure the duty cycle (the oscilloscopes in 310 will measure duty cycle automatically) and the output voltage across the capacitor at enough points to verify that the output is approximately equal to the average value of the input. Since the input is either 0 or 3.3 volts, a 50% duty cycle should give 1.65 volts, a 10% duty cycle should give 0.33 volts. Make sure you understand how this works. Get a screen shot of the input and output with a 50% duty cycle. Measure, as accurately as you can, the magnitude of the ripple.
Modify the code to alternately vary the duty cycle to produce a signal that goes between a duty cycle of 25% and a duty cycle of 75% roughly 100 times per second and measure the input and the output voltage. Get a screen shot, and make sure you can explain it.
Calculate a resistor value that gives an error of only 1 part in 128 when the duty cycle is 50%. Get a screen shot of the input and the output with a 50% duty cycle.
Set the scope channel on Vout to AC coupling and increase the scale until you can see the variations in Vout. Record the measurement and get a screen shot. This is the main reason that AC coupling is useful - observing small fluctuations on a large DC signal.
Switch back to DC coupling and repeat the PWM dynamics with the frequency at which the duty cycle is changed is reduced enough that the circuit comes to (approximated) equilibrium between changes.
Write a program that increases the duty cycle on PWM1 from 0 to 100% as you rotate the potentiometer, and decreases the duty cycle on PWM2 from 100 to 0%. Now put your LED board from lab 1 on the breadboard.

Attach pin 1 (square pad) to +5V, attach pin 2 to PWM2 and pin 4 to PWM1 (note, because of the diode drops, the voltage at the MPSP430 is low enough to avoid damage - but be careful, because if you accidently attach 5V you will probably destroy the microcontroller).
Part 1) Simple D/A converter
Part 2) A/D
Part 3) PWM
| ← |
Comments or Questions? |
![]() |