Forum: Mikrocontroller und Digitale Elektronik ACME Bit lässt sich nich setzen


von Dshing S. (dshing)


Lesenswert?

Hi,
wie setzt man denn beim Atmega 168 das ACME Bit im ADCSRB Register für 
den Multiplexer zum Analogcomparator?
Im Datenblatt steht:

It is possible to select any of the ADC7..0 pins to replace the negative 
input to the Analog Comparator.
The ADC multiplexer is used to select this input, and consequently, the 
ADC must be
switched off to utilize this feature. If the Analog Comparator 
Multiplexer Enable bit (ACME in
ADCSRB) is set and the ADC is switched off (ADEN in ADCSRA is zero), 
MUX2..0 in ADMUX
select the input pin to replace the negative input to the Analog 
Comparator, as shown in Table
23-1. If ACME is cleared or ADEN is set, AIN1 is applied to the negative 
input to the Analog
Comparator.

Das würde ich gerne machen, aber wenn ich schreibe:
ADCSRB |= (1<<ACME);
bleibt es auf Null. Es lässt dich auch in dem I/O Port Fenster des 
AVR-Studios nicht umschalten per Mausklick.

Mein Code komplett ist:
1
#include <inttypes.h>
2
#include <avr/io.h>
3
#include <util/delay.h>
4
#include <avr/pgmspace.h>
5
#include <avr/interrupt.h>
6
7
void HARD ()
8
{
9
  DDRC |= (1<<PC3);
10
      
11
  ACSR &=~ (1<<ACD);
12
  ACSR |= (1<<ACIE);
13
  ACSR |= (1<<ACIS1);
14
  //ACSR |= (1<<ACIS0);  
15
  ADCSRB &=~ (1<<ACME);  
16
  ADCSRA|=(1<<ADEN);
17
  ACSR&=~(1<<ACBG);  //interne referenz abschalten
18
}
19
20
void AC_0()
21
{  
22
  ADCSRA|=(1<<ADEN);
23
}
24
25
void AC_1()
26
{  
27
  ADCSRA&=~(1<<ADEN);
28
  ADMUX =0x00;
29
}
30
31
void AC_2()
32
{  
33
  ADCSRA&=~(1<<ADEN);
34
  ADMUX =0x01;
35
}
36
37
void AC_3()
38
{  
39
  ADCSRA&=~(1<<ADEN);
40
  ADMUX =0x02;
41
}
42
43
int main(void)
44
{
45
  HARD ();
46
  sei();
47
    while(1)
48
    {
49
      
50
        PORTC &=~ (1<<PC3);
51
    AC_1();
52
    _delay_us(5);    
53
    AC_1();
54
    _delay_us(5);
55
    AC_2();
56
    _delay_us(5);
57
    AC_3();
58
    _delay_us(5);
59
    }
60
}
61
62
ISR(ANALOG_COMP_vect)
63
{
64
  PORTC |= (1<<PC3);
65
  _delay_us(100);
66
}

von Ralf G. (ralg)


Lesenswert?

Dshing Sung schrieb:
> The ADC multiplexer is used to select this input, and consequently, the
> ADC must be
> switched off to utilize this feature. If the Analog Comparator
> Multiplexer Enable bit (ACME in
> ADCSRB) is set and the ADC is switched off (ADEN in ADCSRA is zero),

Steht das nicht hier?                         ^^^^              ^^^^

von Dshing S. (dshing)


Lesenswert?

Also wenn es da steht, dann verstehe ich es nicht :(

von Dshing S. (dshing)


Lesenswert?

Achso ich sehe grad was du meinst.
Das oben
  ADCSRB &=~ (1<<ACME);
und nicht

  ADCSRB |= (1<<ACME);

steht sicherlich. Aber ich hatte aus verzweiflung schon prbiert gehabt, 
ob man das Bit löschen muss um es auf EINS zu setzen.
Also auch mit:
  ADCSRB |= (1<<ACME);
Funktioniert es nicht :(

von Ralf G. (ralg)


Lesenswert?

Ralf G. schrieb:
> ADEN in ADCSRA is zero

Dshing Sung schrieb:
> ADCSRA|=(1<<ADEN);

Damit hat es sich sicher für das gesetzte ACME wieder erledigt. Und 
danach wird es nicht mehr eingeschaltet.

von Dshing S. (dshing)


Lesenswert?

Also ich hab es jetzt auch mal ohne das ADEN bit versucht, funktioniert 
aber auch nicht. Ich hab sogar das
  ADCSRB |= (1<<ACME);
in die Hauptschleife geschrieben, aber im Simulator scheint er das 
einfach zu ignorieren, alle  anderen Befehle durchläuft er in der step 
for stem Simulation, aber der wird nie markiert.
1
int main(void)
2
{
3
        DDRC  |= (1<<PC3);
4
5
  ACSR  &=~(1<<ACBG);  
6
  ACSR  &=~(1<<ACD);
7
        ADCSRA&=~(1<<ADEN);
8
  ACSR  |= (1<<ACIE);
9
  ACSR  |= (1<<ACIS1);  
10
  ADCSRB|= (1<<ACME);
11
12
  sei();
13
    while(1)
14
    {
15
          
16
  ADCSRB |= (1<<ACME);  
17
        PORTC &=~ (1<<PC3);
18
  _delay_us(5);
19
    }
20
}
21
22
ISR(ANALOG_COMP_vect)
23
{
24
  PORTC |= (1<<PC3);
25
  _delay_us(100);
26
}

von Dshing S. (dshing)


Lesenswert?

Also ich hab es jetzt mal mit einm Atmega 8 versucht, da heißt das 
Register zwar
SFIOR |= (1<<ACME);
aber da funktioniert alles. Warum nicht bei dem Atmega 168?
Ich hab da auch einfach mal versucht das Register
SFIOR |= (1<<ACME);
zu beschreiben, aber hat auch nicht funktioniert :(
Was ist da los? Kann der Atmega 168 vielleicht gar nicht Multiplexen?

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.