WIP

Dependencies:   mbed

Committer:
mnewton1
Date:
Sat Apr 06 17:16:49 2013 +0000
Revision:
0:c146143219c5
Work in progress.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mnewton1 0:c146143219c5 1 #include "mbed.h"
mnewton1 0:c146143219c5 2
mnewton1 0:c146143219c5 3 volatile int rpmcount;
mnewton1 0:c146143219c5 4 unsigned int rpm;
mnewton1 0:c146143219c5 5 unsigned long timeold;
mnewton1 0:c146143219c5 6
mnewton1 0:c146143219c5 7 InterruptIn speed(p9);
mnewton1 0:c146143219c5 8
mnewton1 0:c146143219c5 9 void setup()
mnewton1 0:c146143219c5 10 {
mnewton1 0:c146143219c5 11
mnewton1 0:c146143219c5 12 rpmcount = 0;
mnewton1 0:c146143219c5 13 rpm = 0;
mnewton1 0:c146143219c5 14 timeold = 0;
mnewton1 0:c146143219c5 15 }
mnewton1 0:c146143219c5 16
mnewton1 0:c146143219c5 17 void loop()
mnewton1 0:c146143219c5 18 {
mnewton1 0:c146143219c5 19 if (rpmcount >= 20) {
mnewton1 0:c146143219c5 20 //Update RPM every 20 counts, increase this for better RPM resolution,
mnewton1 0:c146143219c5 21 //decrease for faster update
mnewton1 0:c146143219c5 22 rpm = 30*1000/(millis() - timeold)*rpmcount;
mnewton1 0:c146143219c5 23 timeold = millis();
mnewton1 0:c146143219c5 24 rpmcount = 0;
mnewton1 0:c146143219c5 25 Serial.println(rpm,DEC);
mnewton1 0:c146143219c5 26 }
mnewton1 0:c146143219c5 27 }
mnewton1 0:c146143219c5 28 void rpm_fun()
mnewton1 0:c146143219c5 29 {
mnewton1 0:c146143219c5 30 rpmcount++;
mnewton1 0:c146143219c5 31 //Each rotation, this interrupt function is run twice
mnewton1 0:c146143219c5 32 }