Forum: Mikrocontroller und Digitale Elektronik ATMega32: ADC-Kanäle liefern gleiches Ergebnis


von Reinhard S. (rezz)


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?

: Bearbeitet durch User
von Christian S. (roehrenvorheizer)


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

von Thomas (kosmos)


Lesenswert?

deaktiviere mal die Pullups. Pin im Portx Register auf Low stellen und 
dann den Pin im DDRx als Eingang einstellen oder man setzt das PUD = 
Pullup disable bit falls der ATMega32 soetwas hat.

von Reinhard S. (rezz)


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.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.