Forum: Mikrocontroller und Digitale Elektronik AVR Butterfly Code Problem


von Adeel A. (Firma: FH) (menuraaa)


Lesenswert?

Hallo,
ich arbeite an einem Projekt, indem ich "delay zwischen 2 Signalen" 
messen muss. Ich erkläre es nun mehr:
Ein Signal kommt an einem Relay (Signalname: rly-1) und es wir 
eingeschaltet. Ein RC-Glied in der Schaltung verursacht eine verzögerung 
in einem Signal, das an einem 2. Relay(Signalname: rly-2) ankommt. Ich 
muss die Zeitverzögerung zwischen den beiden Signal messen.
Ich habe zu Hause einen AVR Butterfly (Atmega 169). Ich habe Signal 
"rly-1" an Bit 0 des Port-B gelegt. Das Signal "rly-2" habe ich am Bit 1 
des Port-B gelegt.
Im Code ist es zu sehen dass sich ein Interrupt auslöst, wenn das Signal 
"rly-2" am Port-B Bit-1 da ist und ein LED am PORT-D Bit-0 wird 
eingeschaltet. Ich bin nur seit zwei Tage in Timer/Counters darin. Ich 
habe von Joe Pardue's Buch und von ein paar anderen Artikel über 
Timer/Counter gelesen und diesen Code geschrieben. Kann jemand von euch 
ein Blick auf den Code werfen und mein Fehler mir erkannt machen?
 Hier ist der Code:


// PortIO.c
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
int main (void)
{
    // Init port pins
  DDRB = 0xFC; // set port B PINS(Bits) 0 and 1 for input
  DDRD = 0xFF; // set port D for output

  TCCR1B| = ((1<<CS10) | (1<<CS12)); //Set Timer with 1024 as Prescaler 
Value

  PCMSK1 = PCMSK1|(1<<PINB1); // enabeling Interrupt on PIN1
  EIFR = (1<<6)|(1<<7); // enableing EIFR and EIMSK for interrupt to 
occour
  EIMSK = (1<<6)|(1<<7);
}


  SIGNAL(SIG_PIN_CHANGE1) // the interrupt on Port B Pins will directly 
jump to this method.
{
    if (TCNT1 > 39065)   // 8MHz/1024 = 7813...i need 5 sec or 0.2Hz so 
7813/0.2=39065
{
  PORTD= 0x01; // if the time period (from turning on buterfly to 
causing interrupt is more than 5 secs then bit 0 of port D should blink 
led
  TCNT1= 0;
}
  else
{
  PORTD=0x02;// if the time period (from turning on buterfly to causing 
interrupt) is less than 5 secs then bit 1 of port D should blink led
  TCNT1= 0;
}
}

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.