Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Simple down to earth frequency counter.

its a simple frequency counter using the famous atmega 8 of the avr II family micro controllers. it uses counter 2 module of the IC and counts for a period of time. then the value is displayed on a LCD module. its kind of a very vague freq meter, but hey its a start!

real time pic
599286_359648027437305_271286898_n.jpg


the proteus simulation .
xxx.jpg


proteus dsgn file , hex file and the elf file:
View attachment freq counter.zip

Code:
#define F_CPU 8000000UL
#include <avr/interrupt.h>
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
#include <stdlib.h>
#include<avr/io.h>
#include<util/delay.h>
#define rs PB0   
#define en PB2


short val,val1,i;
unsigned int presc;
char a[10];
char ff[5] = {'F','r','e','q',':'};
void lcddata(char dataout);
void lcdcmd(char cmdout);
void dis_data(char data_value);
void dis_cmd(char cmd_value);
void lcd_init()    ;

int main()
{
    DDRD = 0x02;
    DDRB =0xff;
    //counter1 initialization
    TIMSK |= 1<<TICIE1;
    //TCCR1B |=
    TCCR1B |=(1<<ICES1)|(1 << CS12) | (1 << CS11) | (1 << CS10);
    //counter 0 initialization
    TIMSK |= (1<<TOIE0);
    TCCR0 = (1<<CS02) | (1<<CS00);
    _delay_ms(50);        // delay of 50 mili seconds
    lcd_init();    // fuction for intialize
    sei();
    while(1)
    {
/*    switch (presc)
    {
     case 1024:
         TCCR0 = (1<<CS02) | (1<<CS00);
     case 256:
        TCCR0 = (1<<CS02);
    case 64:
        TCCR0 = (1<<CS01) | (1<<CS00);
    case 8:
        TCCR0 = (1<<CS01) ;
    case 1:
        TCCR0 = (1<<CS00);
    default :
        TCCR0 = (1<<CS02) | (1<<CS00);

    }*/
     }

    return 0;
}


ISR(TIMER0_OVF_vect)
{
        val =TCNT1;
        TCNT1=0x00;
        TCNT0=0X00;
        TIFR =0x00;
        val =(val/19.912)*100;
        itoa(val,a,10);
        for(i=0;i<=5;i++)
        {
     dis_data(ff[i]);
        }
        for(i=0;i<=10;i++)
        {
     dis_data(a[i]);
        }
        _delay_ms(100);
   
}
void lcd_init()    // fuction for intialize
{
    dis_cmd(0x83);
    dis_cmd(0x02);        // to initialize LCD in 4-bit mode.
    dis_cmd(0x28);        //to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
    dis_cmd(0x0C);
    dis_cmd(0x06);
    dis_cmd(0x83);
    dis_cmd(0x01);
}

void dis_cmd(char cmd_value)
{
    char cmd_value1;
   
    cmd_value1 = cmd_value & 0xF0;        //mask lower nibble because PA4-PA7 pins are used.
    lcdcmd(cmd_value1);            // send to LCD

    cmd_value1 = ((cmd_value<<4) & 0xF0);    //shift 4-bit and mask
    lcdcmd(cmd_value1);            // send to LCD
}                       


void dis_data(char data_value)
{
    char data_value1;
   
    data_value1=data_value&0xF0;
    lcddata(data_value1);

    data_value1=((data_value<<4)&0xF0);
    lcddata(data_value1);
}

void lcdcmd(char cmdout)
{
    PORTB=cmdout;
    PORTB&=~(1<<rs);
    PORTB|=(1<<en);
    _delay_ms(1);
    PORTB&=~(1<<en);
}

void lcddata(char dataout)
{
    PORTB=dataout;
    PORTB|=(1<<rs);
    PORTB|=(1<<en);
    _delay_ms(1);
    PORTB&=~(1<<en);
}

Comments

There are no comments to display.

Part and Inventory Search

Blog entry information

Author
Magvitron
Read time
2 min read
Views
531
Last update

Downloads

  • freq counter.zip
    27 KB · Views: 508

More entries in Uncategorized

More entries from Magvitron

Share this entry

Back
Top