Bluestar88
Member level 3
- Joined
- Oct 17, 2014
- Messages
- 59
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 6
- 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?......
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);
}
}
}