Frequency detector via micro-controller?

Thread Starter

nightcrawler218

Joined Dec 24, 2012
26
Frequency detector via micro-controller?

I have a square wave generated by a 555 multivibrator. I want to detect its frequency via ATMEL 89c51(preferable) or any other microcontroller. can anybody kindly give me some hints to make it happen or tell the steps to make it happen.

I know the basics of analog electronics a bit BUT new in the digital electronics & micro-controller field. kindly help me.
 

MrChips

Joined Oct 2, 2009
30,824
Not a problem. Frequency measurement is a common task or exercise when learning to program a MCU.

Tell us the frequency range of the 555 multivibrator, how many digits of readout and decimal places you need and what kind of accuracy.
 
Last edited:

kubeek

Joined Sep 20, 2005
5,795
You can feed your input to one of the timers, if you uC has one, and then use the timer facilities to measure the frequency. You will have to read the datasheet to see how to use it.
 

IraqiGeek

Joined Dec 25, 2012
4
as kubeek said, you can use a mcu timer. I'm not familiar with 8051s but if you use an ATMega (arduino or clones) you can set connect the 555 output to one of the external interrupts of the mcu and set the interrupt to trigger on the rising edge. In the ISR, read the value of the the 16-bit timer, divide by the mcu frequency (which gives you the frequency of the input wave) and at the end of the ISR zero the 16-bit timer.

just google arduino external interrupts to see how they work. They're not that hard :)
 

Thread Starter

nightcrawler218

Joined Dec 24, 2012
26
Thanks for your kind response.

Actually I am trying to measure temperature from a remote place using light (on-off pulses). Let me explain it to you.

There are 2 parts of the project.
1.Transmitter
2. Receiver

In the transmitter part I am just using a 555 astable mode multi-vibrator & one of the resistance will be replaced by a thermistor. Now according to the change of temperature, the resistance of the thermistor will change as well as the frequency of the output. The output is connected to a 5mW laser pointer to send the on off signal to a distant place (say 200 meters).

In the receiver part there will be 2 parts
1. Analog
2. Digital

In the receiver part a photo transistor is used just to decode the on off light pulse into another square wave or on-off wave. may be a capacitor will be applied to make the square wave a triangular one.

I have finished the above portion, now the problem arises. now I want to calculate the frequency of the on off signal via a micro controller and with that frequency I want to calculate the resistance of the thermistor. I have a datasheet of the temp-resist relationship of the thermistor.

f=[1.44/(R1+2*R2)*C] I will be using very low frequency for better accuracy, in Hz range

in the RECEIVER part I want to detect the frequency & calculate the unknown R2(thermistor) via microcontroller. the datasheet will be added to the micro controller so finally the matched temperature can be displayed in LCD.

I am stuck at the microcontroller portion.
:-/
 

MrChips

Joined Oct 2, 2009
30,824
That is exactly the reason I asked for you to specify the frequency range.

It is easier and more accurate to measure frequency that is greater than, say, 1000Hz.
Below this, it is better to measure period. Hence, if your frequency is in the 100Hz range you should measure period. This is done on MCUs with timer modules using something called input capture. If you do not know what this is, I can explain later.

Secondly, it is always good to give us the big picture as you have done in your second post. This allows us to provide better answers to your problem.

Thirdly, forget about the equations, formulas and datasheet. Once you get your MCU reading the period with sufficient stability and resolution, you will simply calibrate the entire system by taking readings that span the entire temperature range of your interest. Then we will take it from there.
 

kubeek

Joined Sep 20, 2005
5,795
I suggest you use an atmega, they are pretty common and there are lots of examples lying on the internet. You should also decide what lcd you want to use, the easiest would be some 16x2 lcd or similar, with built-in controller.
 

Thread Starter

nightcrawler218

Joined Dec 24, 2012
26
That is exactly the reason I asked for you to specify the frequency range.

It is easier and more accurate to measure frequency that is greater than, say, 1000Hz.
Below this, it is better to measure period. Hence, if your frequency is in the 100Hz range you should measure period. This is done on MCUs with timer modules using something called input capture. If you do not know what this is, I can explain later.

Secondly, it is always good to give us the big picture as you have done in your second post. This allows us to provide better answers to your problem.

Thirdly, forget about the equations, formulas and datasheet. Once you get your MCU reading the period with sufficient stability and resolution, you will simply calibrate the entire system by taking readings that span the entire temperature range of your interest. Then we will take it from there.

Hi, I have googled about the input capture. Will you kindly explain how to use the output of the comparator (just to make sure that the output is absolute low & high, say .1v & 3v) to detect the period using input capture. Is it a device with a standalone clock or should I incorporate an external 8 pin RTC to do the measurement.??

receiver & transmitter diagram links are attached with this post.

Transmitter - http://img834.imageshack.us/img834/8467/transmitter.jpg (the LED is replaced by a 5mW RED Laser pointer)

Receiver - http://img217.imageshack.us/img217/6778/receiver.jpg
(a 10k pot may be used to determine the lower reference voltage of the comparator)
 

MrChips

Joined Oct 2, 2009
30,824
Timer module input capture does not require an analog comparator.

A digital signal is fed into an input pin that is connected to the timer module.
When an input transition occurs, the current time/count in a continuously running counter is captured. An interrupt is generated and the interrupt service handler will record the time/count that was captured.

On the next input transition (or selected rising or falling edge), an second input capture event occurs, similar to the previous event. A second time/count number is captured and recorded. The difference between the two recordings will give you the time interval between events. From this number, one can determine the frequency of the signal and hence the temperature of the thermistor.
 

THE_RB

Joined Feb 11, 2008
5,438
Assuming you are going to average a number of period samples (which you SHOULD do) then you can even do the capturing manually;

1. check input pin for digital input / event
2. read timer value
3. period = timer value - last timer value
4. add period to total
5. repeat for 16,32 or 64 times etc

Any small period error caused by the manual capture delay will be negated on the next capture event so there will be no significant average error.
 
Top