changeset 175:f7a234e8e089 main

Compute RPM and track total ticks.
author Bob Cook <bob@bobcookdev.com>
date Sun, 31 Mar 2013 15:35:32 -0700
parents 7bfb98e62138
children 12681b419e60
files main/demos/avr/ls7366-demo/main.cpp
diffstat 1 files changed, 12 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/main/demos/avr/ls7366-demo/main.cpp	Wed Feb 06 21:46:34 2013 -0800
+++ b/main/demos/avr/ls7366-demo/main.cpp	Sun Mar 31 15:35:32 2013 -0700
@@ -120,7 +120,9 @@
     uint32_t cntr_last = 0;
 
     uint32_t last_diffs[ 10 ];
-    uint32_t index = 0;
+    uint8_t  index = 0;
+    
+    uint32_t total_ticks = 0;
 
     for ( ;; )
     {
@@ -129,23 +131,26 @@
         uint8_t  dir;
         uint32_t diff = ls7366_compute_diff( cntr_last, cntr, &dir );
 
+        total_ticks += diff;
+
         last_diffs[ index++ ] = diff;
         index %= 10;
 
         if ( index == 0 )
         {
-            uint32_t sum = 0;
+            uint32_t total_per_second = 0;
 
             for ( uint8_t i = 0; i < 10; ++i )
             {
-                sum += last_diffs[ i ];
+                total_per_second += last_diffs[ i ];
             }
 
-            uint32_t avg = ( sum + 51 ) / 100;
+            uint32_t rpm = total_per_second * 100 / 30900L;
 
-            printf_P( PSTR("\r average %ld (%ld per second) dir: %s        "),
-                      avg,
-                      sum,
+            printf_P( PSTR("\r total %ld rpm %ld (%ld per second) dir: %s        "),
+                      total_ticks,
+                      rpm,
+                      total_per_second,
                       ( dir == 0 ? "up" : "down" ) );
         }