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.

ADC conversion using AVR

Status
Not open for further replies.

gameelgamal

Member level 5
Joined
Dec 14, 2006
Messages
85
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Egypt
Activity points
1,888
avr adc

HI,
I tried to perform AD conversion using ATMEGA16 & code vision compiler
but it doesnt work!!!

I need any ADC example to compare my progam with it..
 

avr adc speed

Use CodeWizardAVR (shift+F2) inside CodeVision to build your ADC code! It worked
 
adc_vref_type

below link will give you the ADC code for WinAVR
**broken link removed**

Bibin John
www.bibinjohn.tk
 
adc avr

Use the 3 ADC register in ATMega16
ADMUX, ADCSRA, and SFIOR.

Or, if you want to use the CodeWizardAVR, u can use it anyway.
Just be sure you are using free running ADC or single run ADC.
 

avr adc registers

/*****************************************************
Project : Board Test
Version : 1.0
Date : 2/25/2007

Chip type : ATmega8535
Program type : Application
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 128
*****************************************************/

#include <mega8535.h>
#include "stdio.h"
#include "realtime.h"
#include "delay.h"
#include "eeprom.h"

#define ADC_VREF_TYPE 0x40

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}

void Init()
{

// ADC initialization
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC High Speed Mode: Off
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x86;
SFIOR&=0xEF;

}


unsigned int Get_Voltage()
{
unsigned char i;
unsigned int V=0;
unsigned int Data_ADC=0;

buff[4]=buff[3];
buff[3]=buff[2];
buff[2]=buff[1];
buff[1]=buff[0];
buff[0]=read_adc(7);
for(i=0;i<5;i++) Data_ADC+=buff;
V=(unsigned int)((float)Data_ADC/5);
return(V);
}

void main(void)
{

Vadc = Get_Voltage();

}

Good luck to YOU!
 

how to use avr adc

i hope this will help U..

i use atmega32 ..adc 8 bits... and make sampling 8 times ... for display result of adc conversion i use lcd 16

#include <mega32.h>

// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x15 ;PORTC
#endasm
#include <lcd.h>
#include <delay.h>
#include <math.h>
#include <stdio.h>

// Declare your global variables here
char Str[16];
unsigned char adc_input;
unsigned int i;
unsigned char data_adc;
unsigned char data_tampung[8];
unsigned int jumlah;
unsigned int rata2;
unsigned char data_final;

// Read the 8 most significant bits
// of the AD conversion result
unsigned char read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
for(i=0 ; i<8; i++)
{

// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
//return ADCH;
data_adc = ADCH;
data_tampung= data_adc;

}

jumlah = 0;
for(i =0 ;i<8;i++)
{
jumlah += data_tampung;
}

rata2 = ceil(jumlah/8);
data_final =(unsigned char)rata2;
return data_final;
}

void main(void)
{
// Declare your local variables here
unsigned int a= 0;
unsigned char data_kiri;
unsigned char data_serong1;



// Input/Output Ports initialization
// Port A initialization
PORTA=0x00;
DDRA=0x00;

// Port B initialization
PORTB=0x00;
DDRB=0xFF;//port output OKKK

// Port C initialization
PORTC=0x00;
DDRC=0xFF;

// Port D initialization
PORTD=0x00;
DDRD=0xFF;

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 16000,000 kHz
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x01;
TCNT0=0x00;
OCR0=0x00;

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off

TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;

// ADC initialization
// ADC Clock frequency: 500,000 kHz
// ADC Voltage Reference: AREF pin
// Only the 8 most significant bits of
// the AD conversion result are used
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x85;

// LCD module initialization
lcd_init(16);
lcd_clear();
lcd_gotoxy(0,0);
sprintf(Str," start ");
lcd_puts(Str);

while(1)
{

read_adc(3);
data_conversion = data_final;

lcd_clear();
lcd_gotoxy(0,0);
sprintf(Str,"data conversion= %u",data_conversion);
lcd_puts(Str);

};
 

read_adc avr

all the codes given in different are ok but did connect external capacitor btwn AREF and GND try that.
 

Re: how to use avr adc

hello sir
thanks for this code
i m using atmega32 and mq6 gas sensor and connecting tis one pin to pina.0 and taking its analog value and aref=avcc and when i see value at lcd then the value convert but it usually show a value256 and then decrement one by one and when i open gas then show a value and again decrement value on by one.
so sir plz help me in that
 

Re: avr adc registers

/*****************************************************
Project : Board Test
Version : 1.0
Date : 2/25/2007

Chip type : ATmega8535
Program type : Application
Clock frequency : 4.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 128
*****************************************************/

#include <mega8535.h>
#include "stdio.h"
#include "realtime.h"
#include "delay.h"
#include "eeprom.h"

#define ADC_VREF_TYPE 0x40

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}

void Init()
{

// ADC initialization
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC High Speed Mode: Off
// ADC Auto Trigger Source: None
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x86;
SFIOR&=0xEF;

}


unsigned int Get_Voltage()
{
unsigned char i;
unsigned int V=0;
unsigned int Data_ADC=0;

buff[4]=buff[3];
buff[3]=buff[2];
buff[2]=buff[1];
buff[1]=buff[0];
buff[0]=read_adc(7);
for(i=0;i<5;i++) Data_ADC+=buff;
V=(unsigned int)((float)Data_ADC/5);
return(V);
}

void main(void)
{

Vadc = Get_Voltage();

}

Good luck to YOU!


Hi Sir,

How can i read ADC by use interrupt ADC???

Thanks you,
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top