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.

reading frequency using pic16f877a

Status
Not open for further replies.

Qaisar Azeemi

Full Member level 5
Joined
Feb 11, 2011
Messages
315
Helped
16
Reputation
32
Reaction score
15
Trophy points
1,298
Location
Peshawar, Pakistan, Pakistan
Activity points
3,829
Hi all;
i want to measure the frequency of a sin wave passed through HEF4093BE NAND gate Schmitt trigger to be furnished and this frequency is feeded into pin RA2 of PIC16F877A; and from this pin i want to read the frequency. i made the following code for that purpose but instead of reading the frequency it is counting the numbers with a very high speed i think with the clock speed of my 4MHz crystal. plz analyze my code and tell me the mistake. (NOTE: i don't want to use counter pins).

Here are frequency related parts of my code to make it understandable for you.

Code:
void interrupt()
{
     if(PIR1.TMR1IF==1)
     {
        
        frq=1;

     }
}

void main()
{

ADCON1=0x06;   // adc reg initialization
INTCON=0xA0;  // for timer0  ; interrupt reg initilization

 TRISA = 0xFF;     // port A as input

      Lcd_Cmd(_LCD_CLEAR);                    // Clear display
      Lcd_Cmd(_LCD_CURSOR_OFF);
      Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT);
      Lcd_Out(1,1,CopyConst2Ram(msg,fv));   // Write text in first row
    
      
     T1CON.TMR1ON=0;
     PIR1.TMR1IF=0;
     TMR1L=0XEE;    // value loaded for 1 second delay.
     TMR1H=0X85;
              j==1;
              frq=0;
              while(j==1)
              {
                         while(G_freq==1)
                            {G++;}
                            
                                    IntToStr(G,string);
                                    Lcd_Out(2,2,string);
                                    Lcd_Out_CP("Hz");
                            
                         if(mains==P)
                         {j=0;}
                         
                         if(frq==1)
                         {
                             k++;
                             T1CON.TMR1ON=0;
                             PIR1.TMR1IF=0;
                             TMR1L=0XEE; // value loaded for 1 second delay.
                             TMR1H=0X85;
                                if(k=4)
                                  {
                                    IntToStr(G,string);
                                    Lcd_Out(2,2,string);
                                    Lcd_Out_CP("Hz");
                                    Delay_ms(1000);
                                    G=0;
                                    k=0;
                                   }
                             T1CON.TMR1ON=1;
                             frq=0;
                         }
              }
}

where
Code:
#define genr PORTA.F0
#define mains PORTA.F1
#define G_freq PORTA.F2

const char fv[] = "Frequency  Volts";
unsigned char frq=0;
unsigned int j=1,G=0,k=0;
 

You have to use TOCKI pin to count pulses. There is only one interrupt RB0. How can you use RA2?
 

You have to use TOCKI pin to count pulses. There is only one interrupt RB0. How can you use RA2?

acctually a developed hardware is given to me by the company for that i have to program the microcontroller. they have used two pins RA2 and RA3 , RA2 is i think for frequency and i don't know the other's purpose. plz see the schemetic below and analyze the port A.

ATS Schemetic highlighted.png
 

Attachments

  • ATS Schemetic.png
    ATS Schemetic.png
    597.9 KB · Views: 57
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top