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.

Reading From ADC atmega32

Status
Not open for further replies.

Bluestar88

Member level 3
Member level 3
Joined
Oct 17, 2014
Messages
59
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
447
i am using Atmega32 ADC to measure a 5V analog voltage.
i want to make an ADC conversation using ADMUX=0x40 (AVCC ref.) So I used the below code and I attached the AREF pin(number pin=32)to VCC. (I used the putchar() becauuse I want to send the value to visual basic(PC))

unfortunately it's not working and the results keep changing without any changes in the voltages (the value which I measure doesnot change)...can i get some HELP please?......


Code:
#include <mega32.h>

// Standard Input/Output functions
#include <stdio.h>
#include <delay.h>
#include <math.h>



// Read the AD conversion result
unsigned char i=0;
unsigned int read_adc(unsigned char adc_input)
{
unsigned char t;
ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
//t=ADCW;
//t=((ADCW*2.56)/1023)*100;
t=((ADCW*5)/1023);
return t;
}


void main( )
{

ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x86;


while (1)
      {   
        
        if (a=='$')
         {
          
          i=1;
           adc_value=read_adc(i);    
           PORTB=adc_value;
           putchar(adc_value);
           delay_ms(10); 
          
         }    
   }
}
 

Hi,

Please specify "the value is changing".

+/- 1LSB one can not avoid.
With a 10bit ADC it should be stable within this range.
If the change is more than that, then there are a lot of possible problems. Ranging from software problems, setup problems, hardware problems....

To give you better assistance we need mor information..

Klaus
 
I used 8bit ADC, and AVCC(5volt)as a v Refrence....
but for two input which are 0 and 2.5 volt the ADC measures 1.5 and 2.1, respectively...I donot why..please help me..the code is here...
Code:
#include <mega32.h>
#include <stdio.h>
#include <delay.h>
#include <math.h>
#define CLBR 0x33 


#define ADC_VREF_TYPE 0x60
///////////////////////////////////////////////////////////////
// Read the AD conversion result
unsigned char i=0;
unsigned int read_adc(unsigned char adc_input)
{
//unsigned char t;

ADMUX=adc_input | (ADC_VREF_TYPE & 0xff);
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
//t=((ADCW*5)/255); 
//t=((ADCW*2.56)/1023)*100;
//t=((ADCW*5)/1023);
return ADCW;
}


void main( )
{
char a=0;

unsigned char adc_value;

UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x19;


SFIOR=0x00;
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;

while (1)
      {   
     
   a=getchar();
 if (a=='$')
         {
          
          i=1;
           adc_value=read_adc(i); 
           putchar(ADCH);
           //PORTB=ADCH;
           delay_ms(10); 
          
         }    
        

  } 
  
  }
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top