Interrupt stört Pin

Gast #2198566
Lesenswert?

Hi

>Woran kann das sonst liegen?

An deiner geheimen ISR? Das Setzen/Löschen/Toggeln der zugehörigen 
OC-Pins hat nichts mit dem Interrupt zu tun. Das passiert in der 
gewählten Betriebsart des Timers auch ohne Interrupt.

MfG Spess
Gast #2198568
Lesenswert?

Na da wird doch im Interrupt der Out Pin getoggelt. Oder auch... Kunde 
zum Meister: "Irgendwas am Auto ist locker", worauf der Meister später 
sagt "irgendwas fest gezogen".

Du merkst, wir raten einfach mal drauf los...
Gast #2198617
Lesenswert?

Hier ist der Code
1
static volatile bool variable = 0;
2

3
int main(void)
4
{
5
    //Sensor X+        LOW Active
6
    DDRE &= ~(1<<DDE6);
7
    //Sensor X-
8
    DDRE &= ~(1<<DDE7);
9

10
    //Taster X+
11
    DDRB &= ~(1<<DDB0);
12
    //Taster X-
13
  DDRB &= ~(1<<DDB2);
14

15
  //Enable          LOW Active
16
    DDRB |= (1<<DDB1);
17
    PORTB &= ~(1<<PORTB1);
18

19
    //Motor Direction X      HIGH Active
20
    DDRD |= (1<<DDD5);
21
    PORTD |= (1<<PORTD5);
22
 
23

24
    //Motor Clock X        LOW Active
25
    DDRB |= (1<<DDB5);
26
    PORTB |= (1<<PORTB5);
27
  
28

29
    TCCR1B |= (2<<CS10);  //kein prescaler
30
    TIMSK |= (1<<TOIE1);  //overflow interrupt enable
31

32
    sei();
33

34

35
    static bool sensor_x_plus;
36
    static bool sensor_x_minus;
37

38

39

40
    while (1)
41
    {
42
        if (~PINE & (1<<PE6))
43
        {
44
            sensor_x_plus = true;
45
        }
46
        else
47
        {
48
            sensor_x_plus = false;
49
        }
50

51
        if (~PINE & (1<<PE7))
52
        {
53
            sensor_x_minus = true;
54
        }
55
        else
56
        {
57
            sensor_x_minus = false;
58
        }
59
       
60
        if (~PINB & (1<<PB0) && (sensor_x_plus != true))
61
        {
62
            PORTD |= (1<<PORTD5); 
63

64
            if(variable == 0)
65
            {
66
                PORTB &= ~(1<<PB5);
67
            }
68
            else if (variable == 1)
69
            {
70
                PORTB |= (1<<PB5);
71
            }
72
        }
73
        else if (~PINB & (1<<PB2) && (sensor_x_minus != true))
74
        {
75
            PORTD &= ~(1<<PORTD5);  
76

77
            if(variable == 0)
78
            {
79
                PORTB &= ~(1<<PB5);
80
            }
81
            else if (variable == 1)
82
            {
83
                PORTB |= (1<<PB5);
84
            }
85
        }
86
        else
87
        {
88
            PORTB |= (1<<PB5);
89
        }
90
}
91

92

93
ISR (TIMER1_OVF_vect)
94
{
95
    if (variable == 0)
96
    {
97
        variable = 1;
98
    }
99
    else if (variable == 1)
100
    {
101
        variable = 0;
102
    }
103
}
Gast #2198655
Lesenswert?

>Nachdem PB5 auf 1 gesetzt wird und der Debugger weiter springt wird PB5
>automatisch wieder gelöscht.

Naja, was solls, dein Programm macht das halt nicht so wie du
es dir vorstellst. Ganz normale Sache.
Gast #2198704
Lesenswert?

Wenn ich den Handler auskommentiere dann funktioniert es falsch
Wenn Enable-Bits auskommentiert dann richtig
Wenn Handler und Enable-Bits gesetzt dann falsch
Wenn Handler und Enable-Bits aukommentiert dann richtig

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