Embedded software Assessment 2

Dependencies:   MCP23017 SDFileSystem USBDevice WattBob_TextLCD mbed

Committer:
muaiyd
Date:
Tue Mar 04 21:49:29 2014 +0000
Revision:
21:0e681d5fa3ba
Parent:
20:00a9a95ef083
Child:
22:644d53f1f291
END

Who changed what in which revision?

UserRevisionLine numberNew contents of line
muaiyd 18:f485d46a7acb 1 /* Cyclic Executive
muaiyd 21:0e681d5fa3ba 2 This software is built to test (Cyclic Executive). 6 main tasks are used in and every one of them
muaiyd 21:0e681d5fa3ba 3 has its own time of repetition. To execute this, a Ticker was used to call a function every 4 mSec.
muaiyd 21:0e681d5fa3ba 4 In this software a benefit is a token from two counter, one is counting a pulses and it reset every 25 cycles.
muaiyd 21:0e681d5fa3ba 5 That mean it reset every 100 mSec. Then other counter (AllTimeCounter that count a 100 mSec) increased by one.
muaiyd 21:0e681d5fa3ba 6 A slot is defined for each function, for example the slot number 1 is to reading the two digital input. however
muaiyd 21:0e681d5fa3ba 7 this slote is for this function it is not excuted every slot 1. It is excuted just when the timer calculat 400 mSec.
muaiyd 21:0e681d5fa3ba 8 That is 100 cycles. Also, after 200 cycles (800 mSec) the condition is true for two factions, but the processor will
muaiyd 21:0e681d5fa3ba 9 implement one in slot 1 and next cycle implement the other. Excuting the LCD and writing file got more slote space.
muaiyd 21:0e681d5fa3ba 10 The LCD show slot is 72 mSec and the writing is 8 mSec. At A Sec 180 all functions are called and the 1800 (100 mSec)
muaiyd 21:0e681d5fa3ba 11 will be like this:
muaiyd 21:0e681d5fa3ba 12 __ __ __ __ __ __ __ __ __ __
muaiyd 21:0e681d5fa3ba 13 | | | | | | | | | | | | | | | | | | | |
muaiyd 21:0e681d5fa3ba 14 | | | | | | | | | | | | | | | | | |-----------------| |
muaiyd 21:0e681d5fa3ba 15 __| |__| |__| |__| |__| |__| |__| |__| |__| | |__|
muaiyd 21:0e681d5fa3ba 16 < S1 > < S2> < S3> < S4> < S5> < S6 > < S7 >
muaiyd 21:0e681d5fa3ba 17 4 4 4 4 4 8 72 mSec
muaiyd 21:0e681d5fa3ba 18
muaiyd 20:00a9a95ef083 19 The full program ducimentation is on
muaiyd 20:00a9a95ef083 20 http://mbed.org/users/muaiyd/code/ass2/
muaiyd 16:0a2138a18f26 21 */
muaiyd 0:86bba6bf9b6f 22 #include "Function.h"
muaiyd 20:00a9a95ef083 23 #include "Display.h"
muaiyd 20:00a9a95ef083 24 #include "FreqMesure.h"
muaiyd 20:00a9a95ef083 25 #include "ReadInput.h"
muaiyd 16:0a2138a18f26 26
muaiyd 20:00a9a95ef083 27 uint16_t Counter = 0;
muaiyd 20:00a9a95ef083 28 uint16_t AllTimeCounter = 1; //It start from 1 to avoid excute all function at begining
muaiyd 20:00a9a95ef083 29
muaiyd 16:0a2138a18f26 30 void CycleFunction();
muaiyd 0:86bba6bf9b6f 31
muaiyd 0:86bba6bf9b6f 32 int main(){
muaiyd 0:86bba6bf9b6f 33 Init_LCD();
muaiyd 12:582753a4f1fb 34 InitFile();
muaiyd 16:0a2138a18f26 35 LogTimer.start();
muaiyd 21:0e681d5fa3ba 36 Cycle.attach_us(&CycleFunction,4000);
muaiyd 16:0a2138a18f26 37 }
muaiyd 16:0a2138a18f26 38
muaiyd 16:0a2138a18f26 39 void CycleFunction(){
muaiyd 20:00a9a95ef083 40
muaiyd 20:00a9a95ef083 41 /*
muaiyd 20:00a9a95ef083 42 We can see the period of execute time for every function below on the pin that
muaiyd 20:00a9a95ef083 43 assigned for each and writen infront of it. The least common multiple for all the above
muaiyd 21:0e681d5fa3ba 44 repeat time function is 180 Sec so every 180 Sec all the cycle is repeated. That mean 45000
muaiyd 20:00a9a95ef083 45 cycles.
muaiyd 20:00a9a95ef083 46 */
muaiyd 20:00a9a95ef083 47
muaiyd 20:00a9a95ef083 48 Counter ++ ;
muaiyd 20:00a9a95ef083 49 switch(Counter){
muaiyd 20:00a9a95ef083 50 case 1:
muaiyd 20:00a9a95ef083 51 if( AllTimeCounter % 4 == 0) ReadDigitalin(); //Pin 21
muaiyd 20:00a9a95ef083 52 break;
muaiyd 20:00a9a95ef083 53 case 2:
muaiyd 20:00a9a95ef083 54 if( AllTimeCounter % 8 ==0) ReadAnalogin(); //Pin 22
muaiyd 20:00a9a95ef083 55 break;
muaiyd 20:00a9a95ef083 56 case 3:
muaiyd 20:00a9a95ef083 57 if( AllTimeCounter % 10 == 0) FreqMsur(); //Pin 23
muaiyd 20:00a9a95ef083 58 break;
muaiyd 20:00a9a95ef083 59 case 4:
muaiyd 20:00a9a95ef083 60 if( AllTimeCounter % 15 == 0) BinaryCounter();//Pin 24
muaiyd 20:00a9a95ef083 61 break;
muaiyd 20:00a9a95ef083 62 case 5:
muaiyd 20:00a9a95ef083 63 if( AllTimeCounter % 18 == 0) InputCheck(); //Pin 25
muaiyd 20:00a9a95ef083 64 break;
muaiyd 20:00a9a95ef083 65 case 6:
muaiyd 20:00a9a95ef083 66 if( AllTimeCounter % 50 == 0 ) LogFile(); //Pin 27
muaiyd 20:00a9a95ef083 67 break;
muaiyd 20:00a9a95ef083 68 case 8:
muaiyd 21:0e681d5fa3ba 69 if( AllTimeCounter % 20 == 0 ) Display(); //Pin 26
muaiyd 21:0e681d5fa3ba 70 break;
muaiyd 21:0e681d5fa3ba 71 case 25:
muaiyd 20:00a9a95ef083 72 Counter = 0;
muaiyd 20:00a9a95ef083 73 AllTimeCounter ++ ;
muaiyd 20:00a9a95ef083 74 TickerPin = !(TickerPin);
muaiyd 20:00a9a95ef083 75 break;
muaiyd 20:00a9a95ef083 76 }
muaiyd 21:0e681d5fa3ba 77 if ( AllTimeCounter == 1800 ) AllTimeCounter = 0;
muaiyd 0:86bba6bf9b6f 78 }