Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG F746_GUI LCD_DISCO_F746NG RingBuffer TS_DISCO_F746NG fc_GPS1PPS_f746_f4xx mbed
Revision 0:52c5dc2b2b68, committed 2016-11-19
- Comitter:
- kenjiArai
- Date:
- Sat Nov 19 05:32:06 2016 +0000
- Commit message:
- Frequency Counter. User interface are used DISCO-F746NG GUI with touch panel.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BSP_DISCO_F746NG.lib Sat Nov 19 05:32:06 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/ST/code/BSP_DISCO_F746NG/#fe313c53cdb5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/F746_GUI.lib Sat Nov 19 05:32:06 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/MikamiUitOpen/code/F746_GUI/#a9cf68d24f40
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/GPS_rcvr/GPSrcvr.cpp Sat Nov 19 05:32:06 2016 +0000
@@ -0,0 +1,386 @@
+/*
+ * mbed Application program / GPS receiver control and 1PPS output
+ *
+ * Copyright (c) 2004,'09,'10,'16 Kenji Arai / JH1PJL
+ * http://www.page.sannet.ne.jp/kenjia/index.html
+ * http://mbed.org/users/kenjiArai/
+ * Created: March 28th, 2004 Kenji Arai
+ * updated: July 25th, 2009 for PIC24USB
+ * updated: January 16th, 2010 change to GPS-GM318
+ * updated: April 24th, 2010 for mbed / NXP LPC1768
+ * Revised: Nomeber 13th, 2016
+ */
+
+// Include --------------------------------------------------------------------
+#include <string.h>
+#include "mbed.h"
+#include "GPSrcvr.h"
+#if defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F446RE)
+#include "iSerial.h"
+#elif defined(TARGET_STM32F746NG)
+#include "RingBuffer.h"
+#endif
+
+// Definition -----------------------------------------------------------------
+//#define USE_DEBUG
+
+#ifdef USE_DEBUG
+#define U_DEBUGBAUD(x) pc.baud(x)
+#define U_DEBUG(...) pc.printf(__VA_ARGS__)
+#define DBG(c) pc.putc(c)
+#else
+#define U_DEBUGBAUD(x) {;}
+#define U_DEBUG(...) {;}
+#define DBG(c) {;}
+#endif
+
+#define GSP_BUF_B (128 * 3)
+#define GPS_BUF_S (128 * 2)
+
+// Object ---------------------------------------------------------------------
+#if defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F446RE)
+DigitalIn gps_rx(PC_7); // for checking GPS RX line
+iSerial gps(NC, PC_7, 0, 1024); // GPS Data receive
+#error "This is only on DISCO-F746NG!!"
+#elif defined(TARGET_STM32F746NG)
+RingBuffer rxbuf(1024); // can receive all information every one sec
+DigitalIn gps_rx(PF_6); // for checking GPS RX line
+Serial gps(NC, PF_6); // GPS Data receive
+#else
+#error "Target is only Nucleo-F411RE(F446RE) or DISCO-F746NG!!!"
+#endif
+
+extern Serial pc;
+
+// RAM ------------------------------------------------------------------------
+bool gps_is_okay_flag;
+uint8_t gps_ready;
+uint8_t gps_status;
+uint8_t gps_rmc_ready;
+char GPS_Buffer[GSP_BUF_B]; //GPS data buffer
+char MsgBuf_RMC[GPS_BUF_S];
+char MsgBuf_GSA[GPS_BUF_S];
+char MsgBuf_GGA[GPS_BUF_S];
+
+// Function prototypes --------------------------------------------------------
+uint8_t check_gps_3d(void);
+uint8_t check_gps_ready(void);
+void get_time_and_date(struct tm *pt);
+void getline_gps(void);
+void gps_data_rcv(void);
+#if defined(TARGET_STM32F746NG)
+void iGPSrcv_initialize(void);
+int iGPS_readable(void);
+int iGPS_getc(void);
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// Receive GPS data using Interrupt handler
+//
+// !!! Takes urgent and dirty solution by due to IRQ restriction
+// on mbed library (reason is unknown as of today)
+// reference source file:stm32f746xx.h
+// under /mbed-dev/targets/cmsis/TARGET_STM/TARGET_NUCLEO_F746ZG
+////////////////////////////////////////////////////////////////////////////////
+#if defined(TARGET_STM32F746NG)
+
+// ------ Interrupt Function ------
+void rx_handler(void)
+{
+ uint32_t reg = UART7->ISR;
+ if (reg && USART_ISR_RXNE){ // data is ready to read
+ UART7->ISR &= ~(USART_ISR_RXNE + USART_ISR_PE + USART_ISR_FE
+ + USART_ISR_NE + USART_ISR_ORE);
+ rxbuf.save((unsigned char)UART7->RDR);
+ }
+}
+
+void iGPSrcv_initialize(void)
+{
+ __disable_irq();
+ UART7->CR1 &= ~(USART_CR1_TE + USART_CR1_TCIE + USART_CR1_TXEIE
+ + USART_CR1_PEIE + USART_CR1_IDLEIE);
+ UART7->CR1 |= (USART_CR1_RXNEIE + USART_CR1_RE + USART_CR1_UE);
+ NVIC_SetVector(UART7_IRQn, (uint32_t)rx_handler);
+ NVIC_ClearPendingIRQ(UART7_IRQn);
+ NVIC_EnableIRQ(UART7_IRQn);
+ __enable_irq();
+#if 0
+ printf("UART7->CR1 0x%08x:0x%08x\r\n", &UART7->CR1, UART7->CR1);
+ printf("UART7->CR2 0x%08x:0x%08x\r\n", &UART7->CR2, UART7->CR2);
+ printf("UART7->CR3 0x%08x:0x%08x\r\n", &UART7->CR3, UART7->CR3);
+ printf("UART7->BRR 0x%08x:0x%08x\r\n", &UART7->BRR, UART7->BRR);
+ printf("UART7->GTPR 0x%08x:0x%08x\r\n", &UART7->GTPR, UART7->GTPR);
+ printf("UART7->RTOR 0x%08x:0x%08x\r\n", &UART7->RTOR, UART7->RTOR);
+ printf("UART7->RQR 0x%08x:0x%08x\r\n", &UART7->RQR, UART7->RQR);
+ printf("UART7->ISR 0x%08x:0x%08x\r\n", &UART7->ISR, UART7->ISR);
+ printf("UART7->ICR 0x%08x:0x%08x\r\n", &UART7->ICR, UART7->ICR);
+#endif
+}
+
+int iGPS_readable(void)
+{
+ return rxbuf.check();
+}
+
+int iGPS_getc(void)
+{
+ while(!rxbuf.check()){;} // wait receiving a character
+ return rxbuf.read();
+}
+
+#endif
+
+////////////////////////////////////////////////////////////////////////////////
+// Parse GPS data
+// Module Type: u-blux7 NEO-7M
+////////////////////////////////////////////////////////////////////////////////
+// Get RMC & GAA data
+void gps_data_rcv(void)
+{
+ int8_t i;
+ time_t old_ave_sec[2];
+ uint32_t diff = 0;
+ time_t seconds;
+ struct tm t_gps;
+
+ seconds = time(NULL);
+ U_DEBUG("\r\nCurrent Time: %s\r\n", ctime(&seconds));
+ old_ave_sec[0] = 0;
+ old_ave_sec[1] = 0;
+ // Wait long interval (every 1sec)
+ for (uint32_t i = 0; i < 100000; i++){
+ if (gps_rx == 0){
+ i = 0;
+ }
+ }
+ U_DEBUG("GPS line is Hi\r\n");
+#if defined(TARGET_STM32F746NG)
+ // Clear GPS RX line errors(over run)
+ UART7->ICR = 0;
+ UART7->CR1 = 0;
+ UART7->CR1 = 5;
+ iGPSrcv_initialize();
+#endif
+ U_DEBUG("Start GPS!!");
+ while(true) {
+ getline_gps(); // Get GPS data from UART
+ if (strncmp(GPS_Buffer, "$GPRMC",6) == 0) {
+ for (i=0; GPS_Buffer[i] != 0; i++) {// Copy msg to RMC buffer
+ MsgBuf_RMC[i] = GPS_Buffer[i];
+ }
+ MsgBuf_RMC[i+1] = 0;
+ DBG('2');
+ if (gps_ready == 3) {
+ DBG('3');
+ get_time_and_date(&t_gps);
+ seconds = mktime(&t_gps);
+ if (old_ave_sec[0] == 0){
+ old_ave_sec[0] = seconds;
+ } else if (old_ave_sec[1] == 0){
+ old_ave_sec[1] = seconds;
+ } else {
+ if (old_ave_sec[0] >= old_ave_sec[1]){
+ diff = old_ave_sec[0] - old_ave_sec[1];
+ } else {
+ diff = old_ave_sec[1] - old_ave_sec[0];
+ }
+ if (diff > 100 ){
+ old_ave_sec[0] = seconds;
+ old_ave_sec[1] = 0;
+ } else {
+ if (old_ave_sec[0] > old_ave_sec[1]){
+ diff = seconds - old_ave_sec[0];
+ if (diff < 100){
+ old_ave_sec[1] = seconds;
+ }
+ } else {
+ diff = seconds - old_ave_sec[1];
+ if (diff < 100){
+ old_ave_sec[0] = seconds;
+ }
+ }
+ set_time(seconds);
+ DBG('4');
+ return;
+ }
+ }
+ }
+ } else if (strncmp(GPS_Buffer, "$GPGSA",6) == 0) {
+ for (i=0; GPS_Buffer[i] != 0; i++) {// Copy msg to GSA buffer
+ MsgBuf_GSA[i] = GPS_Buffer[i];
+ }
+ MsgBuf_GSA[i+1] = 0;
+ gps_ready = check_gps_3d();
+ DBG('x');
+ } else if (strncmp(GPS_Buffer, "$GPGGA",6) == 0) {
+ for (i=0; GPS_Buffer[i] != 0; i++) {// Copy msg to GGA buffer
+ MsgBuf_GGA[i] = GPS_Buffer[i];
+ }
+ MsgBuf_GGA[i+1] = 0;
+ gps_status = check_gps_ready();
+ DBG('1');
+ }
+ }
+}
+
+bool check_gps_is_okay()
+{
+ return gps_is_okay_flag;
+}
+
+// Get line of data from GPS
+void getline_gps(void)
+{
+ char *p = GPS_Buffer;
+
+#if defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F446RE)
+ while (gps.getc() != '$'){;}
+#elif defined(TARGET_STM32F746NG)
+ while (iGPS_getc() != '$'){;}
+#endif
+ *p++ = '$';
+#if 0
+ U_DEBUG("\r\n");
+#else
+ pc.printf("\r\n");
+#endif
+ for (char i= 0;i < 150;i++){
+#if defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_F446RE)
+ *p = gps.getc();
+#elif defined(TARGET_STM32F746NG)
+ *p = iGPS_getc();
+#endif
+#if 0
+ DBG(*p);
+#else
+ pc.putc(*p);
+#endif
+ if (*p == '\r'){
+ *++p = '\n';
+ *++p = 0;
+ *++p = 0;
+ U_DEBUG("Get one GPS data\r\n");
+ return;
+ } else {
+ p++;
+ }
+ }
+ *++p = 0;
+ *++p = 0;
+}
+
+// ASCII to hex
+uint8_t hex(char c){
+ if(c<= '/') return( ERR );
+ if(((c -= '0')<= 9 || 10 <= ( c -= 'A' - '0' - 10)) && c <= 15) {
+ return((uint8_t)c);
+ }
+ return(ERR);
+}
+
+// Search next ',' (comma)
+char *next_comma( char *p ){
+ while (1) {
+ if ( *p== ',' ) {
+ return ++p;
+ } else if ( *p == 0 ) {
+ return (char*)-1;
+ } else {
+ p++;
+ }
+ }
+}
+
+// 2 digits ASCII char to one byte hex
+unsigned char change_acii_hex( char*p ){
+ unsigned char c;
+
+ c = hex(*p++); /* No concern ERR condition! */
+ c = (c * 10) + hex(*p++);
+ return c;
+}
+
+// Skip number of comma
+char *num_of_comma( char *p, int8_t n ){
+ for (; n> 0; n--) {
+ if ( (p = next_comma(p)) == (char*) -1 ) {
+ return (char*)-1;
+ }
+ }
+ return p;
+}
+
+// Get GPS status (1=Not fix, 2=2D, 3=3D)
+uint8_t check_gps_3d(void){
+ char *p;
+ uint8_t x;
+ uint8_t d;
+
+ // pick-up time
+ p = MsgBuf_GSA;
+ p = num_of_comma(p,1); // skip ','
+ // reach to "Position Fix Indicator"
+ if (*p == 'A') {
+ ++p; //','
+ ++p; // 1 or 2 or 3
+ d = hex(*p++);
+ if (d != ERR) {
+ x = d;
+ } else {
+ x = 1;
+ }
+ } else {
+ x = 1;
+ }
+ return x;
+}
+
+// Get GPS status and number of satelites
+uint8_t check_gps_ready(void){
+ char *p;
+ uint8_t x;
+ uint8_t d;
+
+ // pick-up time
+ p = MsgBuf_GGA;
+ p = num_of_comma(p,6); // skip ','
+ // reach to "Position Fix Indicator"
+ if (*p == '1' || *p == '2') {
+ ++p; //','
+ ++p; // Number
+ d = hex(*p++);
+ if (d != ERR) {
+ x = d * 10;
+ x += (uint32_t)hex(*p++);
+ if (*p != ',') {
+ x = 0;
+ }
+ } else {
+ x = 0;
+ }
+ } else {
+ x = 0;
+ }
+ return x;
+}
+
+// Get time(UTC) from GPS data
+void get_time_and_date(struct tm *pt){
+ char *p;
+
+ p = MsgBuf_RMC;
+ p = num_of_comma(p,1); /* skip one ',' */
+ pt->tm_hour = change_acii_hex(p);
+ p += 2;
+ pt->tm_min = change_acii_hex(p);
+ p += 2;
+ pt->tm_sec = change_acii_hex(p);
+ p = MsgBuf_RMC;
+ p = num_of_comma(p,9); /* skip one ',' */
+ pt->tm_mday = change_acii_hex(p);
+ p += 2;
+ pt->tm_mon = change_acii_hex(p) - 1;
+ p += 2;
+ pt->tm_year = change_acii_hex(p) + 100;
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GPS_rcvr/GPSrcvr.h Sat Nov 19 05:32:06 2016 +0000 @@ -0,0 +1,75 @@ +/* + * mbed Application program / GPS receiver control and 1PPS output + * + * Copyright (c) 2004,'09,'10,'16 Kenji Arai / JH1PJL + * http://www.page.sannet.ne.jp/kenjia/index.html + * http://mbed.org/users/kenjiArai/ + * Created: March 28th, 2004 Kenji Arai + * updated: July 25th, 2009 for PIC24USB + * updated: January 16th, 2010 change to GPS-GM318 + * updated: April 24th, 2010 for mbed / NXP LPC1768 + * Revised: Nomeber 13th, 2016 + */ + +// Definition ----------------------------------------------------------------- +// GPS data selection & buffer size +/* $GPGAA,hhmmss.sss,ddmm.mmmmmm,N,dddmm.mmmmmm, + E,1,xx,xx.xx,xx.xxx,M,xx.xxx,M,s.ss,xxxx*sum<CR><LF> + ex. $GPGGA,060306.00,4344.77894,N,14223.38857, + E,2,11,0.9,128.4,M,28.8,M,5.0,0129*4C<CR><LF> + # of data (ex.) = 81 +*/ +#define SIZE_BUF_GGA 96 +/* + $GPGSA,A,3,xx,xx,,,xx,xx,,,,,xx.x,xx.x,xx.x*sum<CR><LF> + ex. $GPGSA,A,3,03,06,13,16,21,23,24,25,29,31,42,50,1.9,0.9,1.7*3C + # of data (ex.) = 63 +*/ +#define SIZE_BUF_GSA 80 +/* + $GPGSV,x,x,xx*sum<CR><LF> + ex. $GPGSV,3,1,12,03,39,225,47,06,55,217,48,13,21,314,48,16,74,342,50*76 + $GPGSV,3,2,12,21,33,095,50,23,32,280,50,24,18,049,42,25,12,315,43*7E + $GPGSV,3,3,12,29,12,047,45,31,49,146,49,42,39,183,46,50,39,176,42*7C + # of data (ex.) = 70 +*/ +#define SIZE_BUF_GSV 80 +/* + $GPRMC,hhmmss.sss,V,ddmm.mmmm,N,dddmm.mmmm,E,k.kkk,x.xx,ddmmyy,,,N*sum<CR><LF> + ex. $GPRMC,060309.00,A,4344.77571,N,14223.38879, + E,0.03,210.32,190808,06.2,W,D*51 + # of data (ex.) = 84 +*/ +#define SIZE_BUF_RMC 96 +/* + $GPVTG,xx.xx,T,,M,x.xx,N,x.xx,K,A*sum<CR><LF> + ex. $GPVTG,210.32,T,204.30,M,0.03,N,0.06,K,D*3F + # of data (ex.) = 43 +*/ +#define SIZE_BUF_VTG 64 +/* + $GPZDA,hhmmss.sss,dd,mmm,yyyy,hh,mm*sum<CR><LF> + ex. $GPZDA,060307.00,19,08,2008,13,26*6E + # of data (ex.) = 36 +*/ +#define SIZE_BUF_ZDA 48 +/* + $GPGLL,ddmm.mmmmmm,N,dddmm.mmmmmm,E,hhmmss.sss,V,D*sum<CR><LF> + ex. $GPGLL,4344.77956,N,14223.38863,E,060305.00,A,D*61 + # of data (ex.) = 52 +*/ +#define SIZE_BUF_GLL 64 + +#define ERR 0xff + +//------------------------------------------------------------------------------ + +#ifndef _IGPSRCV_H +#define _IGPSRCV_H + +void gps_data_rcv(void); // make sure !! infinit loop on RTOS +bool check_gps_is_okay(void); +uint8_t check_gps_3d(void); + +#endif /* _IGPSRCV_H */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LCD_DISCO_F746NG.lib Sat Nov 19 05:32:06 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/ST/code/LCD_DISCO_F746NG/#d44525b1de98
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RingBuffer.lib Sat Nov 19 05:32:06 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/ykuroda/code/RingBuffer/#ea6d02ba96ae
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TS_DISCO_F746NG.lib Sat Nov 19 05:32:06 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/ST/code/TS_DISCO_F746NG/#fe0cf5e2960f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fc_GPS1PPS_f746_f4xx.lib Sat Nov 19 05:32:06 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/kenjiArai/code/fc_GPS1PPS_f746_f4xx/#be7123d400ae
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Nov 19 05:32:06 2016 +0000
@@ -0,0 +1,532 @@
+/*
+ * mbed Application program / Frequency Counter using GPS 1PPS gate puls
+ * Only for ST DISCO-F746NG
+ * Worked on a dedicated Grafic LCD Module
+ *
+ * Copyright (c) 2014,'15,'16 Kenji Arai / JH1PJL
+ * http://www.page.sannet.ne.jp/kenjia/index.html
+ * http://mbed.org/users/kenjiArai/
+ * Created: October 18th, 2014
+ * Revised: January 2nd, 2015
+ * Re-started: June 25th, 2016 ported from F411 to F746
+ * Re-started: Nobember 13th, 2016 Only for DISCO-F746NG LCD
+ * Revised: Nobember 19th, 2016
+ *
+ * Base program: FreqCntr_GPS1PPS_F746F4xx_w_recipro
+ * https://developer.mbed.org/users/kenjiArai
+ * /code/FreqCntr_GPS1PPS_F746F4xx_w_recipro/
+ *
+ * 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.
+ */
+
+/*
+ REFRENCE: see the source code in this file bottom area
+ 2016/11/12, Copyright (c) 2016 MIKAMI, Naoki
+ https://developer.mbed.org/users/MikamiUitOpen/code/F746_GUI_Demo/
+ Thanks Mikammi-san!
+ */
+
+#define USE_COM // use Communication with PC(UART)
+
+// Include --------------------------------------------------------------------
+#include "mbed.h"
+#include "F746_GUI.hpp"
+#include "GPSrcvr.h"
+#include "fc_GPS1PPS.h"
+
+// Definition -----------------------------------------------------------------
+#ifdef USE_COM
+#define BAUD(x) pc.baud(x)
+#define GETC(x) pc.getc(x)
+#define PUTC(x) pc.putc(x)
+#define PRINTF(...) pc.printf(__VA_ARGS__)
+#define READABLE(x) pc.readable(x)
+#else
+#define BAUD(x) {;}
+#define GETC(x) {;}
+#define PUTC(x) {;}
+#define PRINTF(...) {;}
+#define READABLE(x) {;}
+#endif
+
+enum input_select {
+ BNC_NORMAL = 1,
+ RECIPRO_AC,
+ RECIPRO_DC,
+ SMA_10,
+ SMA_20
+};
+
+using namespace Frequency_counter;
+
+// Object ---------------------------------------------------------------------
+DigitalOut input_frq_select(PF_9);
+DigitalInOut prescaler10or20(PB_15);
+DigitalOut recipro_select(PA_8);
+DigitalOut led1(LED1);
+Serial pc(USBTX, USBRX);
+Timer tmr;
+
+//**** Req. Counter
+FRQ_CUNTR fc;
+//**** GUI
+LCD_DISCO_F746NG lcd_;
+
+// RAM ------------------------------------------------------------------------
+// Freq.
+double new_frequency;
+double f_10sec;
+double f_100sec;
+double f_1000sec;
+double freq_recipro;
+// Operation mode
+uint8_t input_mode;
+
+// ROM / Constant data --------------------------------------------------------
+// 12345678901234567890
+static char *const msg_msg0 = "Frequency Counter by JH1PJL K.Arai";
+static char *const msg_msg1 = "on DISCO-F746NG System";
+static char *const msg_msg2 = " "__DATE__" ";
+static char *const msg_mode1 = " BNC none-prescaler ";
+static char *const msg_mode2 = " BNC recipro(BNC none-prescaler) ";
+static char *const msg_mode3 = " BNC recipro(dedicated BNC input)";
+static char *const msg_mode4 = " SMA prescaler 1/10 ";
+static char *const msg_mode5 = " SMA prescaler 1/20 ";
+
+char *const open_msg[] = {
+ "(1) BNC(AC) div = 1/1 10Hz to 100MHz",
+ "(2) BNC(AC)(same as above) Reciprocal mode less than 5KHz",
+ "(3) BNC(DC) (another BNC) Reciprocal mode less than 5KHz",
+ "(4) SMA div = 1/10 up to 1GHz",
+ "(5) SMA(same as above) div = 1/20 up to 1.5GHz"
+};
+
+char *const select_msg[] = {
+ "(1) BNC(AC) div = 1/1 ",
+ "(2) BNC(AC) Reciprocal",
+ "(3) BNC(DC) Reciprocal",
+ "(4) SMA div = 1/10",
+ "(5) SMA div = 1/20"
+};
+
+// Function prototypes --------------------------------------------------------
+void gps_data_rcv(void);
+void freq_measurement(uint8_t mode);
+void recipro(uint8_t mode);
+void opening(void);
+void show_time(void);
+uint8_t mode_slect(void);
+
+//------------------------------------------------------------------------------
+// Control Program
+//------------------------------------------------------------------------------
+void freq_measurement(uint8_t mode)
+{
+ uint16_t n = 0;
+ char buf[48];
+ double scale;
+
+ Button button(400, 3, 70, 40, "MODE", Font16);
+ Label obj20(180, 5, "Frequency Counter",
+ Label::CENTER, Font24, LCD_COLOR_GREEN, LCD_COLOR_BLACK);
+ if (mode == SMA_20){
+ Label obj21(200, 30, "Input=SMA, Division=1/20",
+ Label::CENTER, Font16, LCD_COLOR_WHITE, LCD_COLOR_BLACK);
+ scale = 20.0f;
+ } else if(mode == SMA_10){
+ Label obj21(200, 30, "Input=SMA, Division=1/10",
+ Label::CENTER, Font16, LCD_COLOR_WHITE, LCD_COLOR_BLACK);
+ scale = 10.0f;
+ } else {
+ Label obj21(200, 30, "Input=BNC(AC), Division=1/1",
+ Label::CENTER, Font16, LCD_COLOR_WHITE, LCD_COLOR_BLACK);
+ scale = 1.0f;
+ }
+ while(true){
+ tmr.reset();
+ tmr.start();
+ if (fc.status_freq_update() != 0) {
+ new_frequency = fc.read_freq_data() * scale;
+ f_10sec = fc.read_freq_w_gate_time(10) * scale;
+ f_100sec = fc.read_freq_w_gate_time(100) * scale;
+ f_1000sec = fc.read_freq_w_gate_time(1000) * scale;
+ PRINTF("%8d, Freq: %9.0f,", ++n, new_frequency);
+ PRINTF(" F10s: %10.1f, F100s: %11.2f,", f_10sec, f_100sec);
+ PRINTF(" F1000s: %12.3f,", f_1000sec);
+ sprintf(buf, "Freq: %11.0f [Hz]", new_frequency);
+ Label obj22(40, 60, buf, Label::LEFT, Font24,
+ LCD_COLOR_GREEN, LCD_COLOR_BLACK);
+ sprintf(buf, "F10S: %12.1f [Hz]", f_10sec);
+ Label obj23(40, 90, buf, Label::LEFT, Font24,
+ LCD_COLOR_WHITE, LCD_COLOR_BLACK);
+ sprintf(buf, "F100: %13.2f [Hz]", f_100sec);
+ Label obj24(40, 120, buf, Label::LEFT, Font24,
+ LCD_COLOR_WHITE, LCD_COLOR_BLACK);
+ } else {
+ PRINTF("%8d, No data,,,,", ++n);
+ Label obj25(40, 60, "Data is NOT available!", Label::LEFT, Font24,
+ LCD_COLOR_GREEN, LCD_COLOR_BLACK);
+ sprintf(buf, " ");
+ Label obj26(40, 80, buf, Label::LEFT, Font24,
+ LCD_COLOR_WHITE, LCD_COLOR_BLACK);
+ Label obj27(40, 100, buf, Label::LEFT, Font24,
+ LCD_COLOR_MAGENTA, LCD_COLOR_BLACK);
+ }
+ if (mode == SMA_20){
+ PRINTF(" Div: 1/20,");
+ } else if(mode == SMA_10){
+ PRINTF(" Div: 1/10,");
+ } else {
+ PRINTF(" Div: 1/1 ,");
+ }
+ show_time();
+ while (1000 > tmr.read_ms()){ // 1 second interval
+ if (button.Touched()){ // if user touched "MODE" panel then return
+ return;
+ }
+ wait_ms(1);
+ }
+ }
+}
+
+void recipro(uint8_t mode)
+{
+ uint16_t n = 0;
+ char buf[48];
+ double freq_recipro;
+ uint32_t interval_recipro;
+ uint32_t base_clk;
+ int32_t run2stop;
+
+ Button button(400, 3, 70, 40, "MODE", Font16);
+ Label obj30(180, 5, "Frequency Counter",
+ Label::CENTER, Font24, LCD_COLOR_GREEN, LCD_COLOR_BLACK);
+ if (mode == RECIPRO_AC){
+ Label obj31(200, 30, "Input=BNC(AC) Reciprocal Mode",
+ Label::CENTER, Font16, LCD_COLOR_WHITE, LCD_COLOR_BLACK);
+ } else if (mode == RECIPRO_DC){
+ Label obj31(200, 30, "Input=BNC(DC) Reciprocal Mode",
+ Label::CENTER, Font16, LCD_COLOR_WHITE, LCD_COLOR_BLACK);
+ }
+ while(true){
+ tmr.reset();
+ tmr.start();
+ fc.recipro_start_measure();
+ PRINTF("Start measurement\r");
+ while (fc.recipro_check_trigger() == 0){
+ run2stop = tmr.read_ms();
+ if (run2stop >= 100000){ // 100sec 0.001Hz
+ break;
+ }
+ if (button.Touched()){ // if user touched "MODE" panel then return
+ return;
+ }
+ }
+ if (button.Touched()){ // if user touched "MODE" panel then return
+ return;
+ }
+ if (run2stop >= 1000000){ // 100sec 0.001Hz
+ //freq_recipro = 0;
+ } else {
+ interval_recipro = fc.recipro_read_data();
+ base_clk = fc.recipro_base_clk_data(1);
+ if (interval_recipro >= 9000){// Measure less than 10KHz frequency
+ freq_recipro = (double)base_clk / (double)interval_recipro;
+ } else {
+ //freq_recipro = 0;
+ }
+ }
+ PRINTF("%8d, Freq: %11.5f [Hz] , ", n++, freq_recipro);
+ PRINTF("Raw: %11u [cnt] , ", interval_recipro);
+ PRINTF("Base: %11u [Hz], ", base_clk);
+ sprintf(buf, "Freq:%11.5f [Hz]", freq_recipro);
+ Label obj32(40, 60, buf, Label::LEFT, Font24,
+ LCD_COLOR_GREEN, LCD_COLOR_BLACK);
+ sprintf(buf, "Raw: %11u [Counts]", interval_recipro);
+ Label obj33(40, 90, buf, Label::LEFT, Font24,
+ LCD_COLOR_WHITE, LCD_COLOR_BLACK);
+ sprintf(buf, "Base:%11u (Sys Clk)", base_clk);
+ Label obj34(40, 120, buf, Label::LEFT, Font24,
+ LCD_COLOR_MAGENTA, LCD_COLOR_BLACK);
+ show_time();
+ run2stop = tmr.read_ms();
+ if (run2stop < 1000){
+ while (tmr.read_ms() < 1000){ // 1 second interval
+ if (button.Touched()){
+ return;
+ }
+ wait_ms(1);
+ }
+ }
+ }
+}
+
+void show_time(void)
+{
+ char buf[48];
+ time_t seconds;
+
+ seconds = time(NULL) + 32400; // Adjust UTC to JST
+ strftime(buf, 40,
+ " %I:%M:%S %p JST %y/%m/%d", localtime(&seconds));
+ PRINTF("%s\r\n", buf);
+ Label obj0(40, 240, buf, Label::LEFT, Font24,
+ LCD_COLOR_ORANGE, LCD_COLOR_BLACK);
+}
+
+int main()
+{
+ // Initial input mode
+ input_mode = BNC_NORMAL;
+ input_frq_select = 1;
+ prescaler10or20.output();
+ prescaler10or20 = 0;
+ recipro_select = 0;
+ while(true){
+ lcd_.Clear(LCD_COLOR_BLACK);
+ // openning message
+ opening();
+ PRINTF("\r\n%s%s\r\n", msg_msg0, msg_msg2);
+ PRINTF("%s\r\n", msg_msg1);
+ PRINTF("Wait GPS 1PPS signal\r\n");
+ // GPS (not return until 3D condition)
+ gps_data_rcv();
+ lcd_.Clear(LCD_COLOR_BLACK);
+ input_mode = mode_slect();
+ lcd_.Clear(LCD_COLOR_BLACK);
+ PRINTF("\r\nInput mode # is %u\r\n", input_mode);
+ PRINTF("If you want to change the input signal,");
+ PRINTF(" please restart the system (Enter Alt+B from your PC)\r\n");
+ PRINTF("\r\nStart measuring\r\nMeasureing mode = ");
+ switch(input_mode){
+ case RECIPRO_AC:
+ PRINTF("%s\r\n", msg_mode2);
+ input_frq_select = 1;
+ prescaler10or20.output();
+ prescaler10or20 = 0;
+ recipro_select = 0;
+ recipro(input_mode);
+ break;
+ case RECIPRO_DC:
+ PRINTF("%s\r\n", msg_mode3);
+ input_frq_select = 1;
+ prescaler10or20.output();
+ prescaler10or20 = 0;
+ recipro_select = 1;
+ recipro(input_mode);
+ break;
+ case SMA_10:
+ PRINTF("%s\r\n", msg_mode4);
+ input_frq_select = 0;
+ prescaler10or20.output();
+ prescaler10or20 = 0;
+ recipro_select = 0;
+ freq_measurement(input_mode);
+ break;
+ case SMA_20:
+ PRINTF("%s\r\n", msg_mode5);
+ input_frq_select = 0;
+ prescaler10or20.input();
+ recipro_select = 0;
+ freq_measurement(input_mode);
+ break;
+ case BNC_NORMAL:
+ default:
+ input_mode = BNC_NORMAL;
+ PRINTF("%s\r\n", msg_mode1);
+ input_frq_select = 1;
+ prescaler10or20.output();
+ prescaler10or20 = 0;
+ recipro_select = 0;
+ freq_measurement(input_mode);
+ break;
+ }
+ }
+}
+
+void opening()
+{
+ Label obj10(240, 2, "Frequency Counter using GPS 1PPS",
+ Label::CENTER, Font16);
+ Label obj11(240, 20, " created on Nov. 2016 by JH1PJL/Kenji Arai",
+ Label::CENTER);
+ Label obj12(240, 100, " Please wait to receive",
+ Label::CENTER, Font24, LCD_COLOR_LIGHTYELLOW);
+ Label obj13(240, 120, " GPS signal!! ",
+ Label::CENTER, Font24, LCD_COLOR_LIGHTYELLOW);
+}
+
+uint8_t mode_slect()
+{
+ Label obj10(240, 2, "Set ""Operationg Mode""",
+ Label::CENTER, Font24, LCD_COLOR_LIGHTGREEN);
+ Label obj11(40, 30, open_msg[0], Label::LEFT);
+ Label obj12(40, 42, open_msg[1], Label::LEFT);
+ Label obj13(40, 54, open_msg[2], Label::LEFT);
+ Label obj14(40, 66, open_msg[3], Label::LEFT);
+ Label obj15(40, 78, open_msg[4], Label::LEFT);
+ const int NUMBER_BUTTONS = 5;
+ const string STR1[NUMBER_BUTTONS] =
+ {"1) Nor(AC)", "2) Rec(AC)", "3) Rec(DC)", "4) 1/10","5) 1/20"};
+ ButtonGroup bGroup1(18, 120, 85, 40, NUMBER_BUTTONS, STR1, 5, 5, 5, 5,
+ Font12, LCD_COLOR_WHITE, 0xFF003538, 0xFFB70068, 0xFFFF7FFF);
+ NumericLabel<int> bTouch(50, 240, "",
+ Label::LEFT, Font24, LCD_COLOR_ORANGE);
+ Button button1(300, 170, 100, 50, "ENTER", Font16);
+ while (true)
+ {
+ int num;
+ if (bGroup1.GetTouchedNumber(num)){
+ char buf[32];
+ strcpy(buf, select_msg[num]);
+ bTouch.Draw(buf, num);
+ }
+ if (button1.Touched()){
+ return (uint8_t)(num + 1);
+ }
+ wait(0.02f);
+ }
+}
+
+
+//------------------------------------------------------------------------------
+// ORIGINAL PROGRAM FOR F746_GUI_DEMO
+// by MIKAMI, Naoki
+// 2016/11/12, Copyright (c) 2016 MIKAMI, Naoki
+//------------------------------------------------------------------------------
+#if 0
+//-----------------------------------------------------------------------
+// GuiBase とその派生クラスのデモプログラム
+// Demo program for GuiBase class and its derivertive classes
+//
+// GuiBase, Button, ButtonGroup, Label, NumericLabel, BlinkLabel,
+// SeekBar, SeekbarGroup
+//
+// 2016/11/12, Copyright (c) 2016 MIKAMI, Naoki
+//-----------------------------------------------------------------------
+
+#include "F746_GUI.hpp"
+
+int main()
+{
+ Label obj10(240, 2, "Dome: GUI parts, 2016/07/30, 19:43", Label::CENTER, Font16);
+ Label obj11(240, 20, "Button, ButtonGroup, Label, NumericLabel, BlinkLabel,",
+ Label::CENTER);
+ Label obj12(240, 32, "SeekBar, SeekbarGroup",
+ Label::CENTER);
+
+ Button button1(10, 54, 50, 40, "1");
+ Button button2(62, 54, 50, 40, "2");
+
+ const int NUMBER_BUTTONS = 4;
+ const string STR1[NUMBER_BUTTONS] = {"Button1", "Button2", "Button3", "Activate"};
+ ButtonGroup bGroup1(160, 54, 66, 40, NUMBER_BUTTONS, STR1, 5, 5, 3, 1,
+ Font12, LCD_COLOR_WHITE, 0xFF003538, 0xFFB70068, 0xFFFF7FFF);
+ NumericLabel<int> bTouch(240, 112, "", Label::LEFT, Font12, LCD_COLOR_MAGENTA);
+
+ // Control status of bGroup1
+ ButtonGroup bGroup2(160, 150, 66, 40, 3, (string[]){"0", "1", "2"}, 5, 5, 3);
+ bGroup2.InactivateAll();
+
+ // Switching buttons to control barH active or inactive
+ ButtonGroup bGroup3(10, 150, 66, 40, 2, (string[]){"ON", "OFF"}, 0, 0, 2);
+ bGroup3.TouchedColor(0);
+
+ Button doNotTouch(250, 220, 120, 40, "Don't Touch", Font12,
+ GuiBase::ENUM_TEXT, GuiBase::ENUM_BACK,
+ LCD_COLOR_DARKGREEN, LCD_COLOR_RED);
+
+ // Using default value for argument (Horizontal)
+ SeekBar barH(20, 250, 200, -5, 5, 0, "-5", "", "5");
+ NumericLabel<float> numLabel1(80, 205, "%5.1f", barH.GetValue());
+ NumericLabel<int> numLabel2(130, 205, "%3d", (int)barH.GetValue());
+ NumericLabel<int> numLabel3(160, 205, "%3d");
+
+ // SeekbarGroup (vertical)
+ SeekbarGroup barV(410, 130, 121, 2, 45, -6, 6, 2,
+ SeekBar::Vertical, 0xFFA0FFC0);
+ NumericLabel<float> **numLabel4;
+ numLabel4 = new NumericLabel<float> *[2];
+ for (int n=0; n<2; n++) numLabel4[n] =
+ new NumericLabel<float>(410+n*45, 104, "%4.1f", barV.GetValue(n), Label::CENTER);
+ NumericLabel<int> numLabel5(455, 92, "%1d", barV.GetIntValue(0), Label::CENTER);
+
+ // Test of left-, cenrer-, and right-justified
+ Label leftJustified(420, 54, "ABC", Label::LEFT);
+ Label centerJustified(420, 64, "ABC", Label::CENTER);
+ Label rightJustified1(420, 74, "ABC", Label::RIGHT);
+
+ while (true)
+ {
+ if (button1.Touched()) button2.Draw();
+ if (button2.Touched()) button1.Draw();
+
+ int num;
+ if (bGroup1.GetTouchedNumber(num))
+ bTouch.Draw("Button%d touched", num+1);
+ if (num == 3)
+ bGroup2.ActivateAll();
+
+ if (bGroup2.GetTouchedNumber(num))
+ switch (num)
+ {
+ case 0: button1.Activate();
+ bGroup1.Activate(1);
+ bGroup1.DrawAll();
+ break;
+ case 1: button1.Inactivate();
+ bGroup1.Inactivate(1);
+ break;
+ case 2: bGroup1.EraseAll();//for (int n=0; n<4; n++) bGroup1.Erase(n);
+ for (int n=0; n<2; n++)
+ {
+ barV.Draw(n, 0); // reset seekbar
+ numLabel4[n]->Draw("%4.1f", barV.GetValue(n));
+ }
+ break;
+ }
+
+ if (barH.Slide())
+ {
+ numLabel1.Draw("%5.1f", barH.GetValue());
+ int8_t x = (int8_t)barH.GetValue();
+ numLabel2.Draw("%3d", x);
+
+ numLabel3.Draw(barH.GetIntValue());
+ }
+
+ int sbNum;
+ if (barV.GetSlidedNumber(sbNum))
+ {
+ if (sbNum == 0) numLabel4[sbNum]->Draw("%4.1f", barV.GetValue(sbNum));
+ else numLabel4[sbNum]->Draw("%4.1f", barV.GetValue(sbNum));
+ if (sbNum == 1) numLabel5.Draw("%1d", barV.GetIntValue(sbNum));
+ }
+ // If "doNotTouch" button touched, trapped into endless loop
+ if (doNotTouch.Touched())
+ BlinkLabel warning(250, 200, "You must reset", Label::LEFT, Font16);
+
+ // SeekBar active inactive switching
+ if (bGroup3.Touched(0))
+ {
+ barH.Activate();
+ barV.ActivateAll();
+ }
+ if (bGroup3.Touched(1))
+ {
+ barH.Inactivate();
+ barV.InactivateAll();
+ }
+
+ wait(0.02f);
+ }
+}
+
+#endif
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Nov 19 05:32:06 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/0ab6a29f35bf \ No newline at end of file