frequency counter

Discussion in 'Embedded Systems and Microcontrollers' started by onlyvinod56, Aug 20, 2013.

  1. onlyvinod56

    Thread Starter Active Member

    Oct 14, 2008
    362
    1
    Hello.

    This is my first post under micro controllers section.
    I want to design an LCR meter using 89s52.(because i have that programmer).

    I need to measure the frequency generated by the opamp for the specific LC elements. I started writing a code. (attachment 1).

    I used timer 0 as counter. initialized TL0 and TH0; started TR0=1;
    It is tested with a clock pulse given to the T0 pin.
    I am not getting idea that how to stop the counter(TR0=0) for a given interval of time.

    for example, i want count a 1KHz pulses / 1millisecond. how to specify the 1 ms in code.

    To see the count i used an 16x2 LCD.

    code:

    Code ( (Unknown Language)):
    1.  
    2. #include<reg51.h>
    3. sbit rs=P3^7;
    4. sbit en=P3^6;
    5. void lcdcmd(char value);
    6. void lcddata(char value);
    7. void delay();
    8. void main()
    9. {
    10. int x,a,b,c,d;
    11. T0=1;
    12. TMOD=0x05;
    13. TL0=0;
    14. TH0=0;
    15. while(1)
    16. {
    17.  
    18. TR0=1;
    19. x=TL0;
    20.  
    21. //while(TF0==0);
    22. //TR0=0;
    23. TF0=0;
    24. a=x/100;
    25. b=x%100;
    26. c=b/10;
    27. d=b%10;
    28.  
    29.  
    30. lcdcmd(0x38);
    31. lcdcmd(0x0e);
    32. lcdcmd(0x01);
    33. delay();
    34. lcddata(a+0x30);
    35. delay();
    36. lcddata(c+0x30);
    37. delay();
    38. lcddata(d+0x30);
    39. delay();
    40. }
    41. }
    42. void lcdcmd(char value)
    43. {
    44. P2=value;
    45. rs=0;
    46. en=1;
    47. delay();
    48. en=0;
    49. }
    50. void lcddata(char value)
    51. {
    52. P2=value;
    53. rs=1;
    54. en=1;
    55. delay();
    56. en=0;
    57. }
    58. void delay()
    59. {
    60. int i,j;
    61. for(i=0;i<=100;i++)
    62. for(j=0;j<=100;j++);
    63. }
    64.  
     
    Last edited by a moderator: Aug 20, 2013
  2. pavans2510

    New Member

    Aug 27, 2013
    3
    1
    Hi Vinod,
    You can use another timer to generate an overflow interrupt (or WDT) for regular interval that you want then inside that interrupt you can start or stop the counter.
     
Loading...