Measure the width (time-wise) of an incoming pulse.

Dependencies:   dispBoB mbed PCA9635

Committer:
d_worrall
Date:
Tue Jul 12 10:05:44 2011 +0000
Revision:
2:bb7e46464d17
Parent:
1:f04131cae8b8

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
d_worrall 0:dd684fb95312 1 #include "mbed.h"
d_worrall 0:dd684fb95312 2 #include "dispBoB.h"
d_worrall 0:dd684fb95312 3
d_worrall 0:dd684fb95312 4 dispBoB db(p28, p27, p26); //instantiate a dispBoB object
d_worrall 0:dd684fb95312 5 InterruptIn trigger(p12); //set up the trigger as an external interrupt
d_worrall 0:dd684fb95312 6 Timer t;
d_worrall 0:dd684fb95312 7
d_worrall 1:f04131cae8b8 8 void up(){ //call this on rising edge
d_worrall 1:f04131cae8b8 9 t.start(); //start timer
d_worrall 0:dd684fb95312 10 }
d_worrall 0:dd684fb95312 11
d_worrall 1:f04131cae8b8 12 void down(){ //call this upon falling edge
d_worrall 1:f04131cae8b8 13 t.stop(); //stop timer
d_worrall 0:dd684fb95312 14 db.locate(0);
d_worrall 2:bb7e46464d17 15 db.printf("%06d", t.read_ms()); //print counter info to dispBoB
d_worrall 1:f04131cae8b8 16 t.reset(); //reset timer
d_worrall 0:dd684fb95312 17 }
d_worrall 0:dd684fb95312 18
d_worrall 0:dd684fb95312 19 int main() {
d_worrall 0:dd684fb95312 20 trigger.mode(PullUp); //activate internal pull up (hardware specific)
d_worrall 2:bb7e46464d17 21 db.init(); //ALWAYS initialise dispBoB
d_worrall 2:bb7e46464d17 22 db.cls();
d_worrall 1:f04131cae8b8 23 trigger.rise(&up); //attach up() to interrupt on rising edge of trigger
d_worrall 1:f04131cae8b8 24 trigger.fall(&down); //attach down() to interrupt on falling edge of trigger
d_worrall 2:bb7e46464d17 25 db.printf("%06d", t.read_ms()); //display an initial count "000000"
d_worrall 2:bb7e46464d17 26
d_worrall 2:bb7e46464d17 27 //To change the timebase just replace the read_ms() function with
d_worrall 2:bb7e46464d17 28 //read() for seconds and read_us() for microseconds. These use a 32bit
d_worrall 2:bb7e46464d17 29 //int microsecond counter, so have a max time of ~30mins
d_worrall 0:dd684fb95312 30 }