Microcontroller › AVR › frequency measurement and display on LCD › This is my approach but i am
May 16, 2012 at 10:46 am
#7835
Participant
This is my approach but i am not getting anything. could u please help me where am i doing wrong.
Your help and guidance is heartily acknowledged.
#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <compat/ina90.h>
#include “easyavr_lcd.c”
volatile ov_counter;
unsigned long frequency;
ISR(TIMER1_CAPT_vect)
{
// Counter to 0
TCNT1 = 0;
// The result is valid only if the counter
// has not overflowed yet
if (!(TIFR & (1 << TOV1)))
{
// Calculating the frequency from the period
frequency = (unsigned long)8000000 /
(unsigned long)ICR1;
}
}
ISR(TIMER1_OVF_vect){
ov_counter++;
}
void init_timer(){
TCCR1B = (1<<ICES1) | (1<<CS10);
TIMSK = (1<<TICIE1) | (1<<TOIE1);
}
int main(){
DDRB = 0x00;
init_timer();
lcdinit();
lcdmsg(“CURRENT LVL”,1);
char a1[7];
sei();
while(1){
lcdmsg(“CURRENT LVL”,1);
itoa(frequency, a1, 10);
lcdmsg(a1,2);
lcdmsg(“CURRENT LVL”,1);
_delay_ms(500);
lcdclr();
}
return 1;
}