1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice
magvitron

avr based frequency meter with full code and design file

its a frequency meter. designed using atmega 8 (avr studio and avr gcc) proteus file : [ATTACH]

  1. magvitron
    its a frequency meter. designed using atmega 8 (avr studio and avr gcc)
    proteus file :
    View attachment freq counter (3).zip
    hex for lcd interfacing of the below code. ( the frequency is shown in an LCD)
    View attachment freq_lcd.hex
    Code (text):
    #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>
    short val,val1,i;
    unsigned int presc;
    char a[10];
    char ff[3] = {'v','a','l'};
    void usart_init();
    void usart_putch(unsigned char send);
    unsigned int usart_getch();
     
    int main()
    {
        DDRD = 0x02;
        //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
        usart_init();       // initialization of USART
        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;
    }
     
     
     
    void usart_init()
    {
        UCSRB |= (1 << RXEN) | (1 << TXEN);  
                        // Turn on the transmission and reception circuitry
        UCSRC |=  (1 << UCSZ0) | (1 << UCSZ1);
                        // Use 8-bit character sizes
     
        UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value..
                                // into the low byte of the UBRR register
        UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value..
                                        // into the high byte of the UBRR register
    }
     
    void usart_putch(unsigned char send)
    {
        while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
                                // for more data to be written to it
        UDR = send; // Send the byte
    }
     
    unsigned int usart_getch()
    {
        while ((UCSRA & (1 << RXC)) == 0);
                    // Do nothing until data have been received and is ready to be read from UDR
        return(UDR); // return the byte
    }
    ISR(TIMER0_OVF_vect)
    {
            val =TCNT1;
            TCNT1=0x00;
            TCNT0=0X00;
            TIFR =0x00;
            val =(val/13.107)*100;
            itoa(val,a,10);
            for(i=0;i<=3;i++)
            {
            usart_putch(ff[i]);
            }
            for(i=0;i<=10;i++)
            {
            usart_putch(a[i]);
            }
            _delay_ms(100);
     
    }
    Willen likes this.