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 07:49:57 2013 +0000
Revision:
2:c4d4f0f9d77c
Parent:
1:e2034bcdb101
Child:
3:bf0a5effbed2
remove unneeded pulldown

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 vcc555 = led = 0;
strysd 1:e2034bcdb101 27 t1.stop();
strysd 1:e2034bcdb101 28 }
Neel 0:c5bcf643a8b1 29 }
Neel 0:c5bcf643a8b1 30
strysd 1:e2034bcdb101 31
Neel 0:c5bcf643a8b1 32 int main() {
strysd 1:e2034bcdb101 33 vcc555 = led = 0;
strysd 2:c4d4f0f9d77c 34 in.mode(PullUp);
strysd 1:e2034bcdb101 35 in.rise(&flip);// Set up the interrupt for rising edge
strysd 1:e2034bcdb101 36
strysd 1:e2034bcdb101 37 pc.printf("\rStarting measure\n");
Neel 0:c5bcf643a8b1 38
Neel 0:c5bcf643a8b1 39 while (1) {
strysd 1:e2034bcdb101 40 //Use interrupt
strysd 1:e2034bcdb101 41 t1.start();
strysd 1:e2034bcdb101 42 in_count = in_limit;
strysd 1:e2034bcdb101 43 vcc555 = led = 1;
strysd 1:e2034bcdb101 44 wait_ms(200);
strysd 1:e2034bcdb101 45
strysd 1:e2034bcdb101 46 if (t_period > 0){
strysd 1:e2034bcdb101 47 my_freq = (1000/t_period)*1000; // Convert to Hz
strysd 1:e2034bcdb101 48 my_ohm = t_period * ohm_constant;// Convert to ohm
strysd 1:e2034bcdb101 49
strysd 1:e2034bcdb101 50 pc.printf("\r %d Hz, %d micro sec, %d ohm \n",
strysd 1:e2034bcdb101 51 (int)my_freq, (int)t_period, (int)my_ohm);
strysd 1:e2034bcdb101 52 } else {
strysd 1:e2034bcdb101 53 pc.printf("\r not ready\n");
strysd 1:e2034bcdb101 54 }
strysd 1:e2034bcdb101 55 wait_ms(1800);
Neel 0:c5bcf643a8b1 56 }
Neel 0:c5bcf643a8b1 57 }