Yeongsoo Kim / Mbed 2 deprecated Mecha_Timer

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
yeongsookim
Date:
Wed Dec 09 00:06:26 2020 +0000
Commit message:
Init commit

Changed in this revision

.mbed Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mbed_config.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.mbed	Wed Dec 09 00:06:26 2020 +0000
@@ -0,0 +1,1 @@
+ROOT=.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Dec 09 00:06:26 2020 +0000
@@ -0,0 +1,101 @@
+#include "mbed.h"
+Serial pc(USBTX, USBRX); // tx, rx
+PwmOut mypwm(p24);
+DigitalIn sensorIn(p23, PullUp);
+
+DigitalOut myled(LED1);
+
+
+//Interrupt is generated every 1ms and count is increased by 1
+int flag_01ms=0;
+int flag_1ms=0;
+int flag_20ms=0;
+void counter_100ns()
+{
+    flag_01ms++;
+    flag_1ms++;
+    flag_20ms++;
+}
+
+int main()
+{
+
+    wait(1);
+
+    //Set the 1ms thicker.
+    Ticker ticker_100ns;
+    ticker_100ns.attach(&counter_100ns,0.0001);
+
+    Timer time;
+    time.start();
+    float init_time = time.read();
+    pc.printf("init_time %.3f sec\n", init_time);
+    mypwm.period_us(5);
+    mypwm.pulsewidth_us(3);
+
+
+    float start_time=0.0;
+    float end_time=0.0;
+    int wait_5s = 10*1000*2;
+    int wait_count =0;
+    bool is_start=false;
+    bool is_end=false;
+    int up_count=0;
+
+    bool is_first_rising =false;
+    float first_rising_time=0.0;
+
+    while(1) {
+        
+        if(flag_01ms>=1) {
+            flag_01ms=0;
+            if(is_start==false) {
+                if(sensorIn==0) {
+                    up_count++;
+                    if (is_first_rising == false) {
+                        is_first_rising =true;
+                        first_rising_time = time.read();
+                    }
+                }
+            } else {
+                if(wait_count>wait_5s) {
+                    if(sensorIn==0) {
+                        up_count++;
+                        if (is_first_rising == false) {
+                            is_first_rising =true;
+                            first_rising_time = time.read();
+                        }
+                    }
+                } else {
+                    wait_count++;
+                }
+            }
+        }
+        if(flag_1ms>=10) {
+            flag_1ms=0;
+            if(up_count>=5 && is_start==false) {
+                start_time=first_rising_time;
+                pc.printf("start time %.5f sec %.5f\n", start_time-init_time);
+                wait_count=0;
+                is_first_rising =false;
+                first_rising_time = 0.0;
+                up_count=0;
+                is_start = true;
+            } else if(up_count>=5 && is_start==true && is_end==false) {
+                end_time=first_rising_time;
+                
+                pc.printf("end time %.5f sec %.5f \n", end_time-init_time);
+                pc.printf("time gap %.5f sec \n", end_time-start_time);
+                is_end=true;
+            }
+
+        }
+        if(flag_20ms>=20*10) {
+            flag_20ms=0;
+            is_first_rising = false;
+            first_rising_time=0.0;
+            up_count=0;
+        }
+        myled = sensorIn;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Dec 09 00:06:26 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_config.h	Wed Dec 09 00:06:26 2020 +0000
@@ -0,0 +1,49 @@
+/*
+ * mbed SDK
+ * Copyright (c) 2017 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Automatically generated configuration file.
+// DO NOT EDIT, content will be overwritten.
+
+#ifndef __MBED_CONFIG_DATA__
+#define __MBED_CONFIG_DATA__
+
+// Configuration parameters
+#define CLOCK_SOURCE                                      USE_PLL_HSE_EXTC|USE_PLL_HSI                                                   // set by target:NUCLEO_F767ZI
+#define LPTICKER_DELAY_TICKS                              1                                                                              // set by target:FAMILY_STM32
+#define MBED_CONF_PLATFORM_DEFAULT_SERIAL_BAUD_RATE       9600                                                                           // set by library:platform
+#define MBED_CONF_PLATFORM_ERROR_ALL_THREADS_INFO         0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_ERROR_DECODE_HTTP_URL_STR      "\nFor more info, visit: https://armmbed.github.io/mbedos-error/?error=0x%08X" // set by library:platform
+#define MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED 0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_ERROR_HIST_ENABLED             0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_ERROR_HIST_SIZE                4                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_FORCE_NON_COPYABLE_ERROR       0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_MAX_ERROR_FILENAME_LEN         16                                                                             // set by library:platform
+#define MBED_CONF_PLATFORM_POLL_USE_LOWPOWER_TIMER        0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_STDIO_BAUD_RATE                9600                                                                           // set by library:platform
+#define MBED_CONF_PLATFORM_STDIO_BUFFERED_SERIAL          0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_STDIO_CONVERT_NEWLINES         0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_STDIO_CONVERT_TTY_NEWLINES     0                                                                              // set by library:platform
+#define MBED_CONF_PLATFORM_STDIO_FLUSH_AT_EXIT            1                                                                              // set by library:platform
+#define MBED_CONF_TARGET_FLASH_DUAL_BANK                  0                                                                              // set by target:NUCLEO_F767ZI
+#define MBED_CONF_TARGET_LPTICKER_LPTIM                   1                                                                              // set by target:NUCLEO_F767ZI
+#define MBED_CONF_TARGET_LPUART_CLOCK_SOURCE              USE_LPUART_CLK_LSE|USE_LPUART_CLK_PCLK1                                        // set by target:FAMILY_STM32
+#define MBED_CONF_TARGET_LSE_AVAILABLE                    1                                                                              // set by target:FAMILY_STM32
+#define MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE   ETHERNET                                                                       // set by target:NUCLEO_F767ZI
+#define MBED_MEM_TRACING_ENABLED                          0                                                                              // set by library:platform
+#define STM32_D11_SPI_ETHERNET_PIN                        PA_7                                                                           // set by target:NUCLEO_F767ZI
+
+#endif