Hallo Zusammen!
mein ADXL will einfach nicht laufen..
Ich habe zwei Interrupts, einmal für den X Ausgang des ADXL's und einmal für den Y Ausgang.
der ADXL generiert bei beiden Ausgängen ein PWM Signal.
Wenn ich in meinem Progamm nun nur einen Interrupt aktiviere funktioniert alles wunderbar.
bei INT1 kommt der Y wert, bei INT0 der X Wert.
Beide zusmammen wollen aber nicht so richtig.
kann mir jemand weiterhelfen?
Vielen Dank!!
Code:#include <inttypes.h> #include <avr/interrupt.h> #define F_CPU 8000000 /* 8Mhz */ #include <util/delay.h> /* definiert _delay_ms() ab avr-libc Version 1.2.0 */ #include "twimaster.c" #include "LCD.h" volatile int t2_y,t2_x; volatile int t1_y,t1_x; volatile int x1,x0; // Temp Variablen für adxl und main int result; long count_y, count_x; char ziel[5]; ISR(SIG_INTERRUPT1){ if(x1==1){ x1=0; if(x0==1) MCUCR = (1<<ISC11 | 1<<ISC10 | 1<<ISC01 | 1<<ISC00); else MCUCR = (1<<ISC11 | 1<<ISC10 | 1<<ISC01 | 0<<ISC00); t1_y = count_y; } else{ x1=1; if(x0==1) MCUCR = (1<<ISC11 | 0<<ISC10 | 1<<ISC01 | 1<<ISC00); else MCUCR = (1<<ISC11 | 0<<ISC10 | 1<<ISC01 | 0<<ISC00); t2_y = count_y; count_y = 0; } } ISR(SIG_INTERRUPT0){ if(x0==1){ x0=0; if(x1==1) MCUCR = (1<<ISC01 | 1<<ISC00 | 1<<ISC01 | 1<<ISC00); else MCUCR = (1<<ISC01 | 1<<ISC00 | 1<<ISC01 | 0<<ISC00); t1_x = count_x; } else{ x0=1; if(x1==1) MCUCR = (1<<ISC01 | 0<<ISC00 | 1<<ISC01 | 1<<ISC00); else MCUCR = (1<<ISC01 | 0<<ISC00 | 1<<ISC01 | 0<<ISC00); t2_x=count_x; count_x = 0; } } ISR (SIG_OUTPUT_COMPARE1A){ count_y++; count_x++; } void Timer_Inits(void){ TCCR1A = 0; TCCR1B = (1 << WGM12) | (1 << CS10); OCR1A = (uint16_t) ((uint32_t) F_CPU / 50000); //100000 TIMSK |= (1 << OCIE1A); // Interrupt wenn Timer Vergleichswert erreicht // GIMSK = (1<<INT0 | 1<<INT1); //Int0,1 aktiv GIMSK = (1<<INT0); //Int0,1 aktiv } int main (void){ DDRC = 0x00; //alles als Eingan def. PORTC =0x00; //PullUp's aus DDRD =0x00; //alles Eingang PORTD =0x00; //PullUp's aus Timer_Inits(); sei(); i2c_init(); _delay_ms(1000); lcd_init(); _delay_ms(1000); for(;;){ _delay_ms(100); clear(); (int) result = (((((float)t1_y/(float)t2_y)*1000)-481)*1000)/125; sprintf(ziel,"%d",result); stringout ("y="); stringout (ziel); (int) result = (((((float)t1_x/(float)t2_x)*1000)-481)*1000)/125; sprintf(ziel,"%d",result); stringout (" x="); stringout (ziel); // if(result>4) PORTC|=(1<<PC3); //LED2 anschalte // else PORTC&=~(1<<PC3); // if(result>6000) PORTC|=(1<<PC2); //LED1 anschalte // else PORTC&=~(1<<PC2); // if(result>7) PORTC|=(1<<PC1); //LED0 anschalte // else PORTC&=~(1<<PC1); // if(result>8) PORTC|=(1<<PC0); //LED0 anschalte // else PORTC&=~(1<<PC0); } }







Zitieren

Lesezeichen