Hallo
Ich möchte gerne die Länge der rot markierten Stellen (also der low-pegel) von folgendem Signal messen: Bild hier
Ich habe das ganze auf einem atmega128@16mhz mit der input capture funktion probiert doch irgendwie funktioniert es nicht so recht. So wie der code jetzt ist funktioniert nicht einmal die displayausgabe im while-loop. Habt ihr einen Tipp was ich anders machen sollte und/oder wo der/die Fehler sind? 
Das ist das erste Mal das ich timer/interrupts benutze also seid bitte gnädig mit mir falls ich einen echt dummen anfängerfehler gemacht habe 
Schon im Vorraus danke für eure Hilfe!
Code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <stdio.h>
#include "lib.h"
uint16_t duration_low=0;
ISR(TIMER3_CAPT_vect)
{
//was rising edge
if((TCCR3B & (1<<ICES3))==0) duration_low=ICR3;
//switch edge detection mode
TCCR3B ^=(1<<ICES3);
//deactivate interrupts
cli();
//set timer to 0
TCNT3=0;
//activate Interrupts
sei();
}
int main(void)
{
char Zahl[4];
// Initialization
INIT();
//set ICP3/PE7 as input
DDRE &= ~(1<<PE7);
//deactivate pwm output
TCCR3A = 0;
//Enable Input Capture Interrupt + Overflow Interrupt
ETIMSK = (1<<TICIE3)|(1<<TOIE3);
//Set Prescaler to cpu clock + Edge detection to falling edge + Input capture noise canceler
TCCR3B |=(0<<CS32)|(0<<CS31)|(1<<CS30)|(0<<ICES3)|(1<<ICNC3);
// Clear Input Capture Flag + clear pending interrupts
ETIFR = (1<<ICF3)|(1<<TOV3);
//activate global interrupts
sei();
while(1)
{
//Displayausgabe
sprintf(Zahl,"%3d",duration_low);
for (uint8_t i=0; i<=10; i++) LINE_2[i]=Zahl[i];
SHOW_LINES();
}
return 0;
}
Lesezeichen