Frequency Counter Library. Only for mbed LPC1768, mbed LPC1114FN28, Nucleo-F401 and Nucleo-F411. No way to change pin assign.

Dependents:   Frequency_Counter Frequency_wind_speed_measure Frequency_counter_wind_speed

Please refer following page.
http://developer.mbed.org/users/kenjiArai/notebook/simple-frequency-counter/

freq_counter.h

Committer:
kenjiArai
Date:
2014-10-21
Revision:
1:fd2e1c853ab6
Parent:
0:83661d0d09c0
Child:
2:54c05b0a117a

File content as of revision 1:fd2e1c853ab6:

/*
 * mbed Library program
 *      Frequency Counter Hardware relataed program
 *
 * Copyright (c) 2014 Kenji Arai / JH1PJL
 *  http://www.page.sannet.ne.jp/kenjia/index.html
 *  http://mbed.org/users/kenjiArai/
 *      Created: October   18th, 2014
 *      Revised: October   21st, 2014
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#ifndef        MBED_F_COUNTER
#define        MBED_F_COUNTER

#include "mbed.h"

/** Frequency Counter
 *
 *  CAUTION: Direct access to the CPU Timer module!!
 *           No way to change pin assign and timer module
 *
 * @code
 * #include "mbed.h"
 * #include "freq_counter.h"
 *
 * F_COUNTER fc(p30);
 *
 * int main() {
 *   uint32_t frequency = 0;
 *
 *   while(true) {
 *      freqency = fc.read_frequency(1.0);  // gate time: 1 sec
 *      printf("%d [Hz]", frequency);
 *   }
 * }
 * @endcode
 */

class F_COUNTER
{
public:
    /** Configure data pin
      * @param frequency counter input pin
      */
    F_COUNTER(PinName f_in);

    /** Read measured frequency
      * @param gate time
      * @return measured frequency
      */
    uint32_t read_frequency(float gate_time);

protected:
    DigitalIn _pin;

    void initialize(void);

private:
    uint32_t freq;

};

#endif  //  MBED_F_COUNTER