You are on page 1of 11

INTRODUCTION

This Part of the Project is to get digital values for Temperature from an analog source. By using AT-MEGA32 controller with potentiometer and other components. The circuit is designed to accomplish the above mentioned task. Software like AVR Studio 4 is used to program the micro controller using C programming. The Advantage of building this Device is that we can get a digital output from analog variable source for example a rheostat or potentiometer. This Project can help learn basic and complicated C Programming commands. It also helps understand how signals are been send and received in micro-controller.

Page 1

COMPONENTS NEEDED
Item
40 Pin DIL IC Socket

Quantity
1

Image

20 Pin DIL IC Socket

DIL LED Bar graph

32 Way SIL IC Socket Strip

7805 Voltage Regulator

Banana Plugs (One Red, One Black)

180 ohm Carbon Film Resistor Watt 220k ohm watt 0.22uF Monolithic Capacitor

2 packs of 8 each

1 2

0.1uF Monolithic Capacitor

SPST Momentary -Miniature

Tantalum 1 uF 25V Capacitor

IDC Vertical 10 pin Header

1 (10 way 2 rows of 5 pins)

Page 2

IDC Vertical 16 pin Header

1 (16 way 2 rows of 8 pins)

PCB Vero 152 mm

* Untapped Nylon PCB Spacers 12mm

1 (Pack of 5)

* Self tapping screws to suit Nylon spacers above

1 (Pack of 25)

Watch crystal (32KHz)

Potentiometer (5 ohm 15 watt)

ATmega32 Micro-controller

Page 3

TECHNICAL DIAGRAM
Step 1
y Use PCB Vero 152 mm board to solder all the components shown in Fig 1 below.

An additional modification has to be done to the circuit diagram above:


20 Pin DIL IC Socket has to be connected beside ATmega32 chip. 180 ohm Carbon Film Resistor is connected from pin 33 to 40 in ATmega32 micro controller and Pin 8 to 1 in DIL socket consequently. Once solder all device has completed, potentiometer can be soldered .

Step 2
y In Figure 2 it shows connection between Atmega32 and potentiometer, which has to be soldered to thePCB Vero board below microcontroller where potentiometer will be connected.

Page 4

Figure 2 y y y Pin 1 is power supply for potentiometer. Pin 2 is an information pin in potentiometer which is connected to 40th pin of AT-Mega 32. Pin 3 is to connected with ground

REAL TIME DIAGRAM


Phase 1
After soldering components to the Board It should look like this:
Page 5

Phase 2
After Programming the micro-controller and by providing 9v power the following shows the running of hardware

Page 6

Phase 3

Page 7

The last image shows the whole connection associated with the project

Pin Descriptions VCC Digital---------------------------- supply voltage. GND-------------------------------------Ground. Port A (PA7..PA0)--------------------Port A serves as the analog inputs to the A/D Converter. Port A also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pinscan provide internal pull-up resistors (selected for each bit). The Port A output buffers have symmetrical drive characteristics with both high sink and source capability. When pins PA0 to PA7are used as inputs and are externally pulled low, they will source current if the internal pull-upresistors are activated. The Port A pins are tri-stated when a reset condition becomes active,even if the clock is not running.

Port B (PB7..PB0)---------------------Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). ThePort B output buffers have symmetrical drive characteristics with both high sink and sourcecapability. As inputs, Port B pins that are externally pulled low will source current if the pull-upresistors are activated. The Port B pins are tri-stated when a reset condition becomes active,even if the clock is not running. Port C (PC7..PC0)--------------------Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). ThePort C output buffers have symmetrical drive characteristics with both Page 8

high sink and sourcecapability. As inputs, Port C pins that are externally pulled low will source current if the pull-upresistors are activated. The Port C pins are tri-stated when a reset condition becomes active,even if the clock is not running. If the JTAG interface is enabled, the pull-up resistors on pinsPC5(TDI), PC3(TMS) and PC2(TCK) will be activated even if a reset occurs.The TD0 pin is tristated unless TAP states that shift out data are entered. Port D (PD7..PD0) ---------------------Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). ThePort D output buffers have symmetrical drive characteristics with both high sink and sourcecapability. As inputs, Port D pins that are externally pulled low will source current if the pull-upresistors are activated. The Port D pins are tri-stated when a reset condition becomes active,even if the clock is not running. RESET------------------------------------Reset Input. A low level on this pin for longer than the minimum pulse length will generate areset, even if the clock is not running. Shorter pulses are not guaranteed to generate a reset. XTAL1-----------------------------------Input to the inverting Oscillator amplifier and input to the internal clock operating circuit. XTAL2----------------------------------Output from the inverting Oscillator amplifier. AVCC-----------------------------------AVCC is the supply voltage pin for Port A and the A/D Converter. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCCthrough a low-pass filter. AREF----------------------------------AREF is the analog reference pin for the A/D Converter.

CODEING
The following is the code for the Analogue to Digital converter It is to read the "temperature" which is substituted with the potentiometer Using ADC on an Atmega32 Features 1. Adjustable 8-bit/10-bit resolution. 2. Multiplexed with pins of port A. 3. 8 multiplexed single channels, 7 multiplexed differential channels including 2 with optional gain. 4. Auto-triggering mode 5. Sleep mode for noise canceling 6. Separate power supply at AVCCRelevant registers 1. ADMUX ADC mux. selection register. Selection of Vref , ADC channel (single channel or differential, channel gain), Left adjust result 2. ADCSRA ADC control and status register. ADC enable, start conversion, Page 9

Auto-trigger enable, interrupt flag, interrupt enable, prescaler bits 3. ADCL, ADCH ADC low and high registers 4. SFIOR Special function IO register; select auto-trigger source.Steps for configuring ADC 1. Select V ref Select AVCC, AREF or internal 2.56V reference (see precautions) 2. Set ADC frequency Set the appropriate scaling factor in ADCSRA. The ADC frequency is (clock frequency)/(scaling factor). 3. Select input channel Channel single/differential can be selected in ADCSRA 4. Trigger If auto trigger is desired, select in ADCSRA, and configure the trigger source in SFIOR 5. Interrupt If an interrupt is desired on completion of conversion, enable global interrupts and adc interrupt. However, ADC interrupt flag is always set upon completion of conversion. 6. 8/10 bit If 8 bit resolution is desired, set ADLAR bit in ADMUX. 2 LSBs are discarded and the 8 MSBs are shifted to ADCH. 7. Enable ADC Set ADEN bit in ADCSRA 8. Start conversion Set ADSC bit in ADCSRA.Precautions 1. If using AVCC or internal 2.56V reference, do not connect any other source at AREF. This pin is directly connected to AVCC when AVCC is enabled. 2. Do not connect anything at AREF that draws current from AREF. Only connect a capacitor (recommended) or a high-impedance element at AREF. 3. Discard the first reading, especially if input is differential. 4. If left-adjustment is not done i.e. in 10-bit mode, read ADCL first, then ADCH.#include <avr/interrupt.h>

MAIN PROGRAM
#include <avr/io.h> #include <avr/iom16.h> #include <stdlib.h> #include <stdio.h> #define A_DEN 0x80 #define A_DSC 0X40 #define A_DIF 0x10 #define A_DIE 0x08 #define A_DPS 0x06 ADCSRA register #define S_REG 0x80 //ADC Enable, in ADCSRA register //ADC Start Conversion, in ADCSRA register //ADC Interrupt Flag, in ADCSRA register //ADC Interrupt Enable, in ADCSRA register //Scaling Factor = 64 between XTAL frequency and ADC input frequency, in //Global interrupt enable, in SREG register Page 10

#define A_REF 0x00 #define A_LAR 0x20 int main(void){ sei(); SREG |= S_REG; ADMUX |= A_REF;

//Select Aref as the reference voltage input, in ADMUX register //ADC left adjust result, gives 8 MSB in ADCH, in ADMUX register

//to select channel, do an OR operation on ADMUX with 0x00 to 0x03

//Global Interrupt enable //set voltage source for ADC

DDRC = 0xFF; //Configure Port C pins as output ADCSRA |= A_DPS; //set ADC frequency ADCSRA |= A_DEN; //ADC enable ADCSRA |= A_DIE; ADMUX |= A_LAR; ADMUX |= 00; while(1){ { { ISR(ADC_vect){ PORTC = ADCH; SREG |= S_REG; ADCSRA |= A_DIE; { //Read ADC value and write it to Port C //Re-enable interrupts //ADC interrupt enable //ADC interrupt enable //left adjust result //Selec ADC0 as input

ADCSRA |= A_DSC; //Start conversion

ADCSRA |= A_DSC; //Start conversion

Page 11

You might also like