Hallo liebe Forumsmitglieder,
ich habe ein Problem: Ich habe eine Stoppuhr mit Laserlichtschranke gebaut. Die 5m entfernte Laserlichtschranke funktioniert problemlos. Ich habe aber auch 2 Taster die auch 5m entfernt sind angebracht, diese lösen einen Interrupt aus und sollten die Stoppuhr starten/stoppen bzw. rücksetzen. Leider funktionieren diese beiden nur sporadisch. Laut Oszi kommen die Signale am µC an, also kann ich mir das nicht erklären. Für Ratschläge wäre ich sehr dankbar.
Ich hoffe der Code ist nicht zu chaotisch.Code:#include <avr/io.h> #define F_CPU 16000000 #include <util/delay.h> #include <avr/interrupt.h> //Konstanten #define timer0_ovf 16000 //--Siebensegmentanzeigen #define ZERO 0x3F #define ONE 0x06 #define TWO 0x5B #define THREE 0x4F #define FOUR 0x66 #define FIFE 0x6D #define SIX 0x7D #define SEVEN 0x07 #define EIGHT 0x7F #define NINE 0x6F volatile uint16_t debounce = 0; volatile uint16_t wait_ms = 0; volatile uint8_t time = 0; volatile uint8_t A[10]={0,0,0,0,0,0,0,0,0,0};//{0,1,2,3,4,5,6,7,8,9};// uint8_t Symbols[10] = {ZERO,ONE,TWO,THREE,FOUR,FIFE,SIX,SEVEN,EIGHT,NINE}; volatile uint8_t Enable = 0; volatile uint8_t Int = 0; volatile uint8_t Reset = 0; volatile uint8_t Lock = 0; void WAIT_MS(uint16_t i){ wait_ms = i; while(wait_ms); } void init_all(void){ DDRA = 0xff; DDRB = 0xff; DDRC = 0xff; DDRD = 0x00; PORTA = 0x00; PORTB = 0x00; PORTC = 0x00; sei(); GICR |= (1<<INT0)|(1<<INT1); MCUCR |= (1<<ISC01)|(1<<ISC11)|(1<<ISC10); //--Timer0 einstellungen TCCR1B |= (1<<CS10)|(1<<WGM12); TIMSK |= (1<<OCIE1A); OCR1A = timer0_ovf; } void TIME(void) { A[0]++; if(A[0] == 10) { A[0]= 0; A[1]++; if(A[1] == 10){ A[1]=0; A[2]++; if(A[2] == 10){ A[2] = 0; A[3]++; if(A[3] ==10){ A[3] = 0; A[4]++; if(A[4] == 6){ A[4] = 0; A[5]++; if(A[5] == 10){ A[5] = 0; A[6]++; if(A[6]==6){ A[6]=0; A[7]++; if(A[7]==10){ A[7]=0; A[8]++; if(A[8]==10) A[8]=0; } } } } } } } } } void OUTPUT(void){ for(uint8_t i = 0; i<5;i++){ PORTC = 0b10000>>i; if( i == 3) PORTA = Symbols[A[i]]|0x80; else PORTA = Symbols[A[i]]; if( i == 1|| i ==3) PORTB = Symbols[A[4+i]]|0x80; else PORTB = Symbols[A[4+i]]; WAIT_MS(2); PORTA = 0; PORTB = 0; WAIT_MS(1); } } int main(void){ init_all(); while(1){ OUTPUT(); // 7-Segmentausgabe if(Int && !Lock){ if(Enable) Enable = 0; // Zeit wird nicht mehr inkrementiert else Enable = 1; // Zeit wird inkrementiert Lock = 1; debounce = 500; Int = 0; } if(Reset){ for(uint8_t t = 0; t<=10; t++) A[t] = 0; Enable = 0; Reset = 0; Int = 0; debounce = 0; } if(Lock && !debounce){ // Das am ende der Prellzeit der Interrupt zurückgesetzt wird. Int= 0; Lock = 0; } } return 0; } ISR(TIMER1_COMPA_vect){ if(debounce) debounce--; // Prellzeit if(wait_ms) wait_ms--; // warteroutine if(Enable) TIME(); // inkrementieren der Zeit } /*ISR (TIMER2_OVF_vect){ TIME(); }*/ ISR(INT0_vect) { if(!(PIND & (1<<PD0))){ // Laserlichtschranke if(!Int) Int = 1; } } // Interrupt für Taster ISR(INT1_vect){ if(!(PIND & (1<<PD5))){// Start/Stop Taster if(!Int) Int = 1; } if(!(PIND & (1<<PD4))){ // Rücksetztaste //Enable = 0; Reset =1; } }
Ich habe nun alles probiert schaffe es jedoch nicht ein Bild oder Anhang hinzu zu fügen.
vielen Dank,
lg Koertis







Zitieren

Lesezeichen