Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

ADC question

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
readw

Bascom Member



Joined: 16 May 2004
Posts: 4
Location: Leichhardt

australia.gif
PostPosted: Sun May 16, 2004 2:04 pm    Post subject: ADC question Reply with quote

Each time I read the ADC channel I get a slightly different value. ie if I read it 16 times I will get 16 numbers that are different by +- 1. If I read the channel 16 times then divide the answer by 16 and then repeat the process I will still get a different result by +-1 from the previous set of numbers. I am using this number to position a stepper motor and unfortunately because of this I am getting a result that is causing the motor to continually step on one direction or the other.

I have turned off the interrupts.

Any suggestions?


Thanks

Warren
Back to top
View user's profile Visit poster's website
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5916
Location: Holland

blank.gif
PostPosted: Thu May 20, 2004 12:16 am    Post subject: Reply with quote

You need to eliminate 1 bit of the resolution.
You can do this by dividing by 2, or shift the result to the right.

Another solution would be to use an external a/d converter with higher resolution and better stability.

What also could be a problem is the reference voltage. Did you tried various options?

_________________
Mark
Back to top
View user's profile Visit poster's website
readw

Bascom Member



Joined: 16 May 2004
Posts: 4
Location: Leichhardt

australia.gif
PostPosted: Thu May 20, 2004 12:19 pm    Post subject: Reply with quote

Hi Mark,

Thanks for the response.

I am using a voltage reference source 4.096volts on the avcc port of an m323 and this appears to be working ok. Being a 10bit adc I thought I would get a reasonable conversion but maybe not. I have tried different settings in the config but the one below appears to be the only one that works

Config Adc = Single , Prescaler = Auto , Reference = Internal

The documentation suggsts that this processor should be able to accept different settings. Is this correct.

If I wanted to reduce the resolution is it best to convert the number to a binary value and then use the shift command? Are you able to post an example of this?


Thanks


Warren
Back to top
View user's profile Visit poster's website
davematt

Bascom Member



Joined: 25 May 2004
Posts: 6
Location: Gippsland, Australia

PostPosted: Tue May 25, 2004 8:56 am    Post subject: Reply with quote

I have sometimes got weird ADC results with the following solution. Read the channel No. one less than the one you want, then read your desired channel. This sometimes fixed the problem, I have no idea why but would appreciate any hints.
Back to top
View user's profile
eddy

Bascom Member



Joined: 09 Apr 2004
Posts: 67
Location: Near Chicago, IL USA

usa.gif
PostPosted: Fri May 28, 2004 1:17 am    Post subject: Reply with quote

I read in the datasheet (or on AVRFreaks) that you should not use the first reading. You could try reading the channel twice and see if it has the same result as reading another channel.

davematt wrote:
I have sometimes got weird ADC results with the following solution. Read the channel No. one less than the one you want, then read your desired channel. This sometimes fixed the problem, I have no idea why but would appreciate any hints.

_________________
Eddy Wright
Wright Hobbies, LLC
http://www.wrighthobbies.net
Back to top
View user's profile Visit poster's website
DyneDude

Bascom Member



Joined: 25 Apr 2004
Posts: 5
Location: Melbourne, Australia

australia.gif
PostPosted: Sun Jun 06, 2004 4:36 am    Post subject: Reply with quote

I haven't used the AVR ADC channels for any real precision, so the last bit "wobble" hasn't been a problem. I have however found that with many commercial ADC boards (ISA and PCI) that I get better results by reading a channel twice, but ignoring the fisrt reading. You could also try accumulating, say, 4 readings and dividing the result by 4 (shift).
_________________
Andrew Elder
DynoLog Dynamometer
Australia
Back to top
View user's profile
Jeremy Wempren

Bascom Member



Joined: 18 Jun 2004
Posts: 8

PostPosted: Fri Jun 18, 2004 7:29 am    Post subject: 2 conversions Reply with quote

the source gennerated by the MCS.lib indicated that it IS reading the adc 2 times and using the second result. more than likely the best thing to do is AND the binary result and kill the last bit.

eg. result anded by
1011011 1111110
would give 1011010

esentialy canceling out the last bit



JW
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5916
Location: Holland

blank.gif
PostPosted: Sat Jun 19, 2004 11:06 pm    Post subject: Reply with quote

Reading twice is only needed for the older non-mega chips.
Most new chips do not have the error and only need 1 conversion.
But to be safe and compatible, you can do 2 readings as is the default in the lib.

_________________
Mark
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum