[go: up one dir, main page]

0% found this document useful (0 votes)
48 views8 pages

Lab 09 - MES

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 8

MT-359L Microcontroller and Embedded Systems

MT-359L Microcontroller and Embedded System

Lab Manual 09

Muhammad Sarmad Baig


Name Shahzaib Khalil
Abdur Rab
Ayesha Siddiqua
201133
Registration Number 201097
201106
201088
Class BEMTS-F20-VA

Instructor’s Name Engr. Iraj Kainat

Session Fall 22

Air University, Islamabad Page 1


Lab # 09
Introduction and implementation of ADC and digital thermometer LM35
temperature sensor of ATMEGA 2560

Objectives:
 Understand the function of ADC in microcontroller.
 Learn different mode of operation of ADC
 Integration of LM35 temperature sensor with Atmega2560.

Equipment/Software Used:
 AVR Studio
 Proteus ISIS
 Microcontroller
 Breadboard
 LCD 16 x 2
 Capacitors
 Variable resistor
 Resistor

Introduction:
Analogue to Digital Converter
ADC is a system that converts an analog signal into a digital signal. In almost all digital systems there is a
frequent need to convert analog signals generated by analog devices such as microphone, sensors and
potentiometers into digital values that can be stored and processed by digital system. The ADC system of
Atmega16 has following features:
 10-bit ADC
 ±2 LSB absolute accuracy
 13 ADC clock cycle conversion rate
 8 multiplexed single-ended input channels
 selectable right or left result justification
 0 to Vcc ADC input voltage range

Registers involved in ADC


16K bytes of In-System Programmable Flash Program memory with Read-While-Write capabilities.

Bit 7:6 – REFS1:0: Reference Selection Bits


These bits select the voltage reference for the ADC, as shown in Table

Bit 5 – ADLAR: ADC Left Adjust Result


The ADLAR bit affects the presentation of the ADC conversion result in the ADC
Data
Register. Write one to ADLAR to left adjust the result. Otherwise, the result is right
adjusted.
Bits 4:0 – MUX4:0: Analog Channel Selection Bits
The value of these bits selects which analog input is connected to the ADC. The table
below show these bit settings for selecting various channels:

Bit 7 – ADEN: ADC Enable


Writing this bit to one enables the ADC. By writing it to zero, the ADC is turned off.
Bit 6 – ADSC: ADC Start Conversion
In Single Conversion mode, write this bit to one to start each conversion. ADSC will
read as one if a conversion is in progress. When the conversion is complete, it returns
to zero.
Bit 5 – ADATE: ADC Auto Trigger Enable
When this bit is written to one, Auto Triggering of the ADC is enabled.
Bit 4 – ADIF: ADC Interrupt Flag
This bit is set when an ADC conversion completes, and the Data Registers are updated. The
ADC Conversion Complete Interrupt is executed if the ADIE bit and the I-bit in SREG are
set. ADIF is cleared by hardware when executing the corresponding interrupt handling
vector.
Bit 3 – ADIE: ADC Interrupt Enable
When this bit IS one and I-bit in SREG is set, ADC Conversion Complete Interrupt
activated.
Bits 2:0 – ADPS2:0: ADC Prescaler Select Bits
These bits determine the division factor between the XTAL frequency and the input
clock to the ADC.

The ADC Data Register –ADCL and ADCH


These two registers contain 10 bits of the conversion result. The result is
stored in two different ways depending on the setting of ADLAR bit as shown
below:

ADLAR=0:

ADLAR=1

Lab Task 01:


Design a digital thermometer using LM35 Temperature sensor and display output on LCD.

Code (Assembly):
#ifndef F_CPU
#define F_CPU 16000000UL // 16 MHz CPU CLOCK SPEED
#endif
#define D0 eS_PORTD0
#define D1 eS_PORTD1
#define D2 eS_PORTD2
#define D3 eS_PORTD3
#define D4 eS_PORTC0
#define D5 eS_PORTC1
#define D6 eS_PORTC2
#define D7 eS_PORTC3
#define RS eS_PORTC6
#define EN eS_PORTC7
#include <avr/io.h>
#include<util/delay.h> #include
"lcd.h" int main (void)
{
unsigned char temp[10];
DDRF = 0x00;
DDRD = 0xFF;
DDRC = 0xFF;
ADCSRA = 0x87;//ADC enable and select ck/128 ADMUX =
0xC0;// Vref, ADC0, right-justified while (1){
ADCSRA |= (1<<ADSC);//start conversion
while((ADCSRA&(1<<ADIF))==0); //wait for end of conversion ADCSRA |=
(1<<ADIF); //clear the ADIF flag
unsigned int x= (ADCL|(ADCH<<8))/4;//x = adc value/4
Lcd8_Init();
itoa(x,temp,10); Lcd8_Set_Cursor(1,0);
Lcd8_Write_String("Temperature: ");
Lcd8_Write_String(temp);
_delay_ms(50);
}
}

Procedure:
 Open proteus on your computer and place down Arduino Mega 2560, one LCD display, variable
resistor and a ground as shown in the picture.
 Copy the hex file from Atmel Software and paste the hex file in the Arduino Mega configuration in
Proteus.

Output (Proteus Simulation):

Figure 1: Proteus Simulation

Output (Hardware Simulation):


Figure 2: Hardware Implementation

Lab Task 02
To check the ADC value by using a Potentiometer show the ADC value on LCD.

Code (Assembly):
#ifndef F_CPU
#define F_CPU 16000000UL // 16 MHz clock speed
#endif
#define D0 eS_PORTD0
#define D1 eS_PORTD1
#define D2 eS_PORTD2
#define D3 eS_PORTD3
#define D4 eS_PORTC0
#define D5 eS_PORTC1
#define D6 eS_PORTC2
#define D7 eS_PORTC3
#define RS eS_PORTC6
#define EN eS_PORTC7
#include <avr/io.h>
#include
<util/delay.h>
#include "lcd.h"
int main (void)
{
unsigned char temp[10];
DDRF = 0x00;
DDRD = 0xFF;
DDRC = 0xFF;
ADCSRA = 0x87;//make ADC enable and select ck/128
ADMUX = 0xC0;// Vref, ADC0, right-justified
while (1)
{
ADCSRA |= (1<<ADSC);//start conversion
while((ADCSRA&(1<<ADIF))==0); //wait for end of conversion
ADCSRA |= (1<<ADIF); //clear the ADIF flag
unsigned int x= (ADCL|(ADCH<<8));//x = adc value/4
Lcd8_Init();
itoa(x,temp,10);
Lcd8_Set_Cursor(1,0);
Lcd8_Write_String("ADC VALUE: ");
Lcd8_Write_String(temp);
_delay_ms(50);
} }

Procedure:

 Open proteus on your computer and place down Arduino Mega 2560, one LCD display, keypad,
resistor pack and a ground as shown in the picture.

 Copy the hex file from Atmel Software and paste the hex file in the Arduino Mega configuration in
Proteus.
Output (Hardware Simulation):

CONCLUSION
In this lab was based on analogue to detail converter. in this lab we perform two tasks one of which was the
resistance measurement in which we differentiated the resistance of a potential meter and displayed the
respective value after processing through the ADC onto the LCD screen and a second task was performed
using LM35 virtual temperature sensor and in this lobby measure different temperature based on the input from
the LM35 and then converted it into a particular DC value and display their respective temperature on the LCD
screen.

You might also like