ADC conversion on Olimex board

kaleem

New Member
Hi friends i have to convert analog voltage and read the conversion value on the output port through digiview,

i have written the code but i think its not working can any one help me out
i am giving dc voltage of 2v as input to adc pin.
here is the code

#include <avr/io.h>
#include <avr/iom128.h>
#include <avr/signal.h>
#include <avr/delay.h>
unsigned char data[];
unsigned char counter;
unsigned char i;
void data_send(void);
void init(void);
void delay_loop(unsigned char);
#define adc_data;

/* ADC interrupt service routine*/
SIGNAL(SIG_ADC)
{
adc_data=((2*256)/5)
data[0]=adc_data;
//data[0]=ADCH;
data_send(); // send packet data
ADCSRA= 0x00; // disable ADC
}
void delay_loop1(unsigned long us)
{for(;us>0;us--)
{asm("nop");}
}

void init(void)
{
PORTA=0xFF;
ADMUX= 0xE0; // Vref (1.1v) internal , channel pB3 of ADC
ADCSRA= 0xC7; // enable ADC ; start conv.
counter=0; // initial value
}
void data_send(void)
{
for(i=0;i<8;i++)
{
if(data[0] & (01<<i))
{ PORTA= 0X40;
delay_loop1(1000000);
}
else
{
PORTA = 0x00;
delay_loop1(1000000);
}
}
}



void main()

{
init();
ADMUX= 0xE0; // Vref (1.1v) internal , channel pB3 of ADC
ADCSRA= 0xEF; // enable ADC ; start conv.
sei(); // interrupt enable
while(1);
}
 
I found something strange in your code

Code:
ADMUX= 0xE0; // Vref (1.1v) internal , channel pB3 of ADC

and you wrote:
"i am giving dc voltage of 2v as input to adc pin."

So, how can you measure 2V with 1.1V ref voltage??

And further:
1) Why continously initialising ADMUX with 0xE0? You did it once in "init" that should be enough?
2) What's the purpose of adc_data? It's continously set to 102(.4) due to your formula without any variable in it
3) Since you then transfer the variable data[0], also filled with adc_data, I expect that you will see a condtant value on your serial port...
 
Reply to ADC conversion

hello my friend, i am sorry i have written 1.1 v as internal reference by mistake actually i am using 2.56 v as internal voltage to ADC pin.

i am very confused whether the adc conversion would go into effect without adc_data,in this function i am defining the formula for ADC i.e ADC=((Vin*256)/2.56).

I have to view the conversion on a digiview device.

further more comments and suggestions are higly appreciated.

thank you.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…