Embedded software Assessment 2

Dependencies:   MCP23017 SDFileSystem USBDevice WattBob_TextLCD mbed

Revision:
16:0a2138a18f26
Parent:
13:6094b94b3b7c
Child:
17:dba09fb3f508
--- a/main.cpp	Wed Feb 26 11:55:20 2014 +0000
+++ b/main.cpp	Wed Feb 26 22:09:17 2014 +0000
@@ -1,13 +1,38 @@
+/*
+This software is built to test (Cyclic Executive). Five main functions are used in and every one of them
+has its own time of repetition. To execute this, a Ticker was used to call a function every 100 mSec.
+In other words, when 100 mSec is passed, the Cycle function is called and so on every 100 mSec. In this
+software a benefit is a token place for the difference between a float division with integer one. For example
+float(Counter/4.0)-Counter/4 if the Counter is a real repetition of 4 so the result of this will be 0. As a 
+result every 4 cycle (400 mSec) the condition be true and calling the function. Also, after 8 cycles (800 mSec)
+the condition is true for two factions, but the processor will implement on the priority that it was put in 
+the program.
+
+*/
 #include "Function.h"
+
+uint16_t Counter=0;
+void CycleFunction(); 
  
 int main(){
     Init_LCD();
     InitFile();
-    CallFreqMsur.attach(&FreqMsur,1);      //Measure the frequency every 400mS
-    CallReadDigitalin.attach(&ReadDigitalin,0.4);    //Read TWO digital inputs every 400mS
-    CallReadAnalogin.attach(&ReadAnalogin,0.8);    //Read TWO analogue inputs every 800mS
-    CallDisplay.attach(&Display,2);      //Display on the LCD every 2 seconds
-    CallInputCheck.attach(&InputCheck,1.8);    //Input Check every 1.8 second
-    CallBinaryCounter.attach(&BinaryCounter,1.5);    //Binary increment every 1.5 second
-    CallLogFile.attach(&LogFile,5);      //Log the values every 5 seconds
+    LogTimer.start();
+    //Call the CycleFunction every 100 msec
+    Cycle.attach(&CycleFunction,0.1);      
+}
+
+void CycleFunction(){
+    TickerPin=!(TickerPin);
+    Counter++;
+    if((float(Counter/4.0)-Counter/4)==0) ReadDigitalin();
+    if((float(Counter/8.0)-Counter/8)==0) ReadAnalogin();
+    if((float(Counter/10.0)-Counter/10)==0) FreqMsur();
+    if((float(Counter/15.0)-Counter/15)==0) BinaryCounter();
+    if((float(Counter/18.0)-Counter/18)==0) InputCheck();
+    if((float(Counter/20.0)-Counter/20)==0) Display();
+    if((float(Counter/50.0)-Counter/50)==0) LogFile();
+    //The least common multiple for all the above is 1800 cycles
+    // so every 180 Sec all the functions are repeated
+    if(Counter==1800) Counter=0;  
 }
\ No newline at end of file