Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

help with my atmega16 ADC conversion

Status
Not open for further replies.

aishiqi

New Member
i want 10 bit precision of ADC with my code below.but the problem is that the result does not change Continuously while i change the voltage continuously with two Precision potentiometer.
do you konw what i mean??

for example :

now ADCL is 0x56.i turn the potentiometer slowly, but ADCL doesn't change immediately .i keep turning, suddenly ADCL changes to 0x60,then 0x62,then0x63,then0x71;it can't be 0x57,0x58,0x59,0x61...........


i hope someone can help me!! thanks a lot first .


this is my code:

#include<iom16v.h>

unsigned long angular,adth,adtl;
unsigned char count=0,adjok=0;
unsigned long speed=0;
unsigned long temp;
adinit()
{
ADMUX=0xc0;
ACSR=0x80;
ADCSRA=0xc8;
}
uinit()
{
UBRRL=51;
UCSRB|=0x88;
SREG|=0x80;

}

portinit()
{
DDRA=0;
PORTA=0x00;
}

delay(){
unsigned int i;
for(i=0;i<100;i++);
}
sendchar(char ch)
{
while(!(UCSRA&0x20));
UDR=ch;}

adjust()
{SREG&=0x7f;
speed=0;
angular=0;
count=0;
adjok=0;
SREG|=0x80;
}

#pragma interrupt_handler adcsvr:15
adcsvr()
{
adtl=ADCL;
adth=ADCH;

ADCSRA=0xc8;
//sendchar(adth);
sendchar(adtl);

angular=angular+((adth<<8)+adtl)*1000-speed;

if(adjok==0)
{
if(count<255) count++;
else
{adjok=1;
speed=angular/256;
}
}

}

main()
{
MCUCR=0x00;
uinit();
portinit();
adinit();
delay();
adjust();
while(1)
{
/*sendchar(adtl);
sendchar(angular>>24);
sendchar((angular>>16)&0xff);
sendchar((speed>>8)&0xff);
sendchar(speed&0xff);
delay();
*/


}

}
 
How are you filtering the POT? That could be easily explained by wiper noise. By the way, even though the ADC gets 10 bits of ADC data actually getting all 10 bits to be noise free and useful is almost impossible. Some type of filtering or statistical method, such as oversampling and averaging to reduce noise, or oversampling and trying to extract extra bits from the accumulated data, but either way you'll lose sampling rate.
 
Last edited:
Mega16 adc doesn't do the job as well as Mega8 adc
try mega8 once again
remeber that it's better to set AVCC pin as ADC reference instead Aref pin(attend to compiler setting and select avcc pin for voltage reference)
then bypass avcc pin with a 100nf capacitor to ground in order to reducing noise
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top