Knowledge Base

An anemometer (wind speed gauge) sensor produces an output frequency between 0Hz and 125Hz. The equation for wind speed is

Wind speed = (Hz x 0.765) + 0.35 in meters/second

The following program will read the anemometer and display wind speed in mph.

;Anemometer

                LaunchTask      Anemometer
                RunTasksForever

;===== Anemometer task ============

iAnemometer     iEQU            0       ;Sensor connected to input 0

Anemometer:
                OBCB_StartA     iAnemometer     ;Start counting in A phase
An_B:
                YieldTask
                OBCB_GoIfB      An_B    ;Wait for A phase ...
                                        ; ... Counting has started

                OBCB_StopB      iAnemometer     ;Stop counting in B phase

An_A:
                YieldTask
                OBCB_GoIfA      An_A            ;Wait for B phase

;In B phase: Read out and reset

                OBCB_fRdClr     iAnemometer     ;Frequency (Hz) in W
                fLoadQ          0.765
                fMUL
                fLoadQ          0.35
                fADD                            ;Speed in m/s

                fLoadQ          3600
                fMUL                            ;m/h
                fLoadQ          1609.344        ;meters/mile
                fSwap
                fDIV                            ;mph

                OBLCD_SetCur    0,0
                OBLCD_fDispW    4,1
                OBLCD_Text      "mph"
                GoTo            Anemometer

The basic principle of frequency measurement is this:

  1. During phase B, you instruct it to start counting at the start of phase A.
  2. Wait for phase A
  3. During phase A, instruct it to stop counting at the start of phase B.
  4. Wait for phase B
  5. During phase B, read out and process the result, then loop (back to step 1).

Chances are that with this procedure the very first reading will be wrong. The next example has some initial synchronization to prevent that.