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