Embedded software Assessment 2

Dependencies:   MCP23017 SDFileSystem USBDevice WattBob_TextLCD mbed

Committer:
muaiyd
Date:
Wed Mar 05 13:26:51 2014 +0000
Revision:
23:ffd758e50c3a
Parent:
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 22:644d53f1f291 12 __ __ __ __ __ __ __ __ __ __
muaiyd 22:644d53f1f291 13 | | | | | | | | | | | | | | | | | | | |
muaiyd 22:644d53f1f291 14 | | | | | | | | | | | | | | | | | |----------------------| |
muaiyd 22:644d53f1f291 15 __| |__| |__| |__| |__| |__| |__| |__| |__| |__ __| |__
muaiyd 22:644d53f1f291 16 <S1 > < S2> < S3 > < S4> < S5> < S6 > < S7 >
muaiyd 22:644d53f1f291 17
muaiyd 22:644d53f1f291 18 4 4 8 4 4 8 64 mSec
muaiyd 22:644d53f1f291 19 ___ ___ ________ ___ ___ ________ __ __
muaiyd 22:644d53f1f291 20 | | | | | | | | | | | | | | |
muaiyd 22:644d53f1f291 21 | | | | | | | | | | | | | ----------------------| |
muaiyd 22:644d53f1f291 22 __| |_| |_| |_| |_| |_| |__| __| |__
muaiyd 21:0e681d5fa3ba 23
muaiyd 20:00a9a95ef083 24 The full program ducimentation is on
muaiyd 20:00a9a95ef083 25 http://mbed.org/users/muaiyd/code/ass2/
muaiyd 16:0a2138a18f26 26 */
muaiyd 0:86bba6bf9b6f 27 #include "Function.h"
muaiyd 20:00a9a95ef083 28 #include "Display.h"
muaiyd 20:00a9a95ef083 29 #include "FreqMesure.h"
muaiyd 20:00a9a95ef083 30 #include "ReadInput.h"
muaiyd 16:0a2138a18f26 31
muaiyd 20:00a9a95ef083 32 uint16_t Counter = 0;
muaiyd 20:00a9a95ef083 33 uint16_t AllTimeCounter = 1; //It start from 1 to avoid excute all function at begining
muaiyd 20:00a9a95ef083 34
muaiyd 16:0a2138a18f26 35 void CycleFunction();
muaiyd 0:86bba6bf9b6f 36
muaiyd 0:86bba6bf9b6f 37 int main(){
muaiyd 0:86bba6bf9b6f 38 Init_LCD();
muaiyd 12:582753a4f1fb 39 InitFile();
muaiyd 16:0a2138a18f26 40 LogTimer.start();
muaiyd 21:0e681d5fa3ba 41 Cycle.attach_us(&CycleFunction,4000);
muaiyd 16:0a2138a18f26 42 }
muaiyd 16:0a2138a18f26 43
muaiyd 16:0a2138a18f26 44 void CycleFunction(){
muaiyd 20:00a9a95ef083 45
muaiyd 20:00a9a95ef083 46 /*
muaiyd 20:00a9a95ef083 47 We can see the period of execute time for every function below on the pin that
muaiyd 20:00a9a95ef083 48 assigned for each and writen infront of it. The least common multiple for all the above
muaiyd 21:0e681d5fa3ba 49 repeat time function is 180 Sec so every 180 Sec all the cycle is repeated. That mean 45000
muaiyd 20:00a9a95ef083 50 cycles.
muaiyd 20:00a9a95ef083 51 */
muaiyd 20:00a9a95ef083 52
muaiyd 20:00a9a95ef083 53 Counter ++ ;
muaiyd 20:00a9a95ef083 54 switch(Counter){
muaiyd 20:00a9a95ef083 55 case 1:
muaiyd 20:00a9a95ef083 56 if( AllTimeCounter % 4 == 0) ReadDigitalin(); //Pin 21
muaiyd 20:00a9a95ef083 57 break;
muaiyd 20:00a9a95ef083 58 case 2:
muaiyd 20:00a9a95ef083 59 if( AllTimeCounter % 8 ==0) ReadAnalogin(); //Pin 22
muaiyd 20:00a9a95ef083 60 break;
muaiyd 20:00a9a95ef083 61 case 3:
muaiyd 20:00a9a95ef083 62 if( AllTimeCounter % 10 == 0) FreqMsur(); //Pin 23
muaiyd 20:00a9a95ef083 63 break;
muaiyd 22:644d53f1f291 64 case 5:
muaiyd 20:00a9a95ef083 65 if( AllTimeCounter % 15 == 0) BinaryCounter();//Pin 24
muaiyd 20:00a9a95ef083 66 break;
muaiyd 22:644d53f1f291 67 case 6:
muaiyd 20:00a9a95ef083 68 if( AllTimeCounter % 18 == 0) InputCheck(); //Pin 25
muaiyd 20:00a9a95ef083 69 break;
muaiyd 22:644d53f1f291 70 case 7:
muaiyd 20:00a9a95ef083 71 if( AllTimeCounter % 50 == 0 ) LogFile(); //Pin 27
muaiyd 20:00a9a95ef083 72 break;
muaiyd 22:644d53f1f291 73 case 9:
muaiyd 21:0e681d5fa3ba 74 if( AllTimeCounter % 20 == 0 ) Display(); //Pin 26
muaiyd 21:0e681d5fa3ba 75 break;
muaiyd 21:0e681d5fa3ba 76 case 25:
muaiyd 20:00a9a95ef083 77 Counter = 0;
muaiyd 20:00a9a95ef083 78 AllTimeCounter ++ ;
muaiyd 20:00a9a95ef083 79 TickerPin = !(TickerPin);
muaiyd 20:00a9a95ef083 80 break;
muaiyd 20:00a9a95ef083 81 }
muaiyd 21:0e681d5fa3ba 82 if ( AllTimeCounter == 1800 ) AllTimeCounter = 0;
muaiyd 0:86bba6bf9b6f 83 }