![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
chad
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
main.cpp@11:b48ff77c664a, 2017-03-07 (annotated)
- Committer:
- f_legge
- Date:
- Tue Mar 07 19:07:24 2017 +0000
- Revision:
- 11:b48ff77c664a
- Parent:
- 10:2414d28be4ba
- Child:
- 12:d088f8024cf0
First compile. Added offsets to timers
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 | 11:b48ff77c664a | 14 | #include "SDFileSystem.h" |
f_legge | 11:b48ff77c664a | 15 | #include "tasks.h" |
f_legge | 4:70553c83c65a | 16 | |
f_legge | 4:70553c83c65a | 17 | #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT) |
f_legge | 4:70553c83c65a | 18 | #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT) |
f_legge | 0:10e3e2697134 | 19 | |
f_legge | 4:70553c83c65a | 20 | // Pointers to LCD Screen |
f_legge | 4:70553c83c65a | 21 | MCP23017 *par_port; // pointer to 16-bit parallel I/O chip |
f_legge | 4:70553c83c65a | 22 | WattBob_TextLCD *lcd; // pointer to 2*16 character LCD object |
f_legge | 7:71a923f423f4 | 23 | FILE *fo; // pointer to uSD object |
f_legge | 4:70553c83c65a | 24 | |
f_legge | 4:70553c83c65a | 25 | // Digital I/O p11 to p20 |
f_legge | 10:2414d28be4ba | 26 | DigitalIn Fq(p11); // Digital frequency in for measurement |
f_legge | 10:2414d28be4ba | 27 | DigitalIn DS(p12); // Digital switch input |
f_legge | 10:2414d28be4ba | 28 | DigitalIn DS_s(p13); // Digital shutdown switch |
f_legge | 10:2414d28be4ba | 29 | DigitalOut WD_pulse_out(p14); // Watchdog Pulse |
f_legge | 4:70553c83c65a | 30 | SDFileSystem uSD(p5, p6, p7, p8, "uSD"); //uSD pinout |
f_legge | 4:70553c83c65a | 31 | |
f_legge | 4:70553c83c65a | 32 | // Analogue I/O p15 to p20 |
f_legge | 11:b48ff77c664a | 33 | AnalogIn A1_(p15); // Analogue input to be filtered |
f_legge | 11:b48ff77c664a | 34 | AnalogIn A2_(p16); // Analogue input to be filtered |
f_legge | 4:70553c83c65a | 35 | |
f_legge | 4:70553c83c65a | 36 | // Timer objects |
f_legge | 9:d04a313420c7 | 37 | Ticker tick; // Clock timer for CycExec |
f_legge | 4:70553c83c65a | 38 | Timer timer; // Frequency Timer |
f_legge | 9:d04a313420c7 | 39 | Timer T5; // Timer for idle states |
f_legge | 4:70553c83c65a | 40 | |
f_legge | 4:70553c83c65a | 41 | // Constant Declaration |
f_legge | 5:e1ade53bce83 | 42 | const int SampFreq = 100; // Sampling Frequency |
f_legge | 5:e1ade53bce83 | 43 | const int WD = 6000; // Watchdog pulse length |
f_legge | 4:70553c83c65a | 44 | |
f_legge | 4:70553c83c65a | 45 | // Variable Declaration |
f_legge | 4:70553c83c65a | 46 | long int tck = 0; // Used to define what task is called (CycExec) |
f_legge | 0:10e3e2697134 | 47 | |
f_legge | 10:2414d28be4ba | 48 | bool FqIn = Fq; // Frequency input boolean |
f_legge | 4:70553c83c65a | 49 | int period = 0; // Frequency timer variable (Frequency Check) |
f_legge | 4:70553c83c65a | 50 | int freq = 0; // Frequency return variable (Frequency Check) |
f_legge | 4:70553c83c65a | 51 | |
f_legge | 10:2414d28be4ba | 52 | bool DSIn = DS; // Switch Input boolean |
f_legge | 4:70553c83c65a | 53 | bool switch_state = 0; // Switch high or low (Digital In) |
f_legge | 10:2414d28be4ba | 54 | |
f_legge | 10:2414d28be4ba | 55 | bool WD_pulse; |
f_legge | 11:b48ff77c664a | 56 | //bool WD_pulse_out = WD_pulse; |
f_legge | 10:2414d28be4ba | 57 | |
f_legge | 11:b48ff77c664a | 58 | int A1_in = A1_; // Analogue 1 input variable |
f_legge | 11:b48ff77c664a | 59 | int A2_in = A2_; // Analogue 2 input variable |
f_legge | 4:70553c83c65a | 60 | int A1_val = 0; // Analogue 1 return variable (Analogue In) |
f_legge | 4:70553c83c65a | 61 | int A2_val = 0; // Analogue 2 return variable (Analogue In) |
f_legge | 4:70553c83c65a | 62 | |
f_legge | 11:b48ff77c664a | 63 | bool DS_sIn = DS_s; // Shutdown Switch boolean |
f_legge | 9:d04a313420c7 | 64 | int error_code = 0; // Error code variable |
f_legge | 6:c538f317f426 | 65 | |
f_legge | 9:d04a313420c7 | 66 | int logcount = 0; // Keep track of log number |
f_legge | 4:70553c83c65a | 67 | |
f_legge | 4:70553c83c65a | 68 | //////////////////////////////////////////////////////////////////////////////// |
f_legge | 4:70553c83c65a | 69 | // |
f_legge | 4:70553c83c65a | 70 | // Main Program |
f_legge | 4:70553c83c65a | 71 | // |
f_legge | 11:b48ff77c664a | 72 | void CycExec(); |
f_legge | 4:70553c83c65a | 73 | |
f_legge | 4:70553c83c65a | 74 | int main() |
f_legge | 4:70553c83c65a | 75 | { |
f_legge | 4:70553c83c65a | 76 | // LCD Init |
f_legge | 4:70553c83c65a | 77 | par_port = new MCP23017(p9, p10, 0x40); // initialise 16-bit I/O chip |
f_legge | 4:70553c83c65a | 78 | lcd = new WattBob_TextLCD(par_port); // initialise 2*26 char display |
f_legge | 4:70553c83c65a | 79 | par_port->write_bit(1,BL_BIT); // turn LCD backlight ON |
f_legge | 4:70553c83c65a | 80 | lcd->cls(); // clear display |
f_legge | 4:70553c83c65a | 81 | |
f_legge | 4:70553c83c65a | 82 | // .csv log Init |
f_legge | 7:71a923f423f4 | 83 | fo = fopen ("/uSD/log.csv", "a"); // Pointer to log file on uSD |
f_legge | 7:71a923f423f4 | 84 | fprintf(fo, "Log of Frazer Legge's Embedded Software Assignment 2\n\n"); |
f_legge | 4:70553c83c65a | 85 | |
f_legge | 4:70553c83c65a | 86 | // |
f_legge | 4:70553c83c65a | 87 | tick.attach(&CycExec, 0.025); // Period set to 25ms |
f_legge | 4:70553c83c65a | 88 | while(1){ |
f_legge | 4:70553c83c65a | 89 | } |
f_legge | 0:10e3e2697134 | 90 | } |
f_legge | 4:70553c83c65a | 91 | |
f_legge | 4:70553c83c65a | 92 | void CycExec() |
f_legge | 4:70553c83c65a | 93 | { |
f_legge | 11:b48ff77c664a | 94 | if(tck % 40 == 4){ // Every Second (needs offset) |
f_legge | 9:d04a313420c7 | 95 | Task1(timer, FqIn, SampFreq, period, freq); |
f_legge | 9:d04a313420c7 | 96 | } |
f_legge | 11:b48ff77c664a | 97 | else if(tck % 13 == 8){ // Every 1/3 sec |
f_legge | 9:d04a313420c7 | 98 | Task2(DSIn, switch_state); |
f_legge | 9:d04a313420c7 | 99 | } |
f_legge | 11:b48ff77c664a | 100 | else if(tck % 80 == 7){ // Every 2 sec |
f_legge | 9:d04a313420c7 | 101 | Task3(WD_pulse, WD); |
f_legge | 9:d04a313420c7 | 102 | } |
f_legge | 11:b48ff77c664a | 103 | else if(tck % 20 == 0){ // Every 1/2 sec |
f_legge | 9:d04a313420c7 | 104 | Task4(A1_val, A2_val, A1_in, A2_in); |
f_legge | 9:d04a313420c7 | 105 | } |
f_legge | 11:b48ff77c664a | 106 | else if(tck % 80 == 1){ // Every 2 sec |
f_legge | 10:2414d28be4ba | 107 | Task5(freq, switch_state, A1_val, A2_val); |
f_legge | 10:2414d28be4ba | 108 | } |
f_legge | 11:b48ff77c664a | 109 | else if(tck % 20 == 3){ // Every 0.5 sec |
f_legge | 10:2414d28be4ba | 110 | Task6(switch_state, A1_val, A2_val, error_code); |
f_legge | 9:d04a313420c7 | 111 | } |
f_legge | 11:b48ff77c664a | 112 | else if(tck % 20 == 10){ // Every 1/2 sec |
f_legge | 10:2414d28be4ba | 113 | Task7(logcount, freq, switch_state, A1_val, A2_val); |
f_legge | 9:d04a313420c7 | 114 | } |
f_legge | 11:b48ff77c664a | 115 | else if(tck % 20 == 12){ |
f_legge | 11:b48ff77c664a | 116 | Task8(DS_sIn, tick, T5); |
f_legge | 9:d04a313420c7 | 117 | } |
f_legge | 10:2414d28be4ba | 118 | tck++; |
f_legge | 9:d04a313420c7 | 119 | } |
f_legge | 8:0e46cf19fc45 | 120 | |
f_legge | 8:0e46cf19fc45 | 121 | |
f_legge | 8:0e46cf19fc45 | 122 | |
f_legge | 8:0e46cf19fc45 | 123 | |
f_legge | 8:0e46cf19fc45 | 124 | |
f_legge | 8:0e46cf19fc45 | 125 | |
f_legge | 8:0e46cf19fc45 | 126 | |
f_legge | 8:0e46cf19fc45 | 127 | |
f_legge | 8:0e46cf19fc45 | 128 | |
f_legge | 8:0e46cf19fc45 | 129 | |
f_legge | 8:0e46cf19fc45 | 130 | |
f_legge | 4:70553c83c65a | 131 | |
f_legge | 4:70553c83c65a | 132 | |
f_legge | 4:70553c83c65a | 133 | |
f_legge | 4:70553c83c65a | 134 |