Mark Gottscho / HardwareTimersLib

Fork of HardwareTimersLib by Mark Gottscho

Revision:
11:e0442c8b182b
Parent:
10:12c1c5cef918
Child:
12:cb395e4be69e
--- a/Timer_TPM.cpp	Tue Mar 11 04:18:04 2014 +0000
+++ b/Timer_TPM.cpp	Tue Mar 11 04:54:13 2014 +0000
@@ -40,15 +40,14 @@
     
     //__disable_irq(); //CRITICAL SECTION -- ALL INTERRUPTS MUST BE STOPPED!
     TPM0->CNT = 0; //Need to write to the TPM CNT register in order to latch current value.
-    
+    tick = (uint16_t) TPM0->CNT; //Value was previously latched, just read it
+
     //It is theoretically possible that the timer interrupt is invoked here, between these two lines.
     //However, the timer doesn't appear to work properly if I put these two in a critical section.
     
     count = __count; //Latch current count value.
     //__enable_irq(); //END CRITICAL SECTION
     
-    tick = (uint16_t) TPM0->CNT; //Value was previously latched, just read it
-    
     //Convert to ticks
     return count * __rolloverValue + (uint32_t) tick;
 }