ADC converter - assembly - 4 ports - Problem

Go To Last Post
10 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, everybody.
I'm experiencing an extrange behaviour with the ADC.
There is a picture attached to understand better (I hope)
Normally, I was working with only one ADC input per micro and there wasn't any problem. This time, I'm using four inputs (ADC0 to ADC3)
I was changing the potentiometer attached to ADC3 and ADC2 starts to shift from his value... the same thing when I change ADC2 respect the value of ADC 1. (but it seems to be a little less I think)

After that, I start to disable the 4 sequential conversions, leaving just ADC3 and ADC2, that is because I was trying to isolate the problem, and ADC1 was showing the same problem with ADC3.
So, just ADC3 and 2, when changing the potentiometer of ADC3, ADC2 start to change his value too!!
The strange thing here is that the voltmeter is constant on the ADC2 input, I can move ADC from 0 to 5V, and the ADC2 is freezed on 2.3V for example, but internally, the micro controller is sensing a variation, and is coherent with the variation on the pin ADC3 but in a different range.

What could be causing this?

here is the code (extract):

ADC_INIT:
	ldi r16,0b01000000			; Este caso es para:  Aref = Vcc = 5V
	out ADMUX,r16				; colocar capacitor en AREF para filtrar ruido (ATMEGA8 P.206)
	ldi r16, 0b10000000;
	out ADCSRA, r16


;--------------------------------------------------------------
ldi 	r16,0b01000011			; Aref = 5V // ADC3
out 	ADMUX,r16		
RCALL	ADC_GET

ldi 	r16,0b01000001			; Aref = 5V // ADC1
out 	ADMUX,r16
RCALL	ADC_GET

ldi 	r16,0b01000000			; Aref = 5V // ADC0
out 	ADMUX,r16
RCALL	ADC_GET

ldi 	r16,0b01000010			; Aref = 5V // ADC2
out 	ADMUX,r16
RCALL	ADC_GET

;--------------------------------------------------------------


ADC_GET:
	sbi 	ADCSRA, ADSC				
ADC_loop:
	sbic 	ADCSRA, ADSC			
	rjmp 	ADC_loop

	in 		r16, ADCL
	STS 	ADC_IN_Lo,r16
	in 		r17, ADCH
	STS 	ADC_IN_HI,r17
	RET
;-----------

Attachment(s): 

Last Edited: Tue. Nov 8, 2011 - 04:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

1. Place the 1..10 nF capacitor from each ADC input to GND.
2. Provide enough time after switching ADMUX to a new channel.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MBedder wrote:
1. Place the 1..10 nF capacitor from each ADC input to GND.
2. Provide enough time after switching ADMUX to a new channel.

I assume that the 10nf is for noise reduction right?
that capacitor is placed, I forget to place it on the scheme. (I just correct the scheme)

There is enough time between readings, because there is a master-slave polling between readings.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You're clocking your ADC with a fastest possible clock which is Fosc/2 in your case (ADCSRA.ADPSx = 000), while the ADC clock frequency should not exceed 200 kHz to get a 10-bit resolution.

Warning: Grumpy Old Chuff. Reading this post may severely damage your mental health.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, you are right, that solve the problem,
I was using a 8Mhz clock and no prescaler configured.
Now, with the prescaler set to 64, ADC3 to ADC1 are working, but ADC0 it's like disconnected.
If I roll back the prescaler to no configured, ADC starts working again, but the ADC reading problem comes again too.
I've tried with the two possible prescalers option for 8Mhz that are 64 and 128, and both presents the same problem

Another curious thing, before the prescaler, ADC0 was the only input that was working fine, now, the others are the good ones. it's a step forward!!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok, find the problem, ADEN was not enabled...
the funny thing is that the ADC was working (partially) anyway.
Thanks for the help MBedder, you save me a lot of time on that.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

troyka wrote:

Thanks for the help MBedder, you save me a lot of time on that.

I'm afraid to look outside, are pigs flying???

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dksmall wrote:
I'm afraid to look outside, are pigs flying???

And you mean...?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

And you mean...?

I think you'd need to read a few of MBedder's previous posts to understand ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

MBedder usually does just the opposite by misleading or confusing new posters. To see him receive thanks and a compliment is a nice change!