ATMega32: ADC-Kanäle liefern gleiches Ergebnis

OP #6248902
Lesenswert?

Hallo zusammen,

ich frag hier auf meinem NET-IO (16 MHz Takt) zwei ADC-Kanäle ab, direkt 
hintereinander:
1
timer1_overflow:
2
  
3
; neuen ADC-Wert lesen 
4
  ldi     temp1, 0b01100110           ; Setzen ADC auf linksbündig, Kanal 6 (vorletzter), interne 5V
5
  out     ADMUX, temp1
6
  sbi     ADCSRA, ADSC        ; den ADC starten
7
 
8
wait_adc6:
9
    sbic    ADCSRA, ADSC        ; wenn der ADC fertig ist, wird dieses Bit gelöscht
10
    rjmp    wait_adc6
11

12
 
13
; ADC einlesen (ADC6):
14
    in      adlow,  ADCL
15
    in      adhigh, ADCH        
16

17
  mov     kanal6, adhigh
18
  mov    zeichen, adhigh
19
  rcall  transmit
20
  mov    zeichen, adlow
21
  rcall  transmit
22
 
23
   ldi     temp1, 0b01000111            ; Setzen ADC auf rechtsbündig, Kanal 7 (letzter), interne 5V
24
   out     ADMUX, temp1
25

26
 wait_adc7:
27
    sbic    ADCSRA, ADSC        ; wenn der ADC fertig ist, wird dieses Bit gelöscht
28
    rjmp    wait_adc7
29

30
  in      adlow, ADCL         ; immer zuerst LOW Byte lesen
31
    in      adhigh, ADCH        ; danach das mittlerweile gesperrte High Byte
32
  mov    zeichen, adhigh
33
  rcall  transmit
34
  mov    zeichen, adlow
35
  rcall  transmit

Wer µc.net kennt dürfte leichte Ähnlichkeiten zum Beispiel aus dem 
Tutorial erkennen ;)

Mein Problem daran: Beidesmal kommt bitgenau der selbe Wert heraus, halt 
einmal rechtsbündig, einmal linksbündig.

Kann es sein, das ich hier schlicht zu schnell hintereinander abfrage? 
Weil mit anderem Code, der das deutlich gemächlicher macht, komm ich auf 
die gewünschten Ergebnisse. Aber ich warte ja nun extra aufs löschen vom 
ADSC-Bit, also sollte sowas doch nicht vorkommen?
#6248923
Lesenswert?

Hallo,

vermutlich benutzt Du single conversion mode.

"When changing channel selections, the user should observe the following 
guidelines to ensure that the correct channel is selected:

In Single Conversion mode, always select the channel before starting the 
conversion. The chan- nel selection may be changed one ADC clock cycle 
after writing one to ADSC. However, the simplest method is to wait for 
the conversion to complete before changing the channel selection.
In Free Running mode, always select the channel before starting the 
first conversion. The chan- nel selection may be changed one ADC clock 
cycle after writing one to ADSC. However, the simplest method is to wait 
for the first conversion to complete, and then change the channel 
selection. Since the next conversion has already started automatically, 
the next result will reflect the previous channel selection. Subsequent 
conversions will reflect the new channel selection.
When switching to a differential gain channel, the first conversion 
result may have a poor accu- racy due to the required settling time for 
the automatic offset cancellation circuitry. The user should preferably 
disregard the first conversion result."

Mfg
OP #6249095
Lesenswert?

Christian S. schrieb:
> Hallo,
>
> vermutlich benutzt Du single conversion mode.

Soweit richtig, ja.
>
> "When changing channel selections, the user should observe the following
> guidelines to ensure that the correct channel is selected:
>
> In Single Conversion mode, always select the channel before starting the
> conversion.

Hab ich gemacht.

> The chan- nel selection may be changed one ADC clock cycle
> after writing one to ADSC. However, the simplest method is to wait for
> the conversion to complete before changing the channel selection.

Gewartet hab ich ja auch. Aber der (vermutliche) Fehler war, das ich den 
ADC beim zweiten Mal nicht wieder gestartet habe.

Ich hab jetzt noch ein
1
sbi     ADCSRA, ADSC
eingefügt und bis jetzt läuft das. Ich könnte aber schwören, das es bei 
den letzten Tests auch so lief...

Da mein Kanalwert aber in Abhängigkeit des anderen Kanals ordentlich 
schwankt (bei GND an einem Kanal -200, bei Vcc +200) muss ich das wohl 
eh noch etwas korrigieren.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren