Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MCP23017 SDFileSystem USBDevice WattBob_TextLCD mbed
main.cpp
00001 /* Cyclic Executive 00002 This software is built to test (Cyclic Executive). 6 main tasks are used in and every one of them 00003 has its own time of repetition. To execute this, a Ticker was used to call a function every 4 mSec. 00004 In this software a benefit is a token from two counter, one is counting a pulses and it reset every 25 cycles. 00005 That mean it reset every 100 mSec. Then other counter (AllTimeCounter that count a 100 mSec) increased by one. 00006 A slot is defined for each function, for example the slot number 1 is to reading the two digital input. however 00007 this slote is for this function it is not excuted every slot 1. It is excuted just when the timer calculat 400 mSec. 00008 That is 100 cycles. Also, after 200 cycles (800 mSec) the condition is true for two factions, but the processor will 00009 implement one in slot 1 and next cycle implement the other. Excuting the LCD and writing file got more slote space. 00010 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) 00011 will be like this: 00012 __ __ __ __ __ __ __ __ __ __ 00013 | | | | | | | | | | | | | | | | | | | | 00014 | | | | | | | | | | | | | | | | | |----------------------| | 00015 __| |__| |__| |__| |__| |__| |__| |__| |__| |__ __| |__ 00016 <S1 > < S2> < S3 > < S4> < S5> < S6 > < S7 > 00017 00018 4 4 8 4 4 8 64 mSec 00019 ___ ___ ________ ___ ___ ________ __ __ 00020 | | | | | | | | | | | | | | | 00021 | | | | | | | | | | | | | ----------------------| | 00022 __| |_| |_| |_| |_| |_| |__| __| |__ 00023 00024 The full program ducimentation is on 00025 http://mbed.org/users/muaiyd/code/ass2/ 00026 */ 00027 #include "Function.h" 00028 #include "Display.h" 00029 #include "FreqMesure.h" 00030 #include "ReadInput.h" 00031 00032 uint16_t Counter = 0; 00033 uint16_t AllTimeCounter = 1; //It start from 1 to avoid excute all function at begining 00034 00035 void CycleFunction(); 00036 00037 int main(){ 00038 Init_LCD(); 00039 InitFile(); 00040 LogTimer.start(); 00041 Cycle.attach_us(&CycleFunction,4000); 00042 } 00043 00044 void CycleFunction(){ 00045 00046 /* 00047 We can see the period of execute time for every function below on the pin that 00048 assigned for each and writen infront of it. The least common multiple for all the above 00049 repeat time function is 180 Sec so every 180 Sec all the cycle is repeated. That mean 45000 00050 cycles. 00051 */ 00052 00053 Counter ++ ; 00054 switch(Counter){ 00055 case 1: 00056 if( AllTimeCounter % 4 == 0) ReadDigitalin(); //Pin 21 00057 break; 00058 case 2: 00059 if( AllTimeCounter % 8 ==0) ReadAnalogin(); //Pin 22 00060 break; 00061 case 3: 00062 if( AllTimeCounter % 10 == 0) FreqMsur(); //Pin 23 00063 break; 00064 case 5: 00065 if( AllTimeCounter % 15 == 0) BinaryCounter();//Pin 24 00066 break; 00067 case 6: 00068 if( AllTimeCounter % 18 == 0) InputCheck(); //Pin 25 00069 break; 00070 case 7: 00071 if( AllTimeCounter % 50 == 0 ) LogFile(); //Pin 27 00072 break; 00073 case 9: 00074 if( AllTimeCounter % 20 == 0 ) Display(); //Pin 26 00075 break; 00076 case 25: 00077 Counter = 0; 00078 AllTimeCounter ++ ; 00079 TickerPin = !(TickerPin); 00080 break; 00081 } 00082 if ( AllTimeCounter == 1800 ) AllTimeCounter = 0; 00083 }
Generated on Tue Jul 12 2022 21:34:48 by
