Embedded software Assessment 2
Dependencies: MCP23017 SDFileSystem USBDevice WattBob_TextLCD mbed
main.cpp@20:00a9a95ef083, 2014-03-04 (annotated)
- Committer:
- muaiyd
- Date:
- Tue Mar 04 18:42:38 2014 +0000
- Revision:
- 20:00a9a95ef083
- Parent:
- 19:304b17087d06
- Child:
- 21:0e681d5fa3ba
I finish it !!!!!!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
muaiyd | 18:f485d46a7acb | 1 | /* Cyclic Executive |
muaiyd | 16:0a2138a18f26 | 2 | This software is built to test (Cyclic Executive). Five main functions are used in and every one of them |
muaiyd | 20:00a9a95ef083 | 3 | has its own time of repetition. To execute this, a Ticker was used to call a function every 12.5 mSec. |
muaiyd | 20:00a9a95ef083 | 4 | In this software a benefit is a token from two counter, one is counting a pulses and it reset every 8 cycles. |
muaiyd | 20:00a9a95ef083 | 5 | That mean it reset every 100 mSec. Then other counter (AllTimeCounter) increased by one. Every slot in the 8 slots |
muaiyd | 20:00a9a95ef083 | 6 | has a defined function, for example the slot number 1 is to reading the two digital input. however this slote is |
muaiyd | 20:00a9a95ef083 | 7 | for this function it is not excuted every slot 1. It excute just when the timer calculat 400 mSec. That is 4X8 |
muaiyd | 20:00a9a95ef083 | 8 | cycles. Also, after 8X8 cycles (800 mSec) the condition is true for two factions, but the processor will |
muaiyd | 20:00a9a95ef083 | 9 | implement one in slot 1 and next cycle implement the other. |
muaiyd | 20:00a9a95ef083 | 10 | The full program ducimentation is on |
muaiyd | 20:00a9a95ef083 | 11 | http://mbed.org/users/muaiyd/code/ass2/ |
muaiyd | 16:0a2138a18f26 | 12 | */ |
muaiyd | 0:86bba6bf9b6f | 13 | #include "Function.h" |
muaiyd | 20:00a9a95ef083 | 14 | #include "Display.h" |
muaiyd | 20:00a9a95ef083 | 15 | #include "FreqMesure.h" |
muaiyd | 20:00a9a95ef083 | 16 | #include "ReadInput.h" |
muaiyd | 16:0a2138a18f26 | 17 | |
muaiyd | 20:00a9a95ef083 | 18 | uint16_t Counter = 0; |
muaiyd | 20:00a9a95ef083 | 19 | uint16_t AllTimeCounter = 1; //It start from 1 to avoid excute all function at begining |
muaiyd | 20:00a9a95ef083 | 20 | |
muaiyd | 16:0a2138a18f26 | 21 | void CycleFunction(); |
muaiyd | 0:86bba6bf9b6f | 22 | |
muaiyd | 0:86bba6bf9b6f | 23 | int main(){ |
muaiyd | 0:86bba6bf9b6f | 24 | Init_LCD(); |
muaiyd | 12:582753a4f1fb | 25 | InitFile(); |
muaiyd | 16:0a2138a18f26 | 26 | LogTimer.start(); |
muaiyd | 20:00a9a95ef083 | 27 | Cycle.attach(&CycleFunction,0.0125); |
muaiyd | 16:0a2138a18f26 | 28 | } |
muaiyd | 16:0a2138a18f26 | 29 | |
muaiyd | 16:0a2138a18f26 | 30 | void CycleFunction(){ |
muaiyd | 20:00a9a95ef083 | 31 | |
muaiyd | 20:00a9a95ef083 | 32 | /* |
muaiyd | 20:00a9a95ef083 | 33 | We can see the period of execute time for every function below on the pin that |
muaiyd | 20:00a9a95ef083 | 34 | assigned for each and writen infront of it. The least common multiple for all the above |
muaiyd | 20:00a9a95ef083 | 35 | repeat time function is 180 Sec so every 180 Sec all the cycle is repeated. That mean 14400 |
muaiyd | 20:00a9a95ef083 | 36 | cycles. |
muaiyd | 20:00a9a95ef083 | 37 | */ |
muaiyd | 20:00a9a95ef083 | 38 | |
muaiyd | 20:00a9a95ef083 | 39 | Counter ++ ; |
muaiyd | 20:00a9a95ef083 | 40 | switch(Counter){ |
muaiyd | 20:00a9a95ef083 | 41 | case 1: |
muaiyd | 20:00a9a95ef083 | 42 | if( AllTimeCounter % 4 == 0) ReadDigitalin(); //Pin 21 |
muaiyd | 20:00a9a95ef083 | 43 | break; |
muaiyd | 20:00a9a95ef083 | 44 | case 2: |
muaiyd | 20:00a9a95ef083 | 45 | if( AllTimeCounter % 8 ==0) ReadAnalogin(); //Pin 22 |
muaiyd | 20:00a9a95ef083 | 46 | break; |
muaiyd | 20:00a9a95ef083 | 47 | case 3: |
muaiyd | 20:00a9a95ef083 | 48 | if( AllTimeCounter % 10 == 0) FreqMsur(); //Pin 23 |
muaiyd | 20:00a9a95ef083 | 49 | break; |
muaiyd | 20:00a9a95ef083 | 50 | case 4: |
muaiyd | 20:00a9a95ef083 | 51 | if( AllTimeCounter % 15 == 0) BinaryCounter();//Pin 24 |
muaiyd | 20:00a9a95ef083 | 52 | break; |
muaiyd | 20:00a9a95ef083 | 53 | case 5: |
muaiyd | 20:00a9a95ef083 | 54 | if( AllTimeCounter % 18 == 0) InputCheck(); //Pin 25 |
muaiyd | 20:00a9a95ef083 | 55 | break; |
muaiyd | 20:00a9a95ef083 | 56 | case 6: |
muaiyd | 20:00a9a95ef083 | 57 | if( AllTimeCounter % 20 == 0 ) Display(); //Pin 26 |
muaiyd | 20:00a9a95ef083 | 58 | break; |
muaiyd | 20:00a9a95ef083 | 59 | case 7: |
muaiyd | 20:00a9a95ef083 | 60 | if( AllTimeCounter % 50 == 0 ) LogFile(); //Pin 27 |
muaiyd | 20:00a9a95ef083 | 61 | break; |
muaiyd | 20:00a9a95ef083 | 62 | case 8: |
muaiyd | 20:00a9a95ef083 | 63 | Counter = 0; |
muaiyd | 20:00a9a95ef083 | 64 | AllTimeCounter ++ ; |
muaiyd | 20:00a9a95ef083 | 65 | TickerPin = !(TickerPin); |
muaiyd | 20:00a9a95ef083 | 66 | break; |
muaiyd | 20:00a9a95ef083 | 67 | } |
muaiyd | 20:00a9a95ef083 | 68 | if ( AllTimeCounter == 14400 ) AllTimeCounter = 0; |
muaiyd | 0:86bba6bf9b6f | 69 | } |