Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Does CVAVR compile correctly?

2005-08-03 by Amir Rahafrooz

Dear everybody,
I wanted to use Differential ADC in atmega64,but it didn't work.
I previously wrote similar codes for atmega16,So I changed them for 
atmega64(considering changes in ADC control bit positions).After all 
I came to the conclusion that something should be wrong with CVAVR.
Does anyone have an idea?


my codes is as follow:

#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
//waits to become stable after changing the channel
delay_us(150);

ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
//for a better result read twice
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;

return ADCW;
}
and my initialization is:

// ADC initialization
// ADC Clock frequency: 115.200 kHz
// ADC Voltage Reference: AVCC pin
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x87;

I use read_adc(0),read_adc(1),read_adc(2),read_adc(9),
I read the first three one correctly(single ended channels),
but the last one(differential ADC with gain x10) is read a constant
value.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.