Maker Pro
Maker Pro

Phase detect compare

uvtal

Jun 30, 2013
3
Joined
Jun 30, 2013
Messages
3
Hi

In order to measure wind direction from an anemometer that I have, I need to measure a phase changes between pulses. it is explained in the attached document.
I want the result (output) of the phase change will be something like range of 0-5V
I noticed there are devices for digital phase detection, are these the right devices to use?
If not which devices should I use?
A sample diagram of how to use them will be a great help.

Thanks
Tal
 

Attachments

  • Anemometer.zip
    72.6 KB · Views: 70

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Hi uvtal and welcome to the electronics point forums :)

That document is poorly written, as well as wrong in places. The relevant section is:

Direction is calculated as the relative timing (phase relationship) between contact closures of the two reed switches. This is a non-linear, sinusoidal relationship. We regard repeated actuation of the speed reed as the reference and arbitrarily define "North" as the vane orientation that causes the two reed switches to close at the same time. "South" is the vane orientation that causes the direction reed to close exactly halfway between two closures of the speed reed. Note that the open and closed intervals are not necessarily equal and may differ between the two switches.

This seems to be saying to me that the spinning anemometer has a magnet attached, and that this magnet operates two independent reed switches: the "speed" reed, which is mounted in a fixed position, and the "direction" reed, which is mounted in the wind vane.

When the wind vane is pointing in the nominal North direction, the direction reed is rotationally in the same position as the speed reed, and they close and open at roughly the same times. When the wind vane is pointing in the nominal South direction, the direction reed is rotationally on the opposite side from the speed reed, and they open and close roughly at opposite times.

Processing this signal to determine wind direction would be best done with a microcontroller, because several characteristics of the signal are poorly defined. The signals are not sinusoidal, as claimed in the document, so some analogue phase comparison methods may not be usable. The frequency of the signals will vary constantly as the wind speed varies.

If you're interested in using a microcontroller for this process, I can help with the design of the code. Something small like an Atmel AVR or a Microchip PIC would be well-suited to this application. A crystal-controlled clock would be needed if you want good speed accuracy. Output could be a serial data stream and/or a PWM stream and/or analogue outputs, if the device has a DAC (digital-to-analogue converter).
 

uvtal

Jun 30, 2013
3
Joined
Jun 30, 2013
Messages
3
Hi Kris
Many thanks for your accurate and fast response
I'd rather use electric devices if possible instead of microcontrollers, that's for robustness and price reasons.
Since there is a use of reed switch I guess that "digital phase detector" may do the job, but I don't have any experience with it.

As far as I understand if the wind speed changes and the direction does not change, then the phase between the pulses should relatively remain the same.

Thanks
Tal
 

aharrison

Nov 14, 2010
7
Joined
Nov 14, 2010
Messages
7
Why not use a "D" flip-flop as a direction detector? One sensor is provided to the clock input, and the other to the data input.
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
The problem with using analogue methods is that you can't tell what part of the cycle each microswitch is "up to", because the signal from the microswitch only changes at two points in the cycle.

A normal phase comparer circuit compares the phases of two sinewaves, which are continuous signals. You can't use that kind of circuit with a pulsed signal, especially if (a) the duty cycle is not clearly defined, and (b) the frequency changes constantly.

As far as price (and robustness, for that matter) are concerned, a microcontroller-based solution is far better. A suitable microcontroller will set you back about USD 0.80, and require almost no other components. A discrete solution will require several ICs and will not perform as well as a micro-based solution.

One idea for an analogue solution that comes to mind is a dual-clocked flip-flop that is set on the rising edge from one reed switch, and cleared on the rising edge from the other. If the output of that flip-flop is averaged, it should give a voltage that's linearly proportional to the phase relationship between the two rising edges. The averaging will introduce a delay in the response, and for best performance the averaging time needs to be scaled to the frequency, i.e. the wind speed.

I will have a think about this and draw up a diagram for you.
 

aharrison

Nov 14, 2010
7
Joined
Nov 14, 2010
Messages
7
I thought this application used two on-off reed switches. So it would seem compatible with a flip-flop scheme. You could also add debouncers after the reeds, which can be done in simple hardware. Micros are fine if you have the development tools, but a CD4013BE dual "D" FF is pretty easy to use with no special tools and widely available.
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Yes, debouncing is definitely needed. But I don't think connecting one switch to the clock, and one to the data input, will give any useful result.

The idea I'm working on involves setting the flip-flop on the active-going edge from one reed switch, and clearing it on the active-going edge from the other one.

The output needs to be averaged, and there are some issues there. For example, what happens when the wind vane is pointing directly north and moving slightly? Depending on which reed switch activates first, the flip-flop output will be almost entirely high, or almost entirely low. When it changes from one to the other, the averaged output voltage will travel from one extreme to the other, making it seem that the wind direction is changing rapidly. This is probably unacceptable, and it's the sort of problem that can be managed fairly easily by a software solution.

Some issue like this is inevitable, I think, when you're trying to represent a quantity that ranges from 0 to 360 degrees with a voltage that ranges from (say) 0V to 5V. When the quantity rotates from 359 to 0 degrees, or from 0 to 359 degrees, there is no discontinuity in the angle being measured, but there is the maximum discontinuity in the voltage that represents it.

The other problem I mentioned is that the required smoothing should adapt to the frequency of the signals, which will vary over quite a wide range depending on the wind speed.

If you think you have a solution, please post a schematic and analysis. I would be very interested to see it.
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
Here is a possible non-microcontroller solution.

attachment.php


SW1 and SW2 are the two reed switches; let's say SW1 is the "speed reed" and SW2 is the "angle reed". When a reed switch closes, after a short time (determined by RSn and CDn, the debouncing components) the input of the relevant Schmitt trigger inverter gate will be regarded as low, and the gate's output will go high.

This high-going edge will be passed through CTn and will produce a short positive pulse across RTn, which will pass through DTn and will force the U1C/U1D latch into the appropriate state.

Therefore, the latch is set on active-going transitions of one reed switch, and the latch is reset on active-going transitions of the other reed switch.

The output of the latch therefore represents the time between activations on the reed switches.

This voltage is smoothed by RS and CS, which have a time constant of about 1 second, and the resulting voltage is the output of the circuit, labelled WD (wind direction).

The WD output represents the wind direction. Due North corresponds to 0V and 5V (see below) and due South corresponds to 2.5V. East and West correspond to 1.25V and 3.75V; which way around depends on details of the design of the anemometer which are not specified in the document you linked to. You will have to find this out through trial and error.

As I've mentioned in earlier posts, there are a few problems with this approach.

Ideally, the RS/CS smoothing circuit should adapt its time constant to suit the actual rate of the pulses from the reed switch; this is not simple to do, so I haven't tried to show it here. Provided that the wind speed is high enough to produce at least ten edges on each reed switch per second, the ripple on the WD signal should be reasonably low.

If the wind vane is pointing roughly North and moving slightly, the phase relationship between the two reed switches can jump from one leading the other, to the other leading the first. This will cause the WS output to alternate between 0V and 5V as the lead/lag relationship changes; this would seem to indicate that the wind direction is changing rapidly, but that's not the case.

The output smoothing circuit is a simple resistor-capacitor averager. These take a long time to settle fully to a new value. They move towards the new averaged value at a rate that depends on the difference between the ideal averaged value and the current value; as the averaged value approaches the ideal value, this difference becomes small, and therefore the rate of change also becomes small.

The voltages I've stated assume that U1, the CD40106B, is running from a 5V supply. It will actually run better from a higher voltage; 12V is good. In this case, output voltages will be scaled up accordingly.

U1 can also be a CD4584 or a 74C14. These are just different names for exactly the same IC. You can also use a CD4093B if you tie the unused inputs high.

If you build this circuit, please let me know how it goes. I suspect it may not be good enough for your requirements, but you haven't really stated those, so I can't be sure. As I said before, I think the best solution to this problem is a microcontroller.

Edit:
1. The capacitors marked "FILM" should be metal film or similar types, not ceramic - especially not MLCC (multi-layer ceramic).
2. CS should be shown as an electrolytic, with its top plate being positive.
3. The power connections to U1 are not shown. VCC connects to pin 14 and 0V (the earth symbol) connects to pin 7. Connect a 100 nF decoupling capacitor across those pins; in this case a ceramic or MLCC is fine.
 

Attachments

  • EVTAL.001.GIF
    EVTAL.001.GIF
    7.5 KB · Views: 213
Last edited:

aharrison

Nov 14, 2010
7
Joined
Nov 14, 2010
Messages
7
Yes, now I see what you mean. I had originally assumed that the issue was simply to sense the rotation of a spinning vane, but now I see that this is a weather vane that is controlled by wind direction, and not a propeller like on a wind mill. So, all your points are well-taken, and I agree that the solution may require some greater complexity. Once you need more than a dozen SSI/MSI parts and a dozen discretes, you might as well do it in software with a dedicated programmable IC, since, as you pointed out, it will be less expensive and more flexible.
 

uvtal

Jun 30, 2013
3
Joined
Jun 30, 2013
Messages
3
Well I couldn't expect any better...
So detailed and well explained.
I'll try it at home but it will take me some time.
many many thanks!
Tal
 

KrisBlueNZ

Sadly passed away in 2015
Nov 28, 2011
8,393
Joined
Nov 28, 2011
Messages
8,393
I had originally assumed that the issue was simply to sense the rotation of a spinning vane, but now I see that this is a weather vane that is controlled by wind direction, and not a propeller like on a wind mill.
It's both. There's a spinning anemometer for measuring wind speed, and also a vane that measures wind direction. The "speed reed" switch is mounted in a fixed location, and just picks up the rotation of the anemometer, and I think that the "direction reed" switch is also actuated by the magnet on the anemometer, but is actually mounted on the wind vane.

As the anemometer rotates, it actuates both reed switches. The timing relationship between the actuation of the fixed reed switch and the reed switch on the vane will depend on the angle of the vane relative to the fixed section.

many many thanks!
You're welcome Tal. Good luck!
 
Top