ADC multi channel conversion

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello!

I'm trying to make multi channel conversation for 2 ADC. The time diagram is added in attachment.

I need to make 2 measures (measuring of ADC0 and measuring of ADC7) per one period of triggering signal. I use PWM (Pin PB7, Atmega 2560) as trigger signal. 

But now it makes just 1 measure per 1 period of time. Firstly - ADC0, secondly - ADC7. For the control, I use terminal on my computer.

This is the part of the code:

//Инициализируем АЦП
void ADCInit(void) {
    ADCSRA|=(1<<ADEN);
    ADMUX=(1<<MUX2)|(1<<MUX1)|(1<<MUX0)|(1<<REFS0);            //на канал ADC7
    ADCSRA|=(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);        //делитель=128
    ADCSRA|=(1<<ADATE);
    ADCSRA|=(1<<ADIE);//разрешаем прерывания
    DIDR0|=(1<<ADC0D)|(1<<ADC7D);
    
}
int main(void) {
	DDRB=(1<<PORTB7)|(1<<PORTB6);
	//DDRE=(1<<PORTE5)|(1<<PORTE4)|(1<<PORTE3);
	PWM_ini();				//Инициализация ШИМ
	UART0_Init();			//Инициализация порта на  uART
	ADCInit();				//Инициализация АЦП
	sei();
	ADCSRA|=(1<<ADSC);

	while(1) {

	}
}

ISR(TIMER1_COMPC_vect)
{
uint8_t theLOW=ADCL;
uint16_t ADC_ten_bits=ADCH<<8|theLOW;

	switch (ADMUX)
	{
	case 0b01000111:

		n=(float) ADC_ten_bits/204.8;// 1024/5=204,8
		uart0_tr((unsigned char)n+0x30);
		uart0_tr('.');
		uart0_tr((unsigned char)(n*10)%10+0x30);
		uart0_tr((unsigned char)(n*100)%10+0x30);
		uart0_tr((unsigned char)(n*1000)%10+0x30);
		uart0_tr(0x20); //делаем "Space". "0x0D" - это Пробел в ASCII коде
		ADMUX=0b01000000;
		break;
	case 0b01000000:

		n=(float) ADC_ten_bits/204.8;// 1024/5=204,8
		uart0_tr((unsigned char)n+0x30);
		uart0_tr('.');
		uart0_tr((unsigned char)(n*10)%10+0x30);
		uart0_tr((unsigned char)(n*100)%10+0x30);
		uart0_tr((unsigned char)(n*1000)%10+0x30);
		uart0_tr(0x0D); //делаем "Enter". "0x0D" - это Enter в ASCII коде
		ADMUX=0b01000111;
		break;

	default:
		break;

	}
	ADCSRA|=(1<<ADSC);

	//_delay_ms(100);
}

ISR(ADC_vect)
{

}

As I understood from datasheet, when I use autotriggering, it is not possible to start the next conversation. 

Are there any other solutions? 

Thanks in advanced! 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

when I use autotriggering, it is not possible to start the next conversation. 

You are always free to change adc modes...when the conversion is complete, maybe use the adc completed interrupt, to set up & force start your second conversion.  When that is finished (and it runs the adc complete irq), set things back to autotrigger on the next pwm.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

when I use autotriggering, it is not possible to start the next conversation. 

You are always free to change adc modes...when the conversion is complete, maybe use the adc completed interrupt, to set up & force start your second conversion.  When that is finished (and it runs the adc complete irq), set things back to autotrigger on the next pwm.

It sounds convicing! I should try to do it