Sign In

Use 128p For Reading 2 Channal ADC Without And With Interrupt

Francesco fr.reitano@hotmail.it

Hardware: 1284p Internal Crystal @ 1Mhz On STK500 Software: C Atmel Studio 6

My problem is read at the same time two potenziometer throw 2 differen ADC.
This ADC are used with 1.1V, 1024 of prescalar, Autotrigger Mode.
This issue with interrupt and without interrupt is very hard for me.
In the code below i try to print the value of the two adc on LCD, but don't work fine.
With interrupt I do not know how you must do.
you can help me or give me some tips ?
best regards.

Images

Program

#define F_CPU 1000000 // with fuses CKDIV active 8Mhz/8=1Mhz

#include <avr/io.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "lcd.h"

void adc_init (void)
{
	/* 
		MUX4..0 = 00011 --> ADC3 
		MUX4..0 = 00111 --> ADC7 
	*/
	
	// set voltage reference AREF=1.1V, mux input ADC3 and Right adjustment
	ADMUX = (1 << REFS1)|(0 << REFS0)|(0 << ADLAR);
	
	ADCSRA = (1 << ADPS2)|(1 << ADPS1)|(1 <<ADPS0)|(1 << ADEN)|(1 << ADATE);	// set prescaler 128 and enable ADC, enable autotrigger
	
	ADCSRB = (0 << ADTS2)|(0 << ADTS1)|(0 << ADTS0);	//freerunning mode
}

int main(void)
{
	//Initialize LCD
	LCDInit(LS_BLINK|LS_ULINE);
	LCDClear();
	
	adc_init();
	
	//Potenziometro asta
	LCDWriteString("Pot1="); //Scrive a partire posizione 0, della riga 0(quella superiore), la stringa "Pot1=", di lunghezza 5 caratteri
	
        //Potenziomentro Set_point
	LCDGotoXY(0,1);
	LCDWriteString("Pot2="); //Scrive a partire posizione 0, della riga 1(quella inferiore), la stringa "Pot2=", di lunghezza 5 caratteri
	
    while(1)
    {	
		
		// ADC3 --> Potenziometro asta
		ADMUX |=(0 << MUX4)|(0 << MUX3) |(0 << MUX2) |(1 << MUX1) |(1 << MUX0); //Setto la lettura dall'ADC3 
		ADCSRA |= (1 << ADSC); // Start Conversion
		while((ADCSRA &(1<<ADIF))==0);	// wait for conversion to finish
		unsigned int a=ADC;
		LCDWriteIntXY(5,0,a,4); //Scrive a partire dalla posizione 5, della riga 0(quella superiore), la variabile data (ADC), di lunghezza 4 caratteri
		a=0;
		_delay_ms(1000); //Ritardo per consentire all'LCD di poter stampare i numeri
		
		ADC=0;
		ADCSRA |= (0 << ADSC); // Stop Conversion
		
		// ADC7 --> Potenziometro Set_point
		ADMUX |=(0 << MUX4)|(0 << MUX3) |(1 << MUX2) |(1 << MUX1) |(1 << MUX0); //Setto la lettura dall'ADC7
		ADCSRA |= (1 << ADSC); // Start Conversion
		while((ADCSRA &(1<<ADIF))==0);	// wait for conversion to finish
		unsigned int a1=ADC;
		LCDWriteIntXY(5,1,a1,4); //Scrive a partire dalla posizione 5, della riga 1(quella inferiore), la variabile data (ADC), di lunghezza 4 caratteri
		a1=0;
		_delay_ms(1000); //Ritardo per consentire all'LCD di poter stampare i numeri
		ADC=0;
		ADCSRA |= (0 << ADSC); // Stop Conversion
		
    }
	return 0;
	
}// fine main

Replies

R Avinash
2016-10-30 04:46:55
What actually you want to do? why you have chosed 1.1v as reference?

Post a reply to Francesco

Think you can help Francesco ? Then post your thoughts that might help Francesco. You will earn a lot of reputation in the technical community.

If your program is in multiple files, then ZIP the entire folder and attach below

Images and Screenshots

These helps other better understand your suggestion.