Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! 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

Newbie level 1
Joined
Jan 4, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
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();
*/


}

}
 

better use ADC interrupt of ATmega16. Refer **broken link removed** for code and working details.
 
aishiqi said:
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...........

What you didn't mention was: You saw the value changing with the voltometer and this value didn't match the ADC value? Or you turned the potentiomemeter, you didn't see changes and you assumed that the voltage changes but the ADC does not follow? And what do you mean by "precision potentiometer"? Because if you are talking about multiturn, then it "tries" to be linear but it can't manage it all the time. It is like "hoping" from one resistor value to another, I have seen this, that's why I'm asking about the way you did your experiments.
 

Sudden increase or decrease may happen if your power supply is not proper. There are some other factors which affect the adc is filtering. (i.e. long wires from potentiometer).

The simplest way is to average the values of adc.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top