Hi,
Nachdem ich den einfachen Analog-Comparator-Interrupt zum laufen
gebracht hab, brauch ich nun den Timer-Capture-Interrupt, ausgelöst
durch den Analog-Comparator.
Ich hab schon etliche Threads gelesen, wo das Problem besprochen wird
aber keine Fehler in meinem Code gefunden:
1 | #include <avr/io.h>
|
2 | #include <avr/interrupt.h>
|
3 |
|
4 | void usart_putc(uint8_t byte) {
|
5 | //Ein Byte senden
|
6 | while (!(UCSR0A&(1 << UDRE0)))
|
7 | ;//warten auf Datenregister empty
|
8 | UDR0=byte;
|
9 | }
|
10 |
|
11 | void usart_puts(char *s)
|
12 | //Einen String mit Endmarke 0 senden
|
13 | {
|
14 |
|
15 | while (*s != 0) {
|
16 | usart_putc(*s);
|
17 | s++;
|
18 | }
|
19 | usart_putc(0); //Endmarke 0 wird übertragen!
|
20 | }
|
21 |
|
22 |
|
23 | void usart_init_intr(uint16_t baud)
|
24 | {
|
25 | sei();
|
26 | UBRR0 = F_CPU/(baud* 16L) - 1;
|
27 | UCSR0B = (1 << RXEN0) | (1 << TXEN0) | (1 << RXCIE0);
|
28 | UCSR0C = (1<<USBS0);
|
29 | }
|
30 |
|
31 | void timer_comp_init_intr()
|
32 | {
|
33 | ACSR = (1 << ACI);//flag löschen
|
34 | ACSR = (1 << ACIC); //Input Capture interrupt enable
|
35 |
|
36 | TCCR1B |= ( 1<< CS11) |(1<<CS10); //1/64 timer starten
|
37 | TIFR1 |= (1<<ICF1) | (1 << TOV1);//flags löschen
|
38 | }
|
39 |
|
40 | int main(void)
|
41 | {
|
42 | DDRB = (1 << PB1) | (1 << PB0);
|
43 | PORTB |= (1 << PB1) | (1<<PB0);
|
44 |
|
45 | timer_comp_init_intr();
|
46 | usart_init_intr(9600);
|
47 |
|
48 |
|
49 | while (1)
|
50 | {
|
51 | if (ACSR & (1 << ACO))
|
52 | PORTB &= ~(1 << PB0);
|
53 | else
|
54 | PORTB |= (1 << PB0);
|
55 | }
|
56 | }
|
57 | ISR(TIMER1_CAPT_vect)
|
58 | {
|
59 | usart_puts("Neuer Interrupt aus TIMER1_CAPT");
|
60 | PORTB ^= (1<<PB1);
|
61 | }
|
62 | /*
|
63 | ISR(ANALOG_COMP_vect)
|
64 | {
|
65 | usart_puts("Neuer Interrupt aus ANALOG_COMP");
|
66 | PORTB ^= (1<<PB1);
|
67 | }*/
|
68 |
|
69 | ISR(USART_RX_vect)
|
70 | {
|
71 | uint8_t tmpChar = UDR0;
|
72 | //PORTB = UDR0%2;
|
73 | while ( !( UCSR0A & (1<<UDRE0))) ;
|
74 | UDR0 = tmpChar;
|
75 | }
|
Ergebniss: PB0 tut genau das was es soll(Je nachdem ob die Flanke fällt
oder steigt wird umgeschalten), PB1 bleibt immer an.
Ersetze ich nun
ACSR = (1 << ACIC); //Input Capture interrupt enable
mit
ACSR = (1 << ACIE); //Comparator interrupt enable
toggelt auch PB1 wenn die Flanke umschält und auf dem seriellen Port
kommt die erwünschte nachricht (neuer interrupt aus analog_comp).
Ich bin ratlos,
Danke für Hilfe,
Moritz