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

Committer:
strysd
Date:
Sat Jun 01 05:44:10 2013 +0000
Revision:
1:e2034bcdb101
Parent:
0:c5bcf643a8b1
Child:
2:c4d4f0f9d77c
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Neel 0:c5bcf643a8b1 1 #include "mbed.h"
Neel 0:c5bcf643a8b1 2
strysd 1:e2034bcdb101 3 //see mbed.org/users/strysd/notebook/measure_humidity_with_hs15p_and_lmc555/
strysd 1:e2034bcdb101 4 #define ohm_constant 7.2 //if use 0.1 micro F
strysd 1:e2034bcdb101 5
Neel 0:c5bcf643a8b1 6 Serial pc(USBTX, USBRX);
Neel 0:c5bcf643a8b1 7 InterruptIn in(p8);
strysd 1:e2034bcdb101 8 DigitalOut vcc555(p9);
Neel 0:c5bcf643a8b1 9 DigitalOut led(LED1);
Neel 0:c5bcf643a8b1 10 Timer t1;
Neel 0:c5bcf643a8b1 11
strysd 1:e2034bcdb101 12 float t_period = 0;//between interrupts in microseconds
strysd 1:e2034bcdb101 13 float my_freq = 0;//Hz
strysd 1:e2034bcdb101 14 float my_ohm = 0;//ohm for HS15P
strysd 1:e2034bcdb101 15 int in_limit = 10;
strysd 1:e2034bcdb101 16 int in_count = 0;
Neel 0:c5bcf643a8b1 17
Neel 0:c5bcf643a8b1 18 void flip(void)
Neel 0:c5bcf643a8b1 19 {
strysd 1:e2034bcdb101 20 if(in_count > 0){
strysd 1:e2034bcdb101 21 t_period = t1.read_us();// Get time since last interrupt
strysd 1:e2034bcdb101 22 in_count--;
strysd 1:e2034bcdb101 23 t1.reset();// Reset timer and wait for next interrupt
strysd 1:e2034bcdb101 24 } else {
strysd 1:e2034bcdb101 25 //No use interrupt
strysd 1:e2034bcdb101 26 in.mode(PullDown);
strysd 1:e2034bcdb101 27 vcc555 = led = 0;
strysd 1:e2034bcdb101 28 t1.stop();
strysd 1:e2034bcdb101 29 }
Neel 0:c5bcf643a8b1 30 }
Neel 0:c5bcf643a8b1 31
strysd 1:e2034bcdb101 32
Neel 0:c5bcf643a8b1 33 int main() {
strysd 1:e2034bcdb101 34 vcc555 = led = 0;
strysd 1:e2034bcdb101 35 in.rise(&flip);// Set up the interrupt for rising edge
strysd 1:e2034bcdb101 36 in.mode(PullDown);
strysd 1:e2034bcdb101 37
strysd 1:e2034bcdb101 38 pc.printf("\rStarting measure\n");
Neel 0:c5bcf643a8b1 39
Neel 0:c5bcf643a8b1 40 while (1) {
strysd 1:e2034bcdb101 41 //Use interrupt
strysd 1:e2034bcdb101 42 t1.start();
strysd 1:e2034bcdb101 43 in_count = in_limit;
strysd 1:e2034bcdb101 44 vcc555 = led = 1;
strysd 1:e2034bcdb101 45 in.mode(PullUp);
strysd 1:e2034bcdb101 46 wait_ms(200);
strysd 1:e2034bcdb101 47
strysd 1:e2034bcdb101 48 if (t_period > 0){
strysd 1:e2034bcdb101 49 my_freq = (1000/t_period)*1000; // Convert to Hz
strysd 1:e2034bcdb101 50 my_ohm = t_period * ohm_constant;// Convert to ohm
strysd 1:e2034bcdb101 51
strysd 1:e2034bcdb101 52 pc.printf("\r %d Hz, %d micro sec, %d ohm \n",
strysd 1:e2034bcdb101 53 (int)my_freq, (int)t_period, (int)my_ohm);
strysd 1:e2034bcdb101 54 } else {
strysd 1:e2034bcdb101 55 pc.printf("\r not ready\n");
strysd 1:e2034bcdb101 56 }
strysd 1:e2034bcdb101 57 wait_ms(1800);
Neel 0:c5bcf643a8b1 58 }
Neel 0:c5bcf643a8b1 59 }