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:
Wed Nov 06 07:38:20 2013 +0000
Revision:
7:42e7f18361c8
Parent:
6:7f90a61e1a69
Child:
8:cb966096a916
sync libraries

Who changed what in which revision?

UserRevisionLine numberNew contents of line
strysd 6:7f90a61e1a69 1 //see mbed.org/users/strysd/notebook/measure_humidity_with_hs15p_and_lmc555/
Neel 0:c5bcf643a8b1 2 #include "mbed.h"
strysd 6:7f90a61e1a69 3 #include "main.h"
strysd 1:e2034bcdb101 4
strysd 4:64d9c0bed75b 5 InterruptIn in(p8); //connect to the Discharge of 555
strysd 5:9be3080ca8ba 6 DigitalOut run555(p9);//connect to the Reset of 555
strysd 7:42e7f18361c8 7 DigitalOut led1(LED1);//running 555
strysd 7:42e7f18361c8 8 DigitalOut led2(LED2);//not ready
Neel 0:c5bcf643a8b1 9 Timer t1;
Neel 0:c5bcf643a8b1 10
strysd 4:64d9c0bed75b 11 float my_interval = 0;//between interrupts in microseconds
strysd 1:e2034bcdb101 12 float my_freq = 0;//Hz
strysd 4:64d9c0bed75b 13 float my_ohm = 0;//ohm for HS15P
strysd 4:64d9c0bed75b 14 int rest_in = 0;//rest of interrupt times
Neel 0:c5bcf643a8b1 15
Neel 0:c5bcf643a8b1 16 void flip(void)
Neel 0:c5bcf643a8b1 17 {
strysd 6:7f90a61e1a69 18 if(rest_in < READ_TIMER){
strysd 6:7f90a61e1a69 19 my_interval = t1.read_us();// Get time since last interrupt
strysd 4:64d9c0bed75b 20 }
strysd 5:9be3080ca8ba 21
strysd 6:7f90a61e1a69 22 t1.reset();// Reset timer and wait for next interrupt
strysd 6:7f90a61e1a69 23 rest_in--;
strysd 6:7f90a61e1a69 24
strysd 6:7f90a61e1a69 25 if(rest_in <= 0){
strysd 1:e2034bcdb101 26 //No use interrupt
strysd 7:42e7f18361c8 27 run555 = led1 = 0;
strysd 1:e2034bcdb101 28 t1.stop();
strysd 1:e2034bcdb101 29 }
Neel 0:c5bcf643a8b1 30 }
Neel 0:c5bcf643a8b1 31
Neel 0:c5bcf643a8b1 32 int main() {
strysd 7:42e7f18361c8 33 run555 = led1 = led2 = 0;
strysd 5:9be3080ca8ba 34 // Set up the interrupt
strysd 2:c4d4f0f9d77c 35 in.mode(PullUp);
strysd 6:7f90a61e1a69 36 in.rise(&flip);
strysd 1:e2034bcdb101 37
strysd 3:bf0a5effbed2 38 printf("\rStarting measure\n");
strysd 5:9be3080ca8ba 39
Neel 0:c5bcf643a8b1 40 while (1) {
strysd 1:e2034bcdb101 41 //Use interrupt
strysd 4:64d9c0bed75b 42 my_interval = 0;
strysd 1:e2034bcdb101 43 t1.start();
strysd 4:64d9c0bed75b 44 rest_in = IN_TIMES;
strysd 7:42e7f18361c8 45 run555 = led1 = 1;
strysd 7:42e7f18361c8 46 led2 = 0;
strysd 4:64d9c0bed75b 47 wait_ms(WAIT_IN);
strysd 7:42e7f18361c8 48 run555 = led1 = 0;//force stop
strysd 3:bf0a5effbed2 49
strysd 4:64d9c0bed75b 50 if (my_interval < MIN_INTERVAL || my_interval > MAX_INTERVAL){
strysd 3:bf0a5effbed2 51 printf("\r not ready\n");
strysd 7:42e7f18361c8 52 led2 = 1;
strysd 1:e2034bcdb101 53 } else {
strysd 4:64d9c0bed75b 54 my_freq = ONESEC_BY_MICRO / my_interval; // Convert to Hz
strysd 4:64d9c0bed75b 55 my_ohm = my_interval * CONV_KILO_OHM;// Convert to kilo ohm
strysd 6:7f90a61e1a69 56 printf("\r %.0f Hz, %.0f micro sec, %.1f kilo ohm \n",
strysd 6:7f90a61e1a69 57 my_freq, my_interval, my_ohm);
strysd 1:e2034bcdb101 58 }
strysd 3:bf0a5effbed2 59
strysd 4:64d9c0bed75b 60 wait_ms(WAIT_NEXT);
Neel 0:c5bcf643a8b1 61 }
Neel 0:c5bcf643a8b1 62 }