![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Embedded software Assessment 2
Dependencies: MCP23017 SDFileSystem USBDevice WattBob_TextLCD mbed
Diff: main.cpp
- Revision:
- 20:00a9a95ef083
- Parent:
- 19:304b17087d06
- Child:
- 21:0e681d5fa3ba
diff -r 304b17087d06 -r 00a9a95ef083 main.cpp --- a/main.cpp Tue Mar 04 17:08:22 2014 +0000 +++ b/main.cpp Tue Mar 04 18:42:38 2014 +0000 @@ -1,42 +1,69 @@ /* Cyclic Executive 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. -http://mbed.org/users/muaiyd/code/ass2/ +has its own time of repetition. To execute this, a Ticker was used to call a function every 12.5 mSec. +In this software a benefit is a token from two counter, one is counting a pulses and it reset every 8 cycles. +That mean it reset every 100 mSec. Then other counter (AllTimeCounter) increased by one. Every slot in the 8 slots +has a defined function, for example the slot number 1 is to reading the two digital input. however this slote is +for this function it is not excuted every slot 1. It excute just when the timer calculat 400 mSec. That is 4X8 +cycles. Also, after 8X8 cycles (800 mSec) the condition is true for two factions, but the processor will +implement one in slot 1 and next cycle implement the other. + The full program ducimentation is on + http://mbed.org/users/muaiyd/code/ass2/ */ #include "Function.h" +#include "Display.h" +#include "FreqMesure.h" +#include "ReadInput.h" -uint16_t Counter=0; +uint16_t Counter = 0; +uint16_t AllTimeCounter = 1; //It start from 1 to avoid excute all function at begining + void CycleFunction(); int main(){ Init_LCD(); InitFile(); LogTimer.start(); - //Call the CycleFunction every 100 msec can see that on pin30 - Cycle.attach(&CycleFunction,0.1); + Cycle.attach(&CycleFunction,0.0125); } void CycleFunction(){ - TickerPin = !(TickerPin); - //Can see the period of execute every function below on the pin that - //writen infront of it - //The least common multiple for all the above is 1800 cycles - // so every 180 Sec all the functions are repeated - Counter++; - if(Counter == 1800) Counter = 0; - - if( Counter % 4 == 0) ReadDigitalin(); //Pin 21 - if( Counter % 8 ==0) ReadAnalogin(); //Pin 22 - if( Counter % 10 == 0) FreqMsur(); //Pin 23 - if( Counter % 15 == 0) BinaryCounter();//Pin 24 - if( Counter % 18 == 0) InputCheck(); //Pin 25 - if( Counter % 20 == 0 ) Display(); //Pin 26 - if( Counter % 50 == 0 ) LogFile(); //Pin 27 - + +/* + We can see the period of execute time for every function below on the pin that + assigned for each and writen infront of it. The least common multiple for all the above + repeat time function is 180 Sec so every 180 Sec all the cycle is repeated. That mean 14400 + cycles. +*/ + + Counter ++ ; + switch(Counter){ + case 1: + if( AllTimeCounter % 4 == 0) ReadDigitalin(); //Pin 21 + break; + case 2: + if( AllTimeCounter % 8 ==0) ReadAnalogin(); //Pin 22 + break; + case 3: + if( AllTimeCounter % 10 == 0) FreqMsur(); //Pin 23 + break; + case 4: + if( AllTimeCounter % 15 == 0) BinaryCounter();//Pin 24 + break; + case 5: + if( AllTimeCounter % 18 == 0) InputCheck(); //Pin 25 + break; + case 6: + if( AllTimeCounter % 20 == 0 ) Display(); //Pin 26 + break; + case 7: + if( AllTimeCounter % 50 == 0 ) LogFile(); //Pin 27 + break; + case 8: + Counter = 0; + AllTimeCounter ++ ; + TickerPin = !(TickerPin); + break; + } + if ( AllTimeCounter == 14400 ) AllTimeCounter = 0; } \ No newline at end of file