![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
chad
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
main.cpp@8:0e46cf19fc45, 2017-03-07 (annotated)
- Committer:
- f_legge
- Date:
- Tue Mar 07 17:01:38 2017 +0000
- Revision:
- 8:0e46cf19fc45
- Parent:
- 7:71a923f423f4
- Child:
- 9:d04a313420c7
Added Shutdown on switch;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
f_legge | 4:70553c83c65a | 1 | // Paramater Allocation |
f_legge | 4:70553c83c65a | 2 | // Paramater: 17 |
f_legge | 4:70553c83c65a | 3 | // Log Option: 1 (uSD) |
f_legge | 4:70553c83c65a | 4 | // Watchdog Pulse Length: 6ms |
f_legge | 4:70553c83c65a | 5 | // Watchdog Repetion Rate: 0.5 |
f_legge | 4:70553c83c65a | 6 | // Error Display: 1 (LCD) |
f_legge | 4:70553c83c65a | 7 | // Execution time display: Task5 (LDC display) |
f_legge | 4:70553c83c65a | 8 | |
f_legge | 4:70553c83c65a | 9 | |
f_legge | 4:70553c83c65a | 10 | |
f_legge | 0:10e3e2697134 | 11 | #include "mbed.h" |
f_legge | 4:70553c83c65a | 12 | #include "MCP23017.h" |
f_legge | 4:70553c83c65a | 13 | #include "WattBob_TextLCD.h" |
f_legge | 4:70553c83c65a | 14 | #include "SDFileSystem" |
f_legge | 4:70553c83c65a | 15 | |
f_legge | 4:70553c83c65a | 16 | #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT) |
f_legge | 4:70553c83c65a | 17 | #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT) |
f_legge | 0:10e3e2697134 | 18 | |
f_legge | 4:70553c83c65a | 19 | // Pointers to LCD Screen |
f_legge | 4:70553c83c65a | 20 | MCP23017 *par_port; // pointer to 16-bit parallel I/O chip |
f_legge | 4:70553c83c65a | 21 | WattBob_TextLCD *lcd; // pointer to 2*16 character LCD object |
f_legge | 7:71a923f423f4 | 22 | FILE *fo; // pointer to uSD object |
f_legge | 4:70553c83c65a | 23 | |
f_legge | 4:70553c83c65a | 24 | // Digital I/O p11 to p20 |
f_legge | 4:70553c83c65a | 25 | DigitalIn FqIn(p11); // Digital frequency in for measurement |
f_legge | 4:70553c83c65a | 26 | DigitalIn DSIn(p12); // Digital switch input |
f_legge | 4:70553c83c65a | 27 | DigitalOut WD_pulse(p14); // Watchdog Pulse |
f_legge | 4:70553c83c65a | 28 | SDFileSystem uSD(p5, p6, p7, p8, "uSD"); //uSD pinout |
f_legge | 4:70553c83c65a | 29 | |
f_legge | 4:70553c83c65a | 30 | // Analogue I/O p15 to p20 |
f_legge | 4:70553c83c65a | 31 | AnalogIn A1_in(p15); // Analogue input to be filtered |
f_legge | 4:70553c83c65a | 32 | AnalogIn A2_in(p16); // Analogue input to be filtered |
f_legge | 4:70553c83c65a | 33 | |
f_legge | 4:70553c83c65a | 34 | // Timer objects |
f_legge | 8:0e46cf19fc45 | 35 | Ticker tick; // Clock timer for CycExec |
f_legge | 4:70553c83c65a | 36 | Timer timer; // Frequency Timer |
f_legge | 8:0e46cf19fc45 | 37 | Timer T5; // Timer for idle states |
f_legge | 4:70553c83c65a | 38 | |
f_legge | 4:70553c83c65a | 39 | // Constant Declaration |
f_legge | 5:e1ade53bce83 | 40 | const int SampFreq = 100; // Sampling Frequency |
f_legge | 5:e1ade53bce83 | 41 | const int WD = 6000; // Watchdog pulse length |
f_legge | 4:70553c83c65a | 42 | |
f_legge | 4:70553c83c65a | 43 | // Variable Declaration |
f_legge | 4:70553c83c65a | 44 | long int tck = 0; // Used to define what task is called (CycExec) |
f_legge | 0:10e3e2697134 | 45 | |
f_legge | 4:70553c83c65a | 46 | int period = 0; // Frequency timer variable (Frequency Check) |
f_legge | 4:70553c83c65a | 47 | int freq = 0; // Frequency return variable (Frequency Check) |
f_legge | 4:70553c83c65a | 48 | |
f_legge | 4:70553c83c65a | 49 | bool switch_state = 0; // Switch high or low (Digital In) |
f_legge | 4:70553c83c65a | 50 | |
f_legge | 4:70553c83c65a | 51 | int A1_val = 0; // Analogue 1 return variable (Analogue In) |
f_legge | 4:70553c83c65a | 52 | int A2_val = 0; // Analogue 2 return variable (Analogue In) |
f_legge | 4:70553c83c65a | 53 | |
f_legge | 6:c538f317f426 | 54 | int logcount = 0; // Keep track of log number |
f_legge | 6:c538f317f426 | 55 | |
f_legge | 8:0e46cf19fc45 | 56 | int T5_ = 0; |
f_legge | 6:c538f317f426 | 57 | |
f_legge | 4:70553c83c65a | 58 | |
f_legge | 4:70553c83c65a | 59 | //////////////////////////////////////////////////////////////////////////////// |
f_legge | 4:70553c83c65a | 60 | // |
f_legge | 4:70553c83c65a | 61 | // Main Program |
f_legge | 4:70553c83c65a | 62 | // |
f_legge | 4:70553c83c65a | 63 | |
f_legge | 4:70553c83c65a | 64 | int main() |
f_legge | 4:70553c83c65a | 65 | { |
f_legge | 4:70553c83c65a | 66 | // LCD Init |
f_legge | 4:70553c83c65a | 67 | par_port = new MCP23017(p9, p10, 0x40); // initialise 16-bit I/O chip |
f_legge | 4:70553c83c65a | 68 | lcd = new WattBob_TextLCD(par_port); // initialise 2*26 char display |
f_legge | 4:70553c83c65a | 69 | par_port->write_bit(1,BL_BIT); // turn LCD backlight ON |
f_legge | 4:70553c83c65a | 70 | lcd->cls(); // clear display |
f_legge | 4:70553c83c65a | 71 | |
f_legge | 4:70553c83c65a | 72 | // .csv log Init |
f_legge | 7:71a923f423f4 | 73 | fo = fopen ("/uSD/log.csv", "a"); // Pointer to log file on uSD |
f_legge | 7:71a923f423f4 | 74 | fprintf(fo, "Log of Frazer Legge's Embedded Software Assignment 2\n\n"); |
f_legge | 4:70553c83c65a | 75 | |
f_legge | 4:70553c83c65a | 76 | // |
f_legge | 4:70553c83c65a | 77 | tick.attach(&CycExec, 0.025); // Period set to 25ms |
f_legge | 4:70553c83c65a | 78 | while(1){ |
f_legge | 4:70553c83c65a | 79 | } |
f_legge | 0:10e3e2697134 | 80 | } |
f_legge | 4:70553c83c65a | 81 | |
f_legge | 4:70553c83c65a | 82 | void CycExec() |
f_legge | 4:70553c83c65a | 83 | { |
f_legge | 8:0e46cf19fc45 | 84 | if(tck % 40 = 0){ // Every Second (needs offset) |
f_legge | 8:0e46cf19fc45 | 85 | Task1( |
f_legge | 8:0e46cf19fc45 | 86 | |
f_legge | 8:0e46cf19fc45 | 87 | |
f_legge | 8:0e46cf19fc45 | 88 | |
f_legge | 8:0e46cf19fc45 | 89 | |
f_legge | 8:0e46cf19fc45 | 90 | |
f_legge | 8:0e46cf19fc45 | 91 | |
f_legge | 8:0e46cf19fc45 | 92 | |
f_legge | 8:0e46cf19fc45 | 93 | |
f_legge | 8:0e46cf19fc45 | 94 | |
f_legge | 8:0e46cf19fc45 | 95 | |
f_legge | 8:0e46cf19fc45 | 96 | |
f_legge | 4:70553c83c65a | 97 | |
f_legge | 4:70553c83c65a | 98 | |
f_legge | 4:70553c83c65a | 99 | |
f_legge | 4:70553c83c65a | 100 |