Sample prog to test timer aspects
Dependencies: TextLCD mbed-src
Testing mbed Timer
Revision 2:a8c19b073684, committed 2015-03-30
- Comitter:
- eduardoG26
- Date:
- Mon Mar 30 15:33:35 2015 +0000
- Parent:
- 1:fa206fcadfad
- Commit message:
- bugfix: timer mask
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r fa206fcadfad -r a8c19b073684 main.cpp --- a/main.cpp Mon Mar 30 14:44:14 2015 +0000 +++ b/main.cpp Mon Mar 30 15:33:35 2015 +0000 @@ -10,10 +10,17 @@ TextLCD_I2C lcd(&i2c_lcd, 0x40, TextLCD::LCD16x2); // I2C bus, PCF8574 Slaveaddress, LCD Type +// Trick to change baudrate of stdout, SFord +void baud(int baudrate) +{ + Serial s(USBTX, USBRX); + s.baud(baudrate); +} + int main() { uint32_t Millis, LastMillis; - + baud(921600); // see function above i2c_lcd.frequency(400000); // 400KHz lcd.setCursor(lcd.CurOff_BlkOff); // Cursor off, Blink off lcd.cls(); @@ -22,17 +29,20 @@ lcd.printf("Testing Timer...\n"); lcd.locate(0,1); // Goto beginning of line = second par. lcd.printf("...us overflow \n"); - printf("Testing Timer us overflow\n"); + printf("\nTesting Timer us overflow..\n"); t.reset(); t.start(); - Millis = t.read_ms() & 0x2000; + +#define TIMER_MASK (0x1000uL - 1) + + Millis = t.read_ms() & TIMER_MASK; lcd.locate(0,1); // Goto beginning of line = second par. lcd.printf("Start M: %08d",Millis); do { LastMillis = Millis; - Millis = t.read_ms() & 0x2000; + Millis = t.read_ms() & TIMER_MASK; } while(LastMillis <= Millis); lcd.locate(0,0); // Goto beginning of line = second par. @@ -40,6 +50,6 @@ lcd.locate(0,1); lcd.printf("Act. M: %08d",Millis); - printf("Last Millis: %08d",LastMillis); - printf("Act. Millis: %08d",Millis); + printf("Last Millis: %08d\n",LastMillis); + printf("Act. Millis: %08d\n",Millis); }