Lab 3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

WANIA ANSARI EE-21090 SEC C

Lab 3
TASK #01:
To test Example 1 on ATmega328P and verify working of ADC using an external
D/A Converter
1. Create a new AVR project and build the code given in the Example 1. Test the obtained
digital output by varying the output from potentiometer. Observe the on / off status of
LEDs (used as indicators for digital output) and verify the digital voltage by calculation for 8-
bit ADC at given reference voltage.
Note that the ATmega328P has an ADC module but not a built-in DAC module so it cannot
provide an analog output through any of its pins.

CODE:
3. Measure the analog input given through the potentiometer and the analog output
reproduced by the DAC. Compare both and verify the ADC and DAC. This is shown in Figure 11
using the R-2R circuit

SCHEMATIC:

Vref = 5V
Output = 0b11010111 is equal to 215 in the decimal number system.
Mapping it to 5V in 8-bit ADC

 (output/2^8 -1) * Vref


 (204/2^8 -1) * 5 = 4.6V
WANIA ANSARI EE-21090 SEC C

 204 corresponds to 4.6V

Vref = 5V
Output = 0b11001100 is equal to 204 in the decimal number system.
Mapping it to 5V in 8-bit ADC

 (output/28 -1) * Vref


 (204/2 8 -1) * 5 = 4V
 204 corresponds to 4V
WANIA ANSARI EE-21090 SEC C

CALCULATION:
Vref = 5V
Output = 0b00011101 is equal to 29 in the decimal number system.
Mapping it to 5V in 8-bit ADC

 (output/2^8 -1) * Vref


 (3.6/2^8 -1) * 5 = 3.6V
 29 corresponds to 3.6V
2. Now, remove the LEDs and provide the 8-bit digital output to an external DAC circuit i.e.,
convert the digital output to analog for verification. You can use a simple R-2R circuit of Figure 8
or use DAC0808 IC. For DAC0808 IC, refer to its datasheet for more information. The pin
diagram and DAC circuit using this is shown in Figures 9 and 10.
CODE:
WANIA ANSARI EE-21090 SEC C

SCHEMATIC:

TASK 2: To control the status of an LED based on the value of input analog
voltage
Modify the previous task or, for example, to read the 10-bit ADC value of voltage across the
potentiometer instead of the 8-bit result. Map the obtained 10-bit result with voltage level using the
step size. Connect an LED to indicate the voltage level. Use some conditions to build the following logic
for controlling the LED status. - If the voltage is above 2.5V, the LED turns ON - If the voltage is below
2.5V, the LED red turns OFF.

When Voltage is greater than 2.5


WANIA ANSARI EE-21090 SEC C

When Voltage is less than 2.5


WANIA ANSARI EE-21090 SEC C

You might also like