counter /atmega8

Started by shirin ghanbari November 19, 2012
i used a mega8 for count the faling edge pulseswith code vision but counterincrement with eachpulsefurther than one .
what can I do?
#include
#include
#include
void main(void)
{
// Declare your local variables here
unsigned char buff [20];
unsigned int t;
TCCR1A=0x00;
TCCR1B=0x06;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
lcd_init(16);
while (1)
{
// Place your code here
t=TCNT1 ;
sprintf(buff,"counter=%d",t);
lcd_puts(buff);
delay_ms(200);
lcd_clear ();
};
}



Hi
the best way to count edges is to use the
T input of the counter or an external interrupt.
T input makes the counter count edges.
If you want to measure  the period of
 the signal, the best way is to use the input capture of the counter controlled
by the analog comparator.
For slow signals : frequency = 1 / period
For fast signals, the best way is to count
the periods (using T input) inside a time window 
________________________________
From: shirin ghanbari
To: avrclub
Sent: Monday, November 19, 2012 3:26 AM
Subject: [AVR club] counter /atmega8


 
i used a mega8 for count the faling edge pulses with code vision but counter increment with each pulse further than one  .
what can I do?
#include
 #include
           #include
void main(void)
{
// Declare your local variables here
  unsigned char buff [20];
  unsigned int t;
TCCR1A=0x00;
TCCR1B=0x06;
TCNT1H=0x00;
TCNT1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
lcd_init(16);
while (1)
      {
      // Place your code here   
      t=TCNT1 ;
              sprintf(buff,"counter=%d",t);
          lcd_puts(buff); 
                   delay_ms(200);
          lcd_clear ();
      };
}