Simple frequency counter, run without modification on Nucleo board, Input pin PA0, PA1, PB3. Only for STM32F4 series (Tested on Nucleo-F401RE,-F411RE and F446RE)
Dependents: Frequency_Counter_for_STM32F4xx
see /users/kenjiArai/notebook/frequency-counters/
Diff: freq_counter.h
- Revision:
- 4:3c589d2aad5c
- Parent:
- 3:61bea8bfe404
--- a/freq_counter.h Wed Oct 22 00:35:23 2014 +0000 +++ b/freq_counter.h Mon Jan 13 07:41:08 2020 +0000 @@ -2,17 +2,12 @@ * 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 22nd, 2014 + * Copyright (c) 2014,'15,'20 Kenji Arai / JH1PJL + * http://www7b.biglobe.ne.jp/~kenjia/ + * https://os.mbed.com/users/kenjiArai/ + * Created: October 18th, 2014 + * Revised: January 13th, 2020 * - * 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 @@ -20,21 +15,22 @@ #include "mbed.h" +/* + CAUTION: Direct access to the CPU Timer module!! + No way to change pin assign and timer module + Tested on Nucleo F401RE, F411RE & F446RE + Tested on mbed-os5.15.0 & mbed-2.0.165 + + Input pin selection -> Only PA0, PA1, PB3 + */ + /** Frequency Counter * - * CAUTION: Direct access to the CPU Timer module!! - * No way to change pin assign and timer module, - * mbed LPC1768 -> p30, - * mbed LPC1114FN28 -> dp14, - * Nucleo F401RE & Nucleo F411RE -> PA_0/A0 - * * @code * #include "mbed.h" * #include "freq_counter.h" - * - * F_COUNTER fc(p30); // for LPC1768 - * //F_COUNTER fc(dp14); // for LPC1114 - * //F_COUNTER fc(PA_0); // for F401 & F411 + * + * F_COUNTER fc(PA_0); // for F401,F411 & F446 * * int main() { * uint32_t frequency = 0; @@ -52,22 +48,40 @@ public: /** Configure data pin * @param frequency counter input pin + * @param gate time (seconds) */ - F_COUNTER(PinName f_in); + F_COUNTER(PinName f_in, float gate_time = 1.0f); /** Read measured frequency - * @param gate time - * @return measured frequency + * @param none + * @return measured frequency (minus = input pin is incorrect) */ - uint32_t read_frequency(float gate_time); + int32_t read_frequency(void); + + /** Set new gate time + * @param new gate time (seconds) + * @return none + */ + void set_gate_time(float gat_time); + + /** Read input assign number + * @param none + * @return Pin number + */ + uint32_t read_pin(); protected: DigitalIn _pin; + Ticker _t; void initialize(void); + void irq(void); private: - uint32_t freq; + uint32_t pin_num; + float gt; + int32_t freq_raw; + bool new_input; };