Measure the time interval between two consecutive rising edges

Dependencies:   dispBoB mbed PCA9635

Committer:
d_worrall
Date:
Tue Jul 12 10:04:32 2011 +0000
Revision:
2:62e168aedc9a
Parent:
1:b56440e55747

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
d_worrall 0:37bc70ca825c 1 #include "mbed.h"
d_worrall 0:37bc70ca825c 2 #include "dispBoB.h"
d_worrall 0:37bc70ca825c 3
d_worrall 0:37bc70ca825c 4 dispBoB db(p28, p27, p26); //instantiate a dispBoB object
d_worrall 0:37bc70ca825c 5 InterruptIn trigger(p12); //set up the trigger as an external interrupt
d_worrall 0:37bc70ca825c 6 Timer t;
d_worrall 0:37bc70ca825c 7
d_worrall 0:37bc70ca825c 8 bool b = false;
d_worrall 0:37bc70ca825c 9
d_worrall 1:b56440e55747 10 void trig(){ //function to call upon interrupt
d_worrall 0:37bc70ca825c 11 db.locate(0);
d_worrall 1:b56440e55747 12 db.printf("%06d", t.read_ms()); //print current time reading
d_worrall 0:37bc70ca825c 13 if(b == false){
d_worrall 1:b56440e55747 14 t.start(); //start timer
d_worrall 0:37bc70ca825c 15 b = true;
d_worrall 0:37bc70ca825c 16 } else {
d_worrall 1:b56440e55747 17 t.stop(); //stop timer
d_worrall 1:b56440e55747 18 db.printf("06d", t.read_ms()); //print out stopwatch time in milliseconds
d_worrall 1:b56440e55747 19 t.reset(); //reset and restart timer
d_worrall 0:37bc70ca825c 20 t.start();
d_worrall 0:37bc70ca825c 21 }
d_worrall 0:37bc70ca825c 22 }
d_worrall 0:37bc70ca825c 23
d_worrall 0:37bc70ca825c 24 int main() {
d_worrall 0:37bc70ca825c 25 trigger.mode(PullUp); //activate internal pull up (hardware specific)
d_worrall 1:b56440e55747 26 db.init(); //ALWAYS initialise the dispBoB
d_worrall 2:62e168aedc9a 27 db.cls();
d_worrall 2:62e168aedc9a 28 trigger.rise(&trig); //attach trig() to interrupt on rising edge of trigger
d_worrall 0:37bc70ca825c 29
d_worrall 1:b56440e55747 30 db.printf("%06d", t.read_ms()); //print initial time reading (000000)
d_worrall 0:37bc70ca825c 31
d_worrall 2:62e168aedc9a 32 //To change the timebase just replace the read_ms() function with
d_worrall 2:62e168aedc9a 33 //read() for seconds and read_us() for microseconds. These use a 32bit
d_worrall 2:62e168aedc9a 34 //int microsecond counter, so have a max time of ~30mins
d_worrall 0:37bc70ca825c 35 }