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.

Freq counter using 8051...

Status
Not open for further replies.

sadashiv_sm

Member level 3
Member level 3
Joined
Mar 23, 2004
Messages
64
Helped
6
Reputation
12
Reaction score
3
Trophy points
1,288
Location
Mumbai,India
Activity points
549
Hi
I want to buid a frequency counter using 8051...
what is the max freq we can count using 8051...
I have seen PIC based projects but not getting 8051 based app note...

My freq requairement is 40MHz...
if any body has some notes regarding this forward me or give mr rep...

Thanks

Sadashiv
 

Hi ,
its very difficult to count 40 MHz with an 8051 chip. As our traditional 8051 works at 32MHz that to it is divided by 12 internally. And also you have to write timer overflow routine. But i don't know if it can serve your purpose of 40 MHz.
 
40MHZ?! I don't think that it could be possible with 8051 alone, you've got to use some sort of prescaler (divider) to get it to sub-megahertz region, since the machine cycle on the standard 8051 core is 1usec, on the atmel's 24MHz versions, it gets to 500nsec...
 
Yes we can do with it. Just configure the 16 bit counter to count external pulses. feed the incoming frequency after waveshaping to the count input pin. Now, configure another timer for some 100mS or so and start both at a time. If you need precission measurement add the calculated delay between enabling both of them. Now, handle the counter interrupt carefully, each rollover should increment another variable in RAM. Finally when the timer of 100mS expires, stop the counter and read the value from the counter & add up to the sum of the (total_rollover_cycles * rollover_value_of_the_counter) + last counter reading. Now, the value multiplied by the 10 (since 100mS is timeconstant), gives you the frequency in Hz. The longer the time constant the precise will be the measurement. But, don't forget to compensate the execution delays. Need further information contact me at just_srinu@yahoo.com. I'll try to post sample schematics & code for 89c52 µC. I did this a long time back as some demonstration project, but of course it is 10MHz max. The only consideration is the propagation delay & wire delays of the counter on chip should not cause the input cycles lost before counting. Hope this helps...
 
Hi Guttina

The information is very useful for me and I Plan to implement this in PIC16f72.
What do u think PIC is better or Atmel is better in this context?

Regards
Gopi
 

You cannot do it with an 8051, since the counters are synchronized with the internal clock and the maximum frequency is limited to 1/24 of the crystal clock (or 1/2 of core clock). That means that for a typical 12MHz crystal, the maximum frequency you can measure is 0.5MHz.

The PIC's prescaler is strictly hardware and it can count up to 50MHz.
There is also an appnote from Microchip on how to build a frequecy counter. It's a good starting point, although I probably do a few things differently. www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1824&appnote=en011033
 

I think that, the best way to measure freq using AT89C51 is to use prescaler before feeding you pulse to MCU pins.

For ex. if frequency range is 1kHz to 40Mhz, you can devide it for 1000, so your range is only 1Hz to 40Khz. It's easy to measure this range using 89C51 (Of course, your prescaler block is not simple).

The last thing to do is to display your frequency!
 

hello guttinasrinivas it's a very good technique, can you please post source code to me, or you may send it to me by mail
ashafee@ieee.org
thanks
 

Yes, if i'm not mistaken, one could only use 8051 counter pin for frequency below 1 Mhz. Because it use sampling method to increment the internal counter register. I've done this project frequency counter before, at my job training.
I also use guttinasrinivas's technique too for the project, but instead of using 100ms timeconstants, I use 1 s timeconstants.
Yes, if you want to use the 8051 counter for 40 MHz, you must use a prescaler. For my previous project, I use the cheap 4 bit updown counter as prescaler, and my supervisor teach me a quite tricky technique to use the counter for about 15-16 prescaler constants.
If you would like to know, I will send you the schematic but I must find my report first :D

Regards,

Leo
 

VVV
The idea is to use the timer/counter in external counter mode. Not sampling. Hope it makes clear.

Shafee001
I'll send you the code soon. Very recent time, my desktop hard disk crashed & hence my machine is out of order for a while. Please give me some time, I have to recover them from back up.

Thanks
Srinu

Added after 2 hours 8 minutes:

Oops! I saw the datasheet of Atmel 89c51. It states the count input is polled once a machine cycle. Sorry for saying this, but the method I mentioned could not be used with Atmel controllers.

Alternatively, as the others are suggesting, use a prescalar counter, for deviding the input frequency and connect the carry out of the counter to the external interrupt input. When the counter rolls over, it generates an interrupt and count all the interrupts. Finally, when the time base period expires, read the value remaining in the counter through some port & the result is:

Frequency = (1/time_base)*((total_interrupts_counted*(2^bit_length_of_counter))+remaining_value_in_counter)

Let me find out all my project details once, I restore my back up. I'll upload the schematics & code too.

Srinu
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top