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:
Tue Jun 04 06:14:19 2013 +0000
Revision:
5:9be3080ca8ba
Parent:
4:64d9c0bed75b
Child:
6:7f90a61e1a69
change interrupt mode and wait time

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 4:64d9c0bed75b 4 #define CONV_KILO_OHM 0.0072 //if use 0.1 micro F
strysd 4:64d9c0bed75b 5 #define IN_TIMES 10 //interrupt times
strysd 4:64d9c0bed75b 6 #define READ_TIMER 3 //rest times when reads timer
strysd 5:9be3080ca8ba 7 #define WAIT_IN 1000 //wait interrupts in msec
strysd 5:9be3080ca8ba 8 #define WAIT_NEXT 4000 //wait next measurement in msec
strysd 4:64d9c0bed75b 9 #define MAX_INTERVAL 100000 // > 0.1 sec ( < 10 Hz) in microseconds
strysd 4:64d9c0bed75b 10 #define MIN_INTERVAL 20 // < 20 micro sec ( > 50 kHz) in microseconds
strysd 4:64d9c0bed75b 11 #define ONESEC_BY_MICRO 1000000// 1 sec in microseconds
strysd 1:e2034bcdb101 12
strysd 4:64d9c0bed75b 13 InterruptIn in(p8); //connect to the Discharge of 555
strysd 5:9be3080ca8ba 14 DigitalOut run555(p9);//connect to the Reset of 555
Neel 0:c5bcf643a8b1 15 DigitalOut led(LED1);
Neel 0:c5bcf643a8b1 16 Timer t1;
Neel 0:c5bcf643a8b1 17
strysd 4:64d9c0bed75b 18 float my_interval = 0;//between interrupts in microseconds
strysd 1:e2034bcdb101 19 float my_freq = 0;//Hz
strysd 4:64d9c0bed75b 20 float my_ohm = 0;//ohm for HS15P
strysd 4:64d9c0bed75b 21 int rest_in = 0;//rest of interrupt times
Neel 0:c5bcf643a8b1 22
Neel 0:c5bcf643a8b1 23 void flip(void)
Neel 0:c5bcf643a8b1 24 {
strysd 4:64d9c0bed75b 25 if(rest_in > 0){
strysd 4:64d9c0bed75b 26 if(rest_in < READ_TIMER){
strysd 4:64d9c0bed75b 27 my_interval = t1.read_us();// Get time since last interrupt
strysd 3:bf0a5effbed2 28 }
strysd 3:bf0a5effbed2 29 t1.reset();// Reset timer and wait for next interrupt
strysd 4:64d9c0bed75b 30 rest_in--;
strysd 4:64d9c0bed75b 31 }
strysd 5:9be3080ca8ba 32
strysd 4:64d9c0bed75b 33 if(rest_in == 0){
strysd 1:e2034bcdb101 34 //No use interrupt
strysd 4:64d9c0bed75b 35 run555 = led = 0;
strysd 1:e2034bcdb101 36 t1.stop();
strysd 1:e2034bcdb101 37 }
Neel 0:c5bcf643a8b1 38 }
Neel 0:c5bcf643a8b1 39
Neel 0:c5bcf643a8b1 40 int main() {
strysd 4:64d9c0bed75b 41 run555 = led = 0;
strysd 5:9be3080ca8ba 42 // Set up the interrupt
strysd 2:c4d4f0f9d77c 43 in.mode(PullUp);
strysd 5:9be3080ca8ba 44 in.fall(&flip);
strysd 1:e2034bcdb101 45
strysd 3:bf0a5effbed2 46 printf("\rStarting measure\n");
strysd 5:9be3080ca8ba 47
Neel 0:c5bcf643a8b1 48 while (1) {
strysd 1:e2034bcdb101 49 //Use interrupt
strysd 4:64d9c0bed75b 50 my_interval = 0;
strysd 1:e2034bcdb101 51 t1.start();
strysd 4:64d9c0bed75b 52 rest_in = IN_TIMES;
strysd 4:64d9c0bed75b 53 run555 = led = 1;
strysd 4:64d9c0bed75b 54 wait_ms(WAIT_IN);
strysd 3:bf0a5effbed2 55
strysd 4:64d9c0bed75b 56 if (my_interval < MIN_INTERVAL || my_interval > MAX_INTERVAL){
strysd 3:bf0a5effbed2 57 printf("\r not ready\n");
strysd 1:e2034bcdb101 58 } else {
strysd 4:64d9c0bed75b 59 my_freq = ONESEC_BY_MICRO / my_interval; // Convert to Hz
strysd 4:64d9c0bed75b 60 my_ohm = my_interval * CONV_KILO_OHM;// Convert to kilo ohm
strysd 3:bf0a5effbed2 61 printf("\r %d Hz, %d micro sec, %4.1f kilo ohm \n",
strysd 4:64d9c0bed75b 62 (int)my_freq, (int)my_interval, my_ohm);
strysd 1:e2034bcdb101 63 }
strysd 3:bf0a5effbed2 64
strysd 4:64d9c0bed75b 65 wait_ms(WAIT_NEXT);
Neel 0:c5bcf643a8b1 66 }
Neel 0:c5bcf643a8b1 67 }