Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help me with a to d converter of atmega 16

Status
Not open for further replies.

sarabgt

Newbie level 4
Joined
Apr 7, 2012
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,312
i am trying to convert voice signal into digital signal by adc of atmega16 and i am confused with its code i am interfacing microphone with atmega16..pls help me out.
 

can you post your code and explain what is your confusion exactly
 

can you post your code and explain what is your confusion exactly[/QUOTE
i am confused with set of adc registers..which one to initialize first and how..??
i am not able to start the conversion and then store it to a memory adderess using c..
cn u pls help me..??
 

ok for that you should read atmega 16 datasheet and for your help i am posting basic adc initialization code

there are two main register ADMUX and ADCSRA (adc status register)
Code:
//Program for ADC to read from channel 0 and show the 8 bit o/p on PORTB
 
#include<avr/io.h>
#include<util/delay.h>
 
void ADC_init(void);
unsigned int ADC_read(unsigned char);
 
// ------------------------------------------------
int main(void)
{
unsigned int value;
DDRB=0xFF;
DDRD=0x03;
ADC_init(); // Initialization of ADC
// ch=0;
while(1)
{
value=ADC_read(0);
PORTB=value;
_delay_ms(500);
} 
}
//------------------------------------------------
 
void ADC_init(void) // Initialization of ADC
{
ADMUX=(1<<REFS0); // AVcc with external capacitor at AREF
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
// Enable ADC and set Prescaler division factor as 128
}
 
unsigned int ADC_read(unsigned char ch)
{
ch= ch & 0b00000111; // channel must be b/w 0 to 7
ADMUX |= ch; // selecting channel
 
ADCSRA|=(1<<ADSC); // start conversion
while(!(ADCSRA & (1<<ADIF))); // waiting for ADIF, conversion complete
ADCSRA|=(1<<ADIF); // clearing of ADIF, it is done by writing 1 to it
 
return (ADC);
}

in above code adc data is stored to protb of atmega you can use this function in your code and change your adc channel selection as your hardware.
 

thanks a million..your program helped me a lot....one more help please..can u please tell me c code for storing data on a memory address..i want to store the converted result on a memory address
 

sarabgt said:
can u please tell me c code for storing data on a memory address..i want to store the converted result on a memory address
To answer this question, someone has to know which memory are you talking about (RAM, EEPROM). Then the programming language (assembly, C).
For EEPROM access, there is an example in datasheet for write (page 22) and read (page 23) in both assembly and C.
If it is about RAM, then in C you just declare a variable and store the ADC value there, no need to know the address.
In assembly you should store this value in a specific address of your choice, please refer to datasheet's instruction summary, page 336.

http://www.atmel.com/Images/doc8154.pdf
 

i have used above code but it didn't work.. i think i didn't apply any vcc to avcc pin..is it necessary to connect avcc pin to vcc every time?
i have also connected AREF to ground..is it also a problem?
 

sarabgt said:
is it necessary to connect avcc pin to vcc every time?
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 VCC
through a low-pass filter.


sarabgt said:
i have also connected AREF to ground..is it also a problem?
Yes this could also be a problem. Please take a look at page 221 of the datasheet (ADMUX register) to understand the AREF pin connection cases.

The worst thing you can do to yourself is to not read the datasheet. It is already posted in post #7 by the way.

Alexandros
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top