View previous topic :: View next topic |
Author |
Message |
P_Santos
Joined: 07 Jul 2011 Posts: 114
|
Posted: Tue Jan 21, 2020 11:31 am Post subject: ADC doesn't work well |
|
|
Hello,
I have a circuit where I measure the battery voltage in ADC1 and another voltage in ADC0, it doesn't work well
When the power is turned on, it makes the measurement on both pins of the Atmega88PA-AU, for example 1020 and 321 respectively, after a few moments I make a new measurement and the 1020 drops to 1015 and the other to more or less 352 and so on, after the 5th or 6th measurement the values remain more stable, does anyone have any explanation that can help to solve.
The same situation supplying the circuit with the battery as well as the power supply
Thanks in advance
Best regards
P_Santos
(BASCOM-AVR version : 2.0.8.1 , Latest : 2.0.8.2 ) |
|
Back to top |
|
|
P_Santos
Joined: 07 Jul 2011 Posts: 114
|
Posted: Tue Jan 21, 2020 11:48 am Post subject: |
|
|
Sorry, i means ADC2 and ADC0, but this is not the problem
100nF from AREF to GND
Connect AVCC to VCC
Not use cristal, it works with the internal 8Mhz oscillator
Fuse Bit's FF, DF, E2
$hwstack = 50
$swstack = 50
$framesize = 50
Have this configurations
'### ADC Configuration
Config Adc = Single , Prescaler = Auto , Reference = Internal_1.1
Stop Adc
Code to meassure
Start Adc
Adc_ = Getadc(0)
Maxvcc = Getadc(2)
Stop Adc
Regards
P_Santos |
|
Back to top |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Tue Jan 21, 2020 2:40 pm Post subject: |
|
|
try to make 5 or 10 measures and do the average
jp _________________ pleasure to learn, to teach, to create |
|
Back to top |
|
|
JC
Joined: 15 Dec 2007 Posts: 585 Location: Cleveland, OH
|
Posted: Tue Jan 21, 2020 6:24 pm Post subject: |
|
|
Well, I think you first need to decide if the "ADC doesn't work", or if, (more likely), the ADC module is doing what you tell it to do, and the actual signal itself is changing over time as the circuit stabilizes.
If you have an O'scope you can perhaps set a bit as a marker of when the ADC is taking it reading, and see the actual signal voltages your are measuring with the micro.
If the input signals are slowing changing , (low frequency), then putting a small RC filter on the input pin will help filter out external noise on the input signal.
Make sure you are driving the ADC input with a low impedance source. That means that the signal source can "drive" the ADC without the ADC putting an undue load upon the source.
If the signal source is high impedance, (> 10K), then the sample and hold cap internal to the ADC module will load the signal and you will get an erroneous value.
Some signals are best buffered by an op-amp so that the signal source is a low impedance driver.
In other cases a small cap on the ADC input will handle this for you.
Some ADCs will retain the prior reading's voltage on the ADC cap, so it is easier for the source to charge the cap to the correct value, with minimal impact on the signal source (for a relatively slowly changing signal). Other ADC's discharge the sample and hold cap, and it ahs to charge up from 0 V for each reading.
Also, make sure you trash the first ADC reading upon powering up the micro, (as per the micro's data sheet).
Bascom will set the ADC clock to the correct value, but if you were to configure the ADC yourself you need to make sure you run the ADC in spec, speed wise, as this can also significantly impact the readings.
JP mentioned taking several readings and averaging them.
That can also help one "get stable readings", if the system sampling speed, etc., so permits.
Bottom line, you need to make sure that changes in the actual signal itself are not the cause for the changes in your voltage readings.
JC |
|
Back to top |
|
|
hgrueneis
Joined: 04 Apr 2009 Posts: 902 Location: A-4786 Brunnenthal
|
Posted: Tue Jan 21, 2020 10:36 pm Post subject: |
|
|
P_Santos,
in addition to the above...
read the electrical characteristics of the ADC.
Total error at 200 KHz is 2 LSB at ideal conditions, plus any noise you have in your supply and system.
It is also not required to start and stop the ADC with every measurement, unless you are saving Battery power.
You might also (in addition to the already suggested measures) try a reduced ADC clock and some delay after Start ADC.
Also suspend any communication and I/O during ADC sense to reduce noise in the system.
Best regards
Hubert |
|
Back to top |
|
|
P_Santos
Joined: 07 Jul 2011 Posts: 114
|
Posted: Wed Jan 22, 2020 12:01 pm Post subject: |
|
|
Hello,
Thank you all
I will follow yours sugestions and see what happens
To save battery, i switch ON the voltage to the instrumentation amplifier always before adc reading, and OFF when itīs done,
today i will try to let it always ON and only OFF when the Atmega go sleep in powermode
Best regards
P_santos |
|
Back to top |
|
|
Evert :-)
Joined: 18 Feb 2005 Posts: 2156
|
Posted: Wed Jan 22, 2020 8:44 pm Post subject: |
|
|
So you have a opamp connected to the adc pin?
Maybe the opamp is not stable or needs a filter. _________________ www.evertdekker.com Bascom code vault |
|
Back to top |
|
|
P_Santos
Joined: 07 Jul 2011 Posts: 114
|
Posted: Thu Jan 23, 2020 11:29 am Post subject: |
|
|
Hello Evert,
Yes, i use a MCP6N11-100E, now i changed the gain and Ref Resistors to 1% tolerance and it better now
On the output of the INA, have a 4,7k and a 100nF to GND to the ADC(2) pin, now have remove the 100nF, it is better without, ask me not why, don't know
Best regards
P_Santos |
|
Back to top |
|
|
|
|
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
|
|