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/

Revision:
2:54c05b0a117a
Parent:
1:fd2e1c853ab6
Child:
3:61bea8bfe404
--- a/freq_counter.cpp	Tue Oct 21 03:44:46 2014 +0000
+++ b/freq_counter.cpp	Tue Oct 21 11:19:54 2014 +0000
@@ -5,7 +5,7 @@
  * Copyright (c) 2014 Kenji Arai / JH1PJL
  *  http://www.page.sannet.ne.jp/kenjia/index.html
  *  http://mbed.org/users/kenjiArai/
- *      Addition and Modification
+ *      Additional functions and modification
  *      started: October   18th, 2014
  *      Revised: October   21st, 2014
  *
@@ -15,6 +15,13 @@
  * 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.
  */
+//-------------------------------------------------------------------------------------------------
+//  Reference program
+//-------------------------------------------------------------------------------------------------
+//  5MHzOSC
+//      http://developer.mbed.org/users/mio/code/5MHzOSC/
+//  by fuyono sakura
+//      http://developer.mbed.org/users/mio/
 
 #include "mbed.h"
 #include "freq_counter.h"
@@ -33,7 +40,7 @@
     LPC_TIM2->CTCR = 1;             // 4)Count on riging edge Cap3[0]
     LPC_TIM2->CCR  = 0;             // 5)Input Capture Disabled
     LPC_TIM2->TCR  = 1;             // 6)Counter Start (bit1<=0,bit0<=1)
-#elif defined(TARGET_NUCLEO_F401RE)
+#elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
     // PA0 -> Counter frequency input pin as Timer2 TI1
     GPIOA->AFR[0] &= 0xfffffff0;
     GPIOA->AFR[0] |= GPIO_AF1_TIM2;
@@ -62,7 +69,7 @@
     wait(gate_time);                // Gate time for count
     freq = LPC_TIM2->TC;
     return freq;
-#elif defined(TARGET_NUCLEO_F401RE)
+#elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
     TIM2->CNT = 0;
     wait(gate_time);                // Gate time for count
     freq = TIM2->CNT;
@@ -73,15 +80,6 @@
 }
 
 #if 0
-//-------------------------------------------------------------------------------------------------
-//  Reference program
-//-------------------------------------------------------------------------------------------------
-
-//  5MHzOSC
-//      http://developer.mbed.org/users/mio/code/5MHzOSC/
-//  by fuyono sakura
-//      http://developer.mbed.org/users/mio/
-
 //
 //  CLOCK OUT to PWM1[6] Sample with Freq Counter using Cap2.0
 //  For LPC1768-mbed