Charles Young's development fork. Going forward I only want to push mature code to main repository.

Dependencies:   mbed

Fork of GEO_COUNTER_L432KC by Geo Electronics "Geo Counter"

Revision:
53:04999d536e92
Parent:
52:6386fd7a2ded
Child:
54:7dbd1f39dc33
--- a/main.cpp	Sat Sep 08 16:58:00 2018 -0700
+++ b/main.cpp	Sat Sep 08 21:13:57 2018 -0700
@@ -58,6 +58,9 @@
 
 uint32_t    Count1, Count2;    // pulse counters (32-bit)
 int32_t     TickerCorrection = 0;
+uint32_t    TickerPeriod = 100000;
+uint32_t    TickerPeriodCount = 0;
+const uint32_t TickerPeriodsPerSecond = 1000000/TickerPeriod;
 const int16_t TickerCorrectionMax = 99;
 const int16_t TickerCorrectionMin = -99;
 
@@ -74,6 +77,7 @@
 // ----- Prototypes of routines (defined below the main) -------------------
 void UpdateInput(void);  // periodically called by the ticker
 void UpdateOutput(void);  // periodically called by the ticker
+void UpdateIO(void);  // periodically called by the ticker
 void Count1_up(void);  // called every time an edge is detected on TRIG1 pin
 void Count2_up(void); // called every time an edge is detected on TRIG2 pin
 void Beep(void);    // used to generate a short beep (buzzer)
@@ -110,8 +114,7 @@
    // set the 1 sec ticker to periodically call the Update() routine
    // NOTE: this is also the 1-sec time base for counters. A better approach
    // would replace the ticker with an interrupt from the RTC (to be implemented)
-   SecTenth_Beat.attach_us(&UpdateInput,  100000);  
-   Sec_Beat.attach_us(&UpdateOutput, 1000000);  
+   SecTenth_Beat.attach_us(&UpdateIO,  TickerPeriod);
    //RTC::attach(&Update, RTC::Second);
    //RTC::detach(RTC::Second);  
   
@@ -141,7 +144,17 @@
    PC.printf(" wheel %f", direction);
 }
 
-void UpdateOutput()   
+void UpdateIO()   
+{
+   if (++TickerPeriodCount >= TickerPeriodsPerSecond)
+   {
+      TickerPeriodCount = 0;
+      UpdateOutput();
+   }
+   UpdateInput();
+}
+
+void UpdateOutput()
 {
    // Capture the counts early so they will be more accurate
    uint32_t Count1Save = Count1;
@@ -258,21 +271,21 @@
          break;
    }
 
-   // ADC_val = KEYB.read();  // read voltage from keyboard
-   // if (   (ADC_val<0.1)    // START/STOP pushbutton pressed
-   //     && (!StartStopPressed))
-   // {
-   //    StartStopPressed = true;
-   //    Stopped=!Stopped;           // toggle status
-   // }
-   // else
-   //    StartStopPressed = false;
+   ADC_val = KEYB.read();  // read voltage from keyboard
+   if (   (ADC_val<0.1)    // START/STOP pushbutton pressed
+       && (!StartStopPressed))
+   {
+      StartStopPressed = true;
+      Stopped=!Stopped;           // toggle status
+   }
+   else
+      StartStopPressed = false;
     
-   // if((ADC_val>0.6)&&(ADC_val<0.7))    // CLEAR pushbutton pressed
-   // { 
-   //    Count1 = 0; // clear counters     
-   //    Count2 = 0;              
-   // }
+   if((ADC_val>0.6)&&(ADC_val<0.7))    // CLEAR pushbutton pressed
+   { 
+      Count1 = 0; // clear counters     
+      Count2 = 0;              
+   }
    // logToPC();
    return;
 }