senior design
Dependencies: mbed
Fork of Test1 by
main.cpp@0:1da3cc3bc3a5, 2010-12-02 (annotated)
- Committer:
- powerstrokediesel97
- Date:
- Thu Dec 02 07:21:02 2010 +0000
- Revision:
- 0:1da3cc3bc3a5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
powerstrokediesel97 | 0:1da3cc3bc3a5 | 1 | #include "mbed.h" |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 2 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 3 | Serial transmit(p28,p27); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 4 | Timer t; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 5 | InterruptIn risingEdge(p16); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 6 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 7 | DigitalOut myled(LED1); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 8 | DigitalOut myled2(LED2); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 9 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 10 | long int count; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 11 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 12 | //Increment the counter variable |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 13 | void pulses() { |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 14 | if(myled2 == 1) { |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 15 | myled2 = 0; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 16 | } else { |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 17 | myled2 = 1; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 18 | } |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 19 | count++; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 20 | } |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 21 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 22 | //main program |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 23 | int main() { |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 24 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 25 | risingEdge.rise(&pulses); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 26 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 27 | while(1) { |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 28 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 29 | // myled = 0; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 30 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 31 | t.reset(); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 32 | t.start(); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 33 | count = 0; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 34 | while(t.read_ms() < 400) { |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 35 | ; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 36 | } |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 37 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 38 | t.stop(); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 39 | // myled = 1; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 40 | long int temp = count; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 41 | // lcdout.putc(0xFE); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 42 | // lcdout.putc(0x01); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 43 | // lcdout.printf("Count: %d\n", temp); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 44 | // transmit.printf("Count: %d", temp); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 45 | double rev = (double)temp/30.0; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 46 | double sec = 1000.0/(double)t.read_ms(); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 47 | double rps = rev * sec; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 48 | double rpm = rps*60.0; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 49 | int irpm = (int)rpm; |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 50 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 51 | //lcdout.printf("Speed: %0.2f RPM", rpm); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 52 | // transmit.printf(" Speed: %0.2f RPM", rpm); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 53 | transmit.printf("%d", irpm); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 54 | // transmit.putc(0xA); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 55 | transmit.putc(0xD); |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 56 | } |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 57 | } |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 58 | |
powerstrokediesel97 | 0:1da3cc3bc3a5 | 59 |