Measure the width (time-wise) of an incoming pulse.
Dependencies: dispBoB mbed PCA9635
counter.cpp@1:f04131cae8b8, 2011-07-11 (annotated)
- Committer:
- d_worrall
- Date:
- Mon Jul 11 13:57:07 2011 +0000
- Revision:
- 1:f04131cae8b8
- Parent:
- 0:dd684fb95312
- Child:
- 2:bb7e46464d17
version2
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:dd684fb95312 | 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 | 1:f04131cae8b8 | 21 | db.init(); //again ALWAYS initialise dispBoB |
d_worrall | 0:dd684fb95312 | 22 | db.cls(); //clear screen |
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 | 0:dd684fb95312 | 25 | db.printf("%06d", t.read_ms()); //display an inital count "000000" |
d_worrall | 0:dd684fb95312 | 26 | } |