Measuring the frequency of a sine wave

Andrew Cowan

Senior Member
Hi all.

I am trying to measure the spped of an axle.

I have a slotted optoisolator, with a stripy disc going through it.

Looking at the signal on a scope, as the axle turns, a sine wave is produced.

I tried to use the COUNT command to measure the number per 200ms, but it gives very erratic results. I think this is due to the input being a sine wave - it looks for a low to high transition every 10uS. In a sine wave, there is never a definite low to high change - it is a slow variable process so it usually misses it.

When it should have been getting around 200 counts, it was getting 10 or so.

I haven't tried using PULSIN, but I imagine it would have the same problem.

In that case, I would need to make the signal digital. The complex way is using an op-amp. Would a schmitt trigger or something be an easier way?

Thanks for any suggestions,

A
 

Andrew Cowan

Senior Member
eclectic - I think the 4096 Jeremy used also has TTL inputs.

hippy - sound like a good idea - I'll try that on Monday. I was using pins 1 on an 08M - maybe the schmitt will help.

A
 

moxhamj

New Member
"Looking at the signal on a scope, as the axle turns, a sine wave is produced."

I guess it could be a sine wave or close to it, thinking of how a slot traces out a circle and how the light will go through that slot. So you need to clean up the edges. You can built a schmitt trigger out of one op amp and two resistors with some positive feedback. Or use just one gate from a 74HC14 (or any 74xx14). That chip will set you back 35c from Futurlec.

Hippy, does your post suggest that there is a schmitt trigger pin already on a picaxe? If so I have missed that feature, and a very useful feature it would be, because then you wouldn't need an external schmitt trigger.
 

Andrew Cowan

Senior Member
Jeremy:
My test circuit is a 1Mhz crystal being divided by 4096, by a CD4040BE 12-stage ripple-carry binary counter/divider, whitch then goes to input 0 on my 18X PICAXE chip.
I'll try using a Schmitt pin, if that doesn't help, I will try a 74HC14 or a 40106.As far as I can see, those would be one component solutions.

The op-amp includes a darlington pair on the output. The reason it is a sinwave (as far as I can work out), is that the light beam is about 0.7mm wide. As the disc approaches, it blocks 1/4 of the beam, then 1/2, then 3/4 etc, making the transistor switch on more and more. The same happens when it unblocks the sensor.

A
 
Last edited:

Jeremy Leach

Senior Member
I don't think I even thought about the type of input when I wrote that old post, which was more about how to display a frequency ;)

Perhaps increasing the gain of the opto-detector (if possible) might help too, because it might give sharper edges and greater output level. Just a thought.
 

Andrew Cowan

Senior Member
To increase the gain, I can increase the value of the resistor driving the IR LED.

The datasheet calls for it to be driven at 50mA, but I found that at 50mA, even cardboard can not block it.

I am running it at 1.5mA, which seems to work well. I could try less although it may mean that the darlington never switches fully on. The darlington is built into the slotted opto, so I can't change the transistors.

A
 

Jeremy Leach

Senior Member
Hold on, I think we're getting somewhere...

So you've got an LED/ detector setup, and the LED should be driven with 50mA and you are driving it with 1.5mA ?! That LED must be pretty dim then (if you could see it!), and no wonder you don't get very sharp edges.

I can appreciate you might need to drop the brightness of the LED a bit, but not as much as you've done.
 
Last edited:

MFB

Senior Member
The rise and fall time of the ‘pulse’ from the opto-coupler will depend to a large extent on the value of the collector pull-up (to 5V) resistor and the capacitive load of the cable to the PICAXE. Decreasing the value of the collector pull-up resistor will improve the shape of the output pulse but reduce the couplers sensitivity. It will therefore be necessary to increase the current through the LED.

Even if a clean pulse is generated by the opto-coupler, a Schmitt input will still be required to reduce the possibility of counting noise pickup. In addition, an unfortunate characteristic of Darlington transistors is that they reduce the available noise margin because their output cannot swing below about 700mV.
 

moxhamj

New Member
A schmitt will certainly make things cleaner. One thing that would be helpful would be the voltages on the trace. If it is a sinewave, how many volts does it vary by? I'm just thinking how that would fit with the volts that a schmitt triggers on.
 

Andrew Cowan

Senior Member
The output varies between 0V and floating. Using a pullup resistor makes up a 6V potential difference.

I have remembered that when I connected it to the PIC, I increased the drive current of the LED to 3mA. At any more than this, the light shines through my wheel. I'll do some more tests and measurements with a scope on Monday.

When I connected it to the scope (and saw the sine wave), I had no pull up resistor (not sure why it worked then - maybe the scope has a low impedance?). I'll experiment with a lower pullup - currently I am using 10K.

If you put an LED between the output and 5V (with a 100 ohm protective), you can see it slowly getting brighter then less bright as you turn the axle.

I'll also try changing the protective resistor on the IR LED, although as I said before, if it is much brighter, it won't ever turn off fully.

A
 
Last edited:
Top