in-file config of the TemperatureControl, and simple adjustments to make
[clinton/Smoothieware.git] / src / libs / SlowTicker.cpp
index 437133c..dad4579 100644 (file)
@@ -11,17 +11,17 @@ SlowTicker* global_slow_ticker;
 
 SlowTicker::SlowTicker(){
     global_slow_ticker = this;
-    LPC_SC->PCONP |= (1 << 22);
-    LPC_TIM2->MR0 = 1000000; 
-    LPC_TIM2->MCR = 3;
-    LPC_TIM2->TCR = 1; 
-    NVIC_EnableIRQ(TIMER2_IRQn);
+    LPC_SC->PCONP |= (1 << 22);     // Power Ticker ON
+    LPC_TIM2->MR0 = 1000000;        // Initial dummy value for Match Register
+    LPC_TIM2->MCR = 3;              // Match on MR0, reset on MR0
+    LPC_TIM2->TCR = 1;              // Enable interrupt
+    NVIC_EnableIRQ(TIMER2_IRQn);    // Enable interrupt handler
 }
 
 void SlowTicker::set_frequency( int frequency ){
-    LPC_TIM2->MR0 = int(floor((SystemCoreClock/4)/frequency));
-    LPC_TIM2->TCR = 3; 
-    LPC_TIM2->TCR = 1; 
+    LPC_TIM2->MR0 = int(floor((SystemCoreClock/4)/frequency));  // SystemCoreClock/4 = Timer increments in a second
+    LPC_TIM2->TCR = 3;  // Reset
+    LPC_TIM2->TCR = 1;  // Reset
 }
 
 void SlowTicker::tick(){
@@ -31,8 +31,8 @@ void SlowTicker::tick(){
 }
 
 extern "C" void TIMER2_IRQHandler (void){
-    if((LPC_TIM2->IR >> 0) & 1){
-        LPC_TIM2->IR |= 1 << 0;
+    if((LPC_TIM2->IR >> 0) & 1){  // If interrupt register set for MR0
+        LPC_TIM2->IR |= 1 << 0;   // Reset it 
         global_slow_ticker->tick(); 
     }
 }