View previous topic :: View next topic |
Author |
Message |
readw
Joined: 16 May 2004 Posts: 4 Location: Leichhardt
|
Posted: Sun May 16, 2004 2:04 pm Post subject: ADC question |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Thu May 20, 2004 12:16 am Post subject: |
|
|
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 |
|
|
readw
Joined: 16 May 2004 Posts: 4 Location: Leichhardt
|
Posted: Thu May 20, 2004 12:19 pm Post subject: |
|
|
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 |
|
|
davematt
Joined: 25 May 2004 Posts: 6 Location: Gippsland, Australia
|
Posted: Tue May 25, 2004 8:56 am Post subject: |
|
|
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 |
|
|
eddy
Joined: 09 Apr 2004 Posts: 67 Location: Near Chicago, IL USA
|
Posted: Fri May 28, 2004 1:17 am Post subject: |
|
|
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 |
|
|
DyneDude
Joined: 25 Apr 2004 Posts: 5 Location: Melbourne, Australia
|
Posted: Sun Jun 06, 2004 4:36 am Post subject: |
|
|
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 |
|
|
Jeremy Wempren
Joined: 18 Jun 2004 Posts: 8
|
Posted: Fri Jun 18, 2004 7:29 am Post subject: 2 conversions |
|
|
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 |
|
|
albertsm
Joined: 09 Apr 2004 Posts: 5913 Location: Holland
|
Posted: Sat Jun 19, 2004 11:06 pm Post subject: |
|
|
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 |
|
|
|