test interruptIn feature with 555 timer

Dependencies:   ClockControl PowerControl mbed

Fork of Frequency_counter by Satoru Yoshida

Test interruptIn function with using LMC555 timer IC

LPC 1768 自身が持つタイマー割り込み機能を使わずに、 あえて外部のタイマー IC 555 からの信号で周期的に割り込みするテスト。

下記の回路例では、555 の output 端子が 約 10 秒周期のうち、0.3 秒間 Low になるはず。 ただし、コンデンサーおよび抵抗の誤差の影響があり、実測値は約7秒周期

C を 47μ から 330 μ に変えると約1分前後で周期的に割り込みがかかります。

/media/uploads/strysd/int555_10s.png

なるべく配線が交差しないように部品配置してみた例

/media/uploads/strysd/555test.jpg

Revision:
8:cb966096a916
Parent:
7:42e7f18361c8
--- a/main.cpp	Wed Nov 06 07:38:20 2013 +0000
+++ b/main.cpp	Sun May 11 07:29:02 2014 +0000
@@ -1,62 +1,36 @@
-//see mbed.org/users/strysd/notebook/measure_humidity_with_hs15p_and_lmc555/
 #include "mbed.h"
-#include "main.h"
+#include "PowerControl/EthernetPowerControl.h"
+#include "ClockControl/ClockControl.h"
 
-InterruptIn in(p8);   //connect to the Discharge of 555
-DigitalOut run555(p9);//connect to the Reset     of 555
+InterruptIn in(p8);   //Connect from output of 555
 DigitalOut led1(LED1);//running 555
-DigitalOut led2(LED2);//not ready
-Timer t1;
 
-float my_interval = 0;//between interrupts in microseconds
-float my_freq = 0;//Hz
-float my_ohm  = 0;//ohm for HS15P
-int   rest_in = 0;//rest of interrupt times
+/* stop USB Interface */
+#define USR_POWERDOWN (0x104)
+int semihost_powerdown() {
+    uint32_t arg;
+    return __semihost(USR_POWERDOWN, &arg);
+}
 
 void flip(void)
 {
-    if(rest_in < READ_TIMER){
-        my_interval = t1.read_us();// Get time since last interrupt
-    }
-
-    t1.reset();// Reset timer and wait for next interrupt
-    rest_in--;
-
-    if(rest_in <= 0){
-        //No use interrupt
-        run555 = led1 = 0;
-        t1.stop();
-    }
+    led1 = !led1; 
 }
 
 int main() {
-    run555 = led1 = led2 = 0;
-    // Set up the interrupt
-    in.mode(PullUp);
-    in.rise(&flip);
+    led1 = 0;
 
-    printf("\rStarting measure\n");
+    setSystemFrequency(0x3, 0x1, 6, 1);//clock down from 96MHz to 48MHz
+
+    semihost_powerdown();//Stop also USB Interface
+    PHY_PowerDown();//net
 
-    while (1) {
-        //Use interrupt
-        my_interval = 0;
-        t1.start();
-        rest_in = IN_TIMES;
-        run555 = led1 = 1;
-        led2 = 0;
-        wait_ms(WAIT_IN);
-        run555 = led1 = 0;//force stop
-
-        if (my_interval < MIN_INTERVAL || my_interval > MAX_INTERVAL){
-            printf("\r not ready\n");
-            led2 = 1;
-        } else {
-            my_freq = ONESEC_BY_MICRO / my_interval;  // Convert to Hz
-            my_ohm  = my_interval     * CONV_KILO_OHM;// Convert to kilo ohm
-            printf("\r %.0f Hz, %.0f micro sec, %.1f kilo ohm \n",
-                   my_freq, my_interval, my_ohm);
-        }
-
-         wait_ms(WAIT_NEXT);
+    // Set up the interrupt
+    in.mode(PullNone);
+    in.rise(&flip);
+    
+    while(1){
+        wait(1);
     }
+      
 }
\ No newline at end of file