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 | }
|