Frequency counter using GPS 1PPS signal and temperature controlled 50MHz Base clock. Ported from F411 Frequency Counter.

Dependencies:   QEI DRV8830 PID ADT7410 TextLCD Frq_cuntr_Nucleo-F746ZG RingBuffer

Fork of Frequency_Counter_w_GPS_1PPS by Kenji Arai

Please refer following.
/users/kenjiArai/notebook/frequency-counters/

Revision:
7:0c09d29c4cf3
Parent:
6:44c2bcbdd77b
Child:
8:7b033903c8fb
diff -r 44c2bcbdd77b -r 0c09d29c4cf3 main.cpp
--- a/main.cpp	Tue Oct 21 12:37:05 2014 +0000
+++ b/main.cpp	Wed Oct 22 00:41:14 2014 +0000
@@ -5,7 +5,7 @@
  *  http://www.page.sannet.ne.jp/kenjia/index.html
  *  http://mbed.org/users/kenjiArai/
  *      Created: October   18th, 2014
- *      Revised: October   21st, 2014
+ *      Revised: October   22nd, 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
@@ -15,8 +15,8 @@
  */
 
 #define USE_COM         // use Communication with PC(UART)
-//#define USE_TEXT_LCD    // use Text LCD/I2C Interface
-//#define USE_GRAP_LCD    // use Grafic LCD/SPI interface
+#define USE_TEXT_LCD    // use Text LCD/I2C Interface
+#define USE_GRAP_LCD    // use Grafic LCD/SPI interface
 
 //  Include ---------------------------------------------------------------------------------------
 #include "mbed.h"
@@ -46,14 +46,20 @@
 #if defined(TARGET_LPC1768)
 // LPC1768 Frequency example
 // Outout mbed's "PWM6" pin to 96MHZ/19 = 5.052MHz (Approx)
-#define PWM_EAMPLE()    PWM6_SETCLK(19)
+#define CLK_REFRENCE()  PWM6_SETCLK(19)
 // Outout mbed's "PWM6" pin to 96MHZ/96 = 1.000MHz (Approx)
-//#define PWM_EAMPLE()    PWM6_SETCLK(96)
+//#define CLK_REFRENCE()    PWM6_SETCLK(96)
+#elif defined(TARGET_LPC1114)
+#define led_not_zero    temp_ram
+#define led_01          temp_ram
+#define led_10          temp_ram
+#define CLK_REFRENCE()  clock_out()
+#warning "Don't forget LPC1114 runs with internal clock. Measurement data is not accurate!!"
 #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
 #define led_not_zero    temp_ram
 #define led_01          temp_ram
 #define led_10          temp_ram
-#define PWM_EAMPLE()    port_mco1_mco2_set()
+#define CLK_REFRENCE()  port_mco1_mco2_set()
 #else
 #error "No support for this CPU"
 #endif
@@ -78,6 +84,22 @@
 PwmOut fmclck(p21);                 // for RESERVE pin21 as PWM1[6]
 F_COUNTER fc(p30);
 
+#elif defined(TARGET_LPC1114)
+
+DigitalOut led_gate(LED2);
+DigitalIn  sw_01(dp25);
+DigitalIn  sw_10(dp26);
+Serial pc(dp16,dp15);       // Communication with Host
+I2C i2cBus(dp5,dp27);       // SDA, SCL
+#if defined(USE_TEXT_LCD)
+TextLCD_I2C_N lcd(&i2cBus, 0x7c, TextLCD::LCD8x2);  // LCD(Akizuki AQM0802A)
+#endif
+#if defined(USE_GRAP_LCD)
+ST7565 glcd(dp2, dp6, dp10, dp4, dp9, ST7565::AQM1248A); // mosi, sck, reset, a0, ncs
+#endif
+F_COUNTER fc(dp14);
+// dp24 uses for CLOCKOUT -> Clock output for checking
+
 #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
 
 DigitalOut led_gate(LED1);
@@ -115,6 +137,7 @@
 //  Control Program
 //-------------------------------------------------------------------------------------------------
 #if defined(TARGET_LPC1768)
+
 // Clock Output From pin21(PWM6)
 // Set Clock Freq with div.
 // if mbed is running at 96MHz, div is set 96 to Get 1MHz.
@@ -128,7 +151,21 @@
     LPC_PWM1->LER |= 1;                 // 4)Start updating at next period start
     LPC_PWM1->TCR = (1 << 0) || (1 << 3); // 5)Enable counter and PWM
 }
+
+#elif defined(TARGET_LPC1114)
+
+// CLOCKOUT from pin24(dp18)
+//      Freq = 48MHz/4 = 12MHz
+void clock_out(void)
+{
+    LPC_SYSCON->CLKOUTCLKSEL = 3;       // System clock
+    LPC_SYSCON->CLKOUTDIV = 4;          // div 1/4
+    LPC_IOCON->PIO0_1 = 1;              // select CLKOUT to P0_1(pin24)/dp18
+    LPC_SYSCON->CLKOUTUEN = 1;          // enable output
+}
+
 #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
+
 void port_mco1_mco2_set(void)
 {
     uint32_t temp = 0x00;
@@ -151,15 +188,11 @@
     //             MCO2          MCO2PRE       MCO1PRE       MCO1
     RCC->CFGR |= (0x0 << 30) + (0x6 << 27) + (0x6 << 24) + (0x3 << 22);
 }
+
 #else
 #error "No support for this CPU"
 #endif
 
-void example_freq_out(void)
-{
-    PWM_EAMPLE();
-}
-
 void read_sw_and_set_gate_time(void)
 {
     if (sw_10) {
@@ -208,15 +241,19 @@
 #endif
 #if defined(USE_GRAP_LCD)
     glcd.cls();
-    glcd.set_contrast(0x06);
     glcd.locate(0, 0);
     glcd.printf("--- Frequency Counter --\r\n");
     glcd.printf("     Kenji Arai / JH1PJL\r\n" );
     glcd.printf("                        \r\n");
 #if defined(TARGET_LPC1768)
+    glcd.set_contrast(0x06);
     glcd.printf(" Input: P30 PWM out: P21\r\n" );
     glcd.printf(" LED1:Gate  LED2:signal \r\n" );
+#elif defined(TARGET_LPC1114)
+    glcd.set_contrast(0x01);
+    glcd.printf(" LED2:Gate              " );
 #elif defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE)
+    glcd.set_contrast(0x06);
     glcd.printf(" Input: PA0 PWM out: PA8\r\n" );
     glcd.printf(" LED1:Gate              \r\n" );
 #else
@@ -229,8 +266,8 @@
     //        12345678
     lcd.puts("        ");
 #endif
-    // Set PWM for example
-    example_freq_out();
+    // Set Internalclock for reference
+    CLK_REFRENCE();
     freqency = 0;
     while(true) {
         led_gate = 1;