[En-Nut-Discussion] Analog input

Lars Andersson lakab at telia.com
Wed Dec 3 16:40:41 CET 2003


Hello,
you can try this for a starter if you use GCC
simple, non interrupt driven.

// Adcdrv.c

#include <io.h>

void ADCSetup(void)
{
// for ATMEGA128
/*
	REFS1 = 1; // Use internal 2.56V REF
	REFS0 = 1;
	ADLAR = 0;
	ADEN = 1;	// AD converter on
*/
	ADCSRA = 0x97;
	ADMUX = 0xC0;
}

int ADConvert(short chan)
{
	int tmp;
	int ADresult;
	tmp = ADMUX & ~0x07;
	tmp |= chan & 0x7;
	ADMUX = tmp;						// Set
channel
	// maybe delay a little here to settle the MUX
	sbi(ADCSRA,ADSC);
// Start ADC	
	loop_until_bit_is_set(ADCSRA, ADIF);	// Wait for ADIF, will
happen soon
	ADresult = ADCL;				// Read LSB
first
	ADresult |= ((int)ADCH) << 8;	// then MSB
	sbi(ADCSRA,ADIF);
// Clear AD Interrupt Flag

	return ADresult;
}


// Regards, Lars H. Andersson


-----Original Message-----
From: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] On Behalf Of Robert
Hildebrand
Sent: Wednesday, 03 December, 2003 16:26
To: Ethernut User Chat (English)
Subject: AW: [En-Nut-Discussion] Analog input


You should look in the Mega128 datasheet for details about the internal
a/d-converter.

Robert

-----Ursprungliche Nachricht-----
Von: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de]Im Auftrag von Rich Wellner
Gesendet: Mittwoch, 3. Dezember 2003 16:05
An: en-nut-discussion at egnite.de
Betreff: [En-Nut-Discussion] Analog input


I've just received my first couple ethernut's and am pretty happy.  Neat
little device.  I've been able to, within hours of receiving it, compile
samples and my source and load them, write code against the digital pins
and
spend some time fooling with the basemon example to see how the board
works.

However, I'm having a hard time finding the doc for programming to the
analog
inputs (or an example).  Can someone point me to either an example or
the
right place in the doc?  Thanks.

rw2
_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion



_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion





More information about the En-Nut-Discussion mailing list