Professional Documents
Culture Documents
Microprocessor Systems & Interfacing EEE-342: Comsats University
Microprocessor Systems & Interfacing EEE-342: Comsats University
Name
Registration Number
TOOLS:
SOFTWARE TOOLS:
Atmel Studio/AVR Studio
Arduino
Proteus ISIS
AVR DUDESS
HARDWARE TOOLS:
PRE-LAB
Analog to digital converters are the most widely used devices for data acquisition. Most of the
physical quantities are analog e.g. temperature, humidity, pressure, light, etc. Therefore, we need
an analog to digital converter to convert the data into digital data in order to communicate with
the digital processors like microcontrollers and microprocessors.
7. A single conversion is started by writing a '1' to the ADC Start Conversion bit in the ADC
Control and Status Register A (ADCSRA.ADSC). ADCS will stay high as long as the
conversion is in progress, and will be cleared by hardware when the conversion is completed. If a
different data channel is selected while a conversion is in progress, the ADC will finish the
current conversion before performing the channel change.
8. Auto Triggering is enabled by setting the ADC Auto Trigger Enable bit (ADCSRA.ADATE).
The trigger source is selected by setting the ADC Trigger Select bits in the ADC Control and
Status Register B (ADCSRB.ADTS).
7.3.1 ADC Conversion Result
After the conversion is complete (ADCSRA.ADIF is set), the conversion result can be found in
the ADC Result Registers (ADCL, ADCH). For single ended conversion, the result is:
Where VIN is the voltage on the selected input pin, and VREF the selected voltage reference
7.4 Modes of operation:
The ADC has two fundamental operation modes:
1. Single conversion mode
2. Free running mode
PRE-LAB TASK:
EXPLAIN THE WORKING OF FIVE ANALOG SENSORS. EXPLAIN WHAT
PHYSICAL QUANTITY DO THEY MEASURE AND PROVIDE THE MAPPING
FUNCTION FOR THE OUTPUT VOLTAGE.
ANALOG SENSORS:
There are different types of sensors that produce continuous analog output signal and these
sensors are considered as analog sensors. This continuous output signal produced by the analog
sensors is proportional to the measure-and.
ACCELEROMETERS:
Analog sensors that detect changes in position, velocity, orientation, shock, vibration, and tilt by
sensing motion are called as accelerometers. These analog accelerometers are again classified
into different types based on the variety of configurations and sensitivities.
These accelerometers are available as analog and digital sensors, based on the output signal.
Analog accelerometer produces a constant variable voltage based on the amount of acceleration
applied to the accelerometer.
LIGHT SENSORS:
Analog sensors that are used for detecting the amount of light striking the sensors are called as
light sensors. These analog light sensors are again classified into various types such as photo-
resistor, Cadmium Sulfide (CdS), and, photocell. Light dependent resistor (LDR) can be used
as analog light sensor which can be used to switch on and off loads automatically based on
the day light incident on the LDR. The resistance of the LDR increases with decrease in light and
decreases with increase in light.
SOUND SENSORS:
Analog sensors that are used to sense sound level are called as sound sensors. These analog
sound sensors translate the amplitude of the acoustic volume of the sound into an electrical
voltage for sensing sound level. This process requires some circuitry, and
utilizes microcontroller along with a microphone for creating an analog output signal.
PRESSURE SENSOR:
The analog sensors that are used to measure the amount of pressure applied to a sensor are called
as analog pressure sensors. Pressure sensor will produce an analog output signal that is
proportional to the amount of applied pressure. These pressure sensors are used for different
types of applications such as piezoelectric plates or piezoelectric sensors that are used for the
generation of electric charge. These piezoelectric sensors are one type of pressure sensors that
can produce an analog output voltage signal proportional to the pressure applied to the
piezoelectric sensor.
ANALOG TEMPERATURE SENSOR:
Temperature sensors are widely available as both digital and analog sensors. Typically used
analog temperature sensors are thermistors. There are different types of thermistors that are used
for different applications. Thermistor is a thermally sensitive resistor that is used for detecting
changes in temperature. If the temperature increases, then the electrical resistance
of thermistor increases. Similarly, if temperature decreases, then the resistance decreases. It is
used in various temperature sensor applications.
Practical example of analog temperature sensor is thermistor based temperature control system.
This project is used to maintain constant temperature in an enclosed area. A block diagram of
temperature control system consists of lamp (that represents a cooler), temperature sensor
or thermistor, relay.
If the temperature exceeds certain value, then the lamp switches on automatically indicating a
cooler for bringing back temperature to normal value. Operational along with a negative
temperature coefficient thermistor is used for activating relay-in case if the temperature exceeds
certain range. As this process of activating relay for switching on cooler (in this system shown as
lamp) can be done automatically, hence there is no need to monitor temperature in
person. Thermistor is most frequently used analog temperature sensor, because of its low cost
advantage. Whenever changes occur in temperature, then the input parameters to the op-amp will
be altered. Thus, op-amp delivers an output that energizes relay and the load turns on or off
accordingly.
If we use a digital temperature sensor instead of analog temperature sensor, then the accuracy of
temperature control system can be improved.
Where;
VOUT is the LM35 output voltage
T is the temperature in °C
IN-LAB TASKS:
TASK-1: USE LM35 TO SENSE THE ROOM TEMPERATURE. CONVERT THIS DATA INTO
DIGITAL USING ATMEGA328P ADC AND DISPLAY TEMPERATURE VALUE ON VIRTUAL
TERMINAL.
COMPLETE THE CODE AND SIMULATE ON PROTEUS.
CODE:
#include <stdlib.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <string.h>
#include <math.h>
/*********************************************************************
************/
#define ADC_#include <inttypes.h>
#define ADC_CHANNEL0 0
#define ADC_CHANNEL1 1
#define ADC_CHANNEL2 2
int main(void)
{
ADC_Initialize();
DIDR0=0xFF; //Disable digital I/O
DDRD = 0xFF;
UART0_init(MYUBRR);
printSerialStrln("Lab 8: ");
unsigned char temprature;
while(1)
{ printSerialStr("Temperature is ");
temprature = read_temp_sensor(TEMP_SENSOR_CHANNEL);
printSerialInt(temprature);
printSerialStr("\r \n");
PORTD = temprature;
_delay_us(1000000);
}
}
// Function Initializes the ADC for 10-Bit Single Conversion mode..
unsigned char ADC_Initialize()
{ //left adjust
ADMUX |=(1<<ADLAR);
// right adjust result. Vref = AVCC = 5V
/*** Write Code for this ***/
ADMUX|= (1<<REFS0); //Here select the prescaler for 16 MHz System Clock
ADCSRA |=(1<<ADPS1);
ADCSRA |=(1<<ADPS2); // Prescaler = 128
ADCSRA |=(1<<ADEN);// Clock for ADC = 125 KHz (should be between 50K to 200K)
return 0;
}
/* Function reads the result of a single conversion from the ADC
channel given as an argument*/
unsigned int ADC_Read(unsigned char channel)
{
unsigned char ADC_lo;
unsigned char ADC_hi;
unsigned int result;
ADMUX &= ~(0x07); // clear previous selction of channel
ADMUX |= channel; // Select the new channel
// Delay needed for the stabilization of the ADC input voltage
_delay_us(10);
//wait for ADC to finish any ongoing opeartion
while((ADCSRA & (1<<ADSC)) != 0);
ADCSRA |= (1 << ADSC); //start conversion
while((ADCSRA & (1<<ADIF)) == 0);
ADCSRA |= (1<<ADIF); // clear the flag by writing 1 to it
//result = (ADCH<<8)|(ADCL & 0xC0); // Left adjust result
ADC_lo = ADCL;
ADC_hi = ADCH;
result = (ADC_hi<<2)|(ADC_lo >> 6); // Right adjust result
return result;
}
return temp_celsius;
}
PROTUES SIMULATION
HARWARE IMPLEMENTATION
CODE:
#include <avr\io.h>
#include <avr\interrupt.h>
#include <avr\signal.h>
#include <util\delay.h>
void conversion(void);
int main(void) {
DDRC=0xFF;
ADMUX=0x60;
ADCSRA=0x83;
while(1) {
conversion();}}
void conversion()
{
ADCSRA|=1<<6;
_delay_ms(0.1);
PORTC=ADCH;
}
PROTUES SIMULTATION