Forum: Mikrocontroller und Digitale Elektronik ATmega mit Timer1 und Touchpanel stürzt ab


von Roland K. (roland_k)


Lesenswert?

Hallo,
ich habe einen ATmega 1284 PU.
Dieser steuert ein Touchscreen (128x64) und generiert zusätzlich mittels 
Timer1 im CTC - Modus ein Signal.

Der uC startet jedoch ständig neu.

Beide Funktionsbereich alleine Funktionieren wunderbar.
Nur wenn der uC beide Dinge tun soll, stürzt er ab und startet sofort 
neu.

Hier der Quelltext der main mit ISR:
1
 // Timer1 - ISR
2
void Timer1COMPA_ISR() org IVT_ADDR_TIMER1_COMPA {
3
SREG_I_bit = 0;                      // Interrupt disable
4
PORTB.B0 = ~PORTB.B0;
5
6
ADC_Value = adc_read(4);
7
8
if(ADC_Value <= S2){
9
y = Q /(S2 - S1) * (ADC_Value - S1) - Q;
10
PortB.B1 = 1;
11
PortB.B2 = 0;
12
PortB.B3 = 0;
13
}
14
15
if (ADC_Value > S2 && ADC_Value <= S3){
16
y=65500;
17
PortB.B1 = 0;
18
PortB.B2 = 1;
19
PortB.B3 = 0;
20
}
21
if(ADC_Value > S3){
22
y = Q / (S4 - S3)* ADC_Value - (Q /(S4 - S3)) *S3;
23
PortB.B1 = 0;
24
PortB.B2 = 0;
25
PortB.B3 = 1;
26
}
27
28
  OCR1AH = y;
29
  OCR1AL = (y>>8);
30
// Just for controlling
31
Timer1counter++;
32
33
SREG_I_bit = 1;                      // Interrupt enable
34
35
}
36
37
38
void main() {
39
40
//Pindirections **** *************************************************/
41
// 0 means input - 1 means output
42
   DDRB = 0b100001111;
43
   PORTB = 0x00;
44
/******************************************************************************/
45
  adc_init(); //AD-Wandler initialisieren
46
  
47
  TIMSK1 = 0b00000010;       //compare A Register Interrupt on
48
49
  y=65500;                 // write Compare Value in register
50
  OCR1AH = y;
51
  OCR1AL = (y>>8);
52
53
//MCU Clock Frequency 20 MHz
54
  TCCR1A = 0b00000000;
55
  TCCR1B = 0b00001100;                 // 0b00000001 starte Timer1 mit Prescaler 1   s.D.-sheet 160
56
57
  SREG_I_bit = 1;                      // Interrupt enable
58
59
  Start_TP();
60
61
  while (1) {
62
    Check_TP();
63
  }
64
65
}
Was könnte hier der Grund sein?
Danke!

Gruß Roland

von Martin K. (Gast)


Lesenswert?

Wo ist der Rest vom Programm? TopSecret?  Kommentare im programm währen 
auch hilfreich, um rauszufinden was du überhaupt bezwecken willst.

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.