test interruptIn feature with 555 timer
Dependencies: ClockControl PowerControl mbed
Fork of Frequency_counter by
Test interruptIn function with using LMC555 timer IC
LPC 1768 自身が持つタイマー割り込み機能を使わずに、 あえて外部のタイマー IC 555 からの信号で周期的に割り込みするテスト。
下記の回路例では、555 の output 端子が 約 10 秒周期のうち、0.3 秒間 Low になるはず。 ただし、コンデンサーおよび抵抗の誤差の影響があり、実測値は約7秒周期
C を 47μ から 330 μ に変えると約1分前後で周期的に割り込みがかかります。
なるべく配線が交差しないように部品配置してみた例
Diff: main.cpp
- Revision:
- 1:e2034bcdb101
- Parent:
- 0:c5bcf643a8b1
- Child:
- 2:c4d4f0f9d77c
--- a/main.cpp Sun Feb 03 21:06:02 2013 +0000 +++ b/main.cpp Sat Jun 01 05:44:10 2013 +0000 @@ -1,32 +1,59 @@ #include "mbed.h" +//see mbed.org/users/strysd/notebook/measure_humidity_with_hs15p_and_lmc555/ +#define ohm_constant 7.2 //if use 0.1 micro F + Serial pc(USBTX, USBRX); InterruptIn in(p8); +DigitalOut vcc555(p9); DigitalOut led(LED1); -DigitalOut led2(LED2); Timer t1; -float t_period = 0; // This is the period between interrupts in microseconds -float t_freq = 0; +float t_period = 0;//between interrupts in microseconds +float my_freq = 0;//Hz +float my_ohm = 0;//ohm for HS15P +int in_limit = 10; +int in_count = 0; void flip(void) { - led=!led; - t_period = t1.read_us(); // Get time since last interrupt - t_freq = (1/t_period)*1000000; // Convert period (in us) to frequency (Hz) - t1.reset(); // Reset timer and wait for next interrupt + if(in_count > 0){ + t_period = t1.read_us();// Get time since last interrupt + in_count--; + t1.reset();// Reset timer and wait for next interrupt + } else { + //No use interrupt + in.mode(PullDown); + vcc555 = led = 0; + t1.stop(); + } } + int main() { - pc.printf("\rStarting frequency counter\n"); - in.mode(PullDown); // Set the pin to Pull Down mode. - in.rise(&flip); // Set up the interrupt for rising edge - t1.start(); // start the timer + vcc555 = led = 0; + in.rise(&flip);// Set up the interrupt for rising edge + in.mode(PullDown); + + pc.printf("\rStarting measure\n"); while (1) { - wait_ms(100); - led2=!led2; - pc.printf("\rfrq is %d Hz\n", (int)t_freq); + //Use interrupt + t1.start(); + in_count = in_limit; + vcc555 = led = 1; + in.mode(PullUp); + wait_ms(200); + + if (t_period > 0){ + my_freq = (1000/t_period)*1000; // Convert to Hz + my_ohm = t_period * ohm_constant;// Convert to ohm + + pc.printf("\r %d Hz, %d micro sec, %d ohm \n", + (int)my_freq, (int)t_period, (int)my_ohm); + } else { + pc.printf("\r not ready\n"); + } + wait_ms(1800); } - } \ No newline at end of file