sribalaji
Junior Member level 2
Doubt regarding multiple ADC conversion
My objective is to convert voltage and current simultaneously in an atmega controller and to find the power by multiplying it.
I've written the following code for ADC conversion:
Initially adc_channel was set to 0. Is this the correct way to write the code in case of multiple ADC conversion? I'm new to atmel programming and I've used codevision avr compiler.
My objective is to convert voltage and current simultaneously in an atmega controller and to find the power by multiplying it.
I've written the following code for ADC conversion:
Code:
interrupt [ADC_INT] void adc_isr(void)
{
data= ADCW;
if(adc_channel==0)
{
voltage_data_available=TRUE;
adc_channel++;
}
else if(adc_channel==1)
{
line_current_data_available=TRUE;
adc_channel++;
}
else
{
neutral_current_data_available=TRUE;
adc_channel=0;
}
}
void main(void)
{
ADMUX=adc_channel;
ADCSRA=0b11101101;
#asm("sei")
while (1)
{
if(voltage_data_available==TRUE)
{
voltage=data;
voltage_data_available=FALSE;
}
else if(line_current_data_available==TRUE)
{
line_current=data;
line_current_data_available=FALSE;
}
else if(neutral_current_data_available==TRUE)
{
neutral_current=data;
neutral_current_data_available=FALSE;
}
power=voltage*line_current;
};
}
Initially adc_channel was set to 0. Is this the correct way to write the code in case of multiple ADC conversion? I'm new to atmel programming and I've used codevision avr compiler.