Escolar Documentos
Profissional Documentos
Cultura Documentos
INTRODUCTION:
These require less time to process, further more the processor understands
only digital information.
The digital quantity obtained upon conversion consists of discrete levels as shown
ATmega16:
16 Kb flash memory
1 Kb SRAM
Up to 16MHz operation
Operating Voltage:4.55.5V
HARDWARE OVERVIEW:
ADC in ATmega16:
MODES:
REGISTER OVERVIEW:
1.
2.
3.
4.
1.
ADMUX:
Selects the input channels,
As there are 8-channels, it as possible to store it in a 3 registers.
It also stores the reference value.
BIT7
BIT6
BIT5
BIT4
BIT3
BIT2
BIT1
BIT0
REFS1
REFS0 ADLAR MUX4
MUX3
MUX2
MUX1
MUX0
MUX3, MUX2, MUX0: Allow you to select the channel when the following set of values
are given
MUX2
0
0
0
0
1
1
1
1
MUX1
0
0
1
1
0
0
1
1
MUX0
0
1
0
1
0
1
0
1
CHANNEL
ADC0
ADC1
ADC2
ADC3
ADC4
ADC5
ADC6
ADC7
If these bits are changed during a conversion, there is no effect till the conversion is
complete.
REFS0
0
1
1
1
0
1
Vref
Aref, Internal reference off
AVcc with external capacitor at
Aref
Reserved
Internal 2.56V with capacitor at
Aref
If ADLAR = 0,
The 10-bit converted value is stored as
15
ADC7
7
14
13
ADC6
6
ADC5
5
12
ADC4
4
11
ADC3
3
If ADLAR = 1,
The 10-bit converted value is stored as
15
ADC9
ADC1
7
14
ADC8
ADC0
6
13
ADC7
5
12
ADC6
4
11
ADC5
3
10
ADC2
2
9
ADC9
ADC1
1
8
ADC8
ADC0
0
10
ADC4
9
ADC3
8
ADC2
ADCSRA:
Stores the control and status bits of the ADC.
BIT7
ADEN
BIT6
ADSC
BIT5
ADFR
BIT4
ADIF
BIT3
ADIE
BIT2
ADPS2
BIT1
ADPS1
BIT0
ADPS0
ADPS2
ADPS1
ADPS0
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Division
Factor
2
2
4
8
16
32
64
128
ADPS1
ADPS0
Division
Factor
8
ADCL, ADCH:
Set the ADC clock Frequency (50 KHz< f <200 KHz) by adjusting the
Prescaler (ADPS2, ADPS1, ADPS0 in ADCSRA register).
PROGRAMMING:
For Standard programming we choose AVR Studio 4
Getting started in C programming,
Start AVR Studio 4,
You get the interface, Type your program in the text editor in center of window.
Include the header file avr/io.h; else your compiler will throw errors!!!
You can find the .hex file; this is to be downloaded into your Microcontroller
For this demo program, let us display the ADC input value at PORTC, PORTB, the output
would be in a 10-bit binary fashion,
so defining PORTC as ADCL output (Lower 8 Bytes)
Starting an infinite loop because we want to observe the output until the microcontroller is
given power, if no loop is defined then the ADC would be running but PORTC, PORTB
will not get updated i.e. the PORTC, PORTB will never change the value
Wait for the conversion to complete, when the conversion is complete ADIF flag would be
set to one
Press F7 to build the program, if errors are present they will be shown in the results.
Warnings can be neglected.
Check for the program size.
Your program is now compiled and stored in .hex format which is ready to be burnt in
your microcontroller.
Now go to the folder where you saved your project
Open the folder and you can see your .c file of your project
You can now see your .hex file and its size also
Your programming is now complete, but how do you know whether your program is
correct or not???
You will have to simulate the program
You have two ways
AVR Simulator: you can get the register simulation, without the
hardware connected.
Proteus ISIS: you can get the graphical simulation i.e. you can
connect external hardware to it but you cannot know the internal registers status
Therefore we will use both and let us first use AVR simulator
Open the AVR Studio4 and open your project and notice this button in the I/O on the right
of your screen
Press F11 to execute the next line and observe the I/O view and repeat the process of
pressing F11 till your program is complete and notice the registers.
In this case
ADMUX = 01000010 is being displayed
The dark ones represent 1, and the blank ones represent 0
If satisfied continue to simulation in AVR Simulator or else check your program
Important tools:
Component mode: selecting this allows you to place the required components
Voltage Sources: this allows you to select Vcc, Gnd, BiDirectional bus, etc
Graph mode: This allows you to plot graphical visualization of the data simulated
Meter mode: This allows you to select oscilloscope, Virtual terminal, ammeter
(AC/DC), Voltmeter (AC/DC)
For placing the components Press the Component mode and press
You will get a window like this,
You will get a list of possible components; choose your required one, now choosing a
standard resistor
Press ok and you will get the home screen of Proteus now right click on the screen to
place the component
Now lets choose a push to on switch, for making the led on or off
Press P and enter SPST Push Button
The symbol
stands for standard +5V supply
Now choose GROUND
And place it on the home screen, and join the circuit by pressing the component, you will
notice a red box (or) red circle right click on it and move your mouse till the next
component and the wire will be joined
ATmega16 microcontroller
8-leds
8 1K resistors
Vcc
Gnd
So enter these components in the search box by pressing P and place it on the home screen