EmbeddedRelated.com
Forums

Differential ADC in atmega64

Started by Amir Rahafrooz July 31, 2005
Hi,
I tried to use diffrential adc in atmega64,but it didn't work,it
alwayes returns a constant number,Does anybody have any suggestions?


On Sun, 31 Jul 2005, Amir Rahafrooz wrote:

> Hi,
> I tried to use diffrential adc in atmega64,but it didn't work,it
> alwayes returns a constant number,Does anybody have any suggestions?
>

Did you follow the initialization procedure as outlined in the data sheet?
I had problems with an ADC setup once, but looking it over carefully I
found I had set it up incorrectly.

Can you post the section of your code that initializes and reads the ADC?

Zack


--- In avrclub@avrc..., Zack Widup <w9sz@p...> wrote:
> On Sun, 31 Jul 2005, Amir Rahafrooz wrote:
>
> > Hi,
> > I tried to use diffrential adc in atmega64,but it didn't work,it
> > alwayes returns a constant number,Does anybody have any
suggestions?
> >
>
> Did you follow the initialization procedure as outlined in the
data sheet?
> I had problems with an ADC setup once, but looking it over
carefully I
> found I had set it up incorrectly.
>
> Can you post the section of your code that initializes and reads
the ADC?
>
> Zack

I wrote similar codes befor for atmega16 successfully.
my codes is as follow:

#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUXc_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
ADMUXC_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.


So you're using CVAVR right..?? for my project, formerly i am also want to using differential channel.. but finally its not easy to do it especially using CVAVR ,so i prefer using single channer, but before it ,I'm using diifferential amplifier to recontrusct signal that I want...

For my project, I am using ATMega8535 version PDIP. When i read datasheet i finnaly found that PDIP dont support differential ADC.so thats the problem that I found and the solution..

maybe for your project, According to me,.. CV AVR dont support differential channel, the listing that you give is inisialisation for single channel not for differential..

just all.. wanna share my experience with you..
I hope it will be helping
Amir Rahafrooz <am_rahafrooz@am_r...> wrote:
--- In avrclub@avrc..., Zack Widup <w9sz@p...> wrote:
> On Sun, 31 Jul 2005, Amir Rahafrooz wrote:
>
> > Hi,
> > I tried to use diffrential adc in atmega64,but it didn't work,it
> > alwayes returns a constant number,Does anybody have any
suggestions?
> >
>
> Did you follow the initialization procedure as outlined in the
data sheet?
> I had problems with an ADC setup once, but looking it over
carefully I
> found I had set it up incorrectly.
>
> Can you post the section of your code that initializes and reads
the ADC?
>
> Zack

I wrote similar codes befor for atmega16 successfully.
my codes is as follow:

#define ADC_VREF_TYPE 0x40
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUXc_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
ADMUXC_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.
SPONSORED LINKS
Atmel avr Microcontrollers Intel microprocessors Pic microcontrollers 8086 microprocessor 8051 microprocessor

---------------------------------
YAHOO! GROUPS LINKS ---------------------------------

---------------------------------
Start your day with Yahoo! - make it your home page