![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
chad
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
main.cpp@14:ede0e7ed2745, 2017-03-08 (annotated)
- Committer:
- f_legge
- Date:
- Wed Mar 08 15:36:57 2017 +0000
- Revision:
- 14:ede0e7ed2745
- Parent:
- 13:ad04937ca366
- Child:
- 15:85616bc0e2ae
Ticker Finally Attaching. ~ 2days lost
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 | 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 | 14:ede0e7ed2745 | 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 | 14:ede0e7ed2745 | 21 | DigitalIn Fq(p11); // 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 | 14:ede0e7ed2745 | 24 | DigitalOut WD_pulse_out(p14); // 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 | 4:70553c83c65a | 28 | // Analogue I/O p15 to p20 |
f_legge | 14:ede0e7ed2745 | 29 | AnalogIn A1_(p15); // Analogue input to be filtered |
f_legge | 14:ede0e7ed2745 | 30 | AnalogIn A2_(p16); // Analogue input to be filtered |
f_legge | 4:70553c83c65a | 31 | |
f_legge | 4:70553c83c65a | 32 | // Timer objects |
f_legge | 14:ede0e7ed2745 | 33 | //Ticker tick; // Clock timer for CycExec |
f_legge | 14:ede0e7ed2745 | 34 | Ticker ticker; |
f_legge | 14:ede0e7ed2745 | 35 | //Timer timer; // Frequency Timer |
f_legge | 14:ede0e7ed2745 | 36 | //Timer T5; // Timer for idle states |
f_legge | 4:70553c83c65a | 37 | |
f_legge | 4:70553c83c65a | 38 | // Constant Declaration |
f_legge | 5:e1ade53bce83 | 39 | const int SampFreq = 100; // Sampling Frequency |
f_legge | 5:e1ade53bce83 | 40 | const int WD = 6000; // Watchdog pulse length |
f_legge | 4:70553c83c65a | 41 | |
f_legge | 4:70553c83c65a | 42 | // Variable Declaration |
f_legge | 14:ede0e7ed2745 | 43 | int tck = 1; // Used to define what task is called (CycExec) |
f_legge | 0:10e3e2697134 | 44 | |
f_legge | 14:ede0e7ed2745 | 45 | int FqIn = Fq; // Frequency input boolean |
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 | 14:ede0e7ed2745 | 49 | int DSIn = DS; // Switch Input boolean |
f_legge | 13:ad04937ca366 | 50 | int switch_state = 0; |
f_legge | 10:2414d28be4ba | 51 | |
f_legge | 12:d088f8024cf0 | 52 | int WD_pulse; |
f_legge | 12:d088f8024cf0 | 53 | |
f_legge | 10:2414d28be4ba | 54 | |
f_legge | 14:ede0e7ed2745 | 55 | int A1_in = A1_; // Analogue 1 input variable |
f_legge | 14:ede0e7ed2745 | 56 | int A2_in = A2_; // Analogue 2 input variable |
f_legge | 4:70553c83c65a | 57 | int A1_val = 0; // Analogue 1 return variable (Analogue In) |
f_legge | 4:70553c83c65a | 58 | int A2_val = 0; // Analogue 2 return variable (Analogue In) |
f_legge | 4:70553c83c65a | 59 | |
f_legge | 14:ede0e7ed2745 | 60 | int DS_sIn = DS_s; // Shutdown Switch |
f_legge | 9:d04a313420c7 | 61 | int error_code = 0; // Error code variable |
f_legge | 6:c538f317f426 | 62 | |
f_legge | 9:d04a313420c7 | 63 | int logcount = 0; // Keep track of log number |
f_legge | 4:70553c83c65a | 64 | |
f_legge | 14:ede0e7ed2745 | 65 | |
f_legge | 14:ede0e7ed2745 | 66 | |
f_legge | 4:70553c83c65a | 67 | //////////////////////////////////////////////////////////////////////////////// |
f_legge | 4:70553c83c65a | 68 | // |
f_legge | 4:70553c83c65a | 69 | // Main Program |
f_legge | 4:70553c83c65a | 70 | // |
f_legge | 13:ad04937ca366 | 71 | |
f_legge | 13:ad04937ca366 | 72 | void CycExec() |
f_legge | 14:ede0e7ed2745 | 73 | { |
f_legge | 14:ede0e7ed2745 | 74 | /* |
f_legge | 14:ede0e7ed2745 | 75 | if(tck == 2){ // Every Second (needs offset) |
f_legge | 14:ede0e7ed2745 | 76 | //Task1(); |
f_legge | 14:ede0e7ed2745 | 77 | lcd->locate(0,0); |
f_legge | 14:ede0e7ed2745 | 78 | } |
f_legge | 14:ede0e7ed2745 | 79 | else if(tck == 4){ // Every 1/3 sec |
f_legge | 14:ede0e7ed2745 | 80 | //Task2(); |
f_legge | 14:ede0e7ed2745 | 81 | lcd->printf("Test"); |
f_legge | 14:ede0e7ed2745 | 82 | } |
f_legge | 14:ede0e7ed2745 | 83 | else if(tck % 80 == 7){ // Every 2 sec |
f_legge | 14:ede0e7ed2745 | 84 | Task3(); |
f_legge | 14:ede0e7ed2745 | 85 | } |
f_legge | 14:ede0e7ed2745 | 86 | else if(tck % 20 == 0){ // Every 1/2 sec |
f_legge | 14:ede0e7ed2745 | 87 | Task4(); |
f_legge | 14:ede0e7ed2745 | 88 | } |
f_legge | 14:ede0e7ed2745 | 89 | else if(tck % 80 == 1){ // Every 2 sec |
f_legge | 14:ede0e7ed2745 | 90 | Task5(); |
f_legge | 14:ede0e7ed2745 | 91 | } |
f_legge | 14:ede0e7ed2745 | 92 | else if(tck % 20 == 3){ // Every 0.5 sec |
f_legge | 14:ede0e7ed2745 | 93 | Task6(); |
f_legge | 14:ede0e7ed2745 | 94 | } |
f_legge | 14:ede0e7ed2745 | 95 | else if(tck % 20 == 10){ // Every 1/2 sec |
f_legge | 14:ede0e7ed2745 | 96 | Task7(); |
f_legge | 14:ede0e7ed2745 | 97 | } |
f_legge | 14:ede0e7ed2745 | 98 | else{ |
f_legge | 14:ede0e7ed2745 | 99 | Task8(); |
f_legge | 14:ede0e7ed2745 | 100 | } */ |
f_legge | 14:ede0e7ed2745 | 101 | |
f_legge | 14:ede0e7ed2745 | 102 | |
f_legge | 14:ede0e7ed2745 | 103 | //lcd->locate(0,0); |
f_legge | 14:ede0e7ed2745 | 104 | //lcd->printf("Tck: %d", tck); |
f_legge | 14:ede0e7ed2745 | 105 | led2 = !led2; |
f_legge | 14:ede0e7ed2745 | 106 | |
f_legge | 14:ede0e7ed2745 | 107 | tck++; |
f_legge | 14:ede0e7ed2745 | 108 | //WD_pulse_out = WD_pulse; |
f_legge | 14:ede0e7ed2745 | 109 | } |
f_legge | 14:ede0e7ed2745 | 110 | |
f_legge | 4:70553c83c65a | 111 | |
f_legge | 4:70553c83c65a | 112 | int main() |
f_legge | 14:ede0e7ed2745 | 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 | 14:ede0e7ed2745 | 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 | 14:ede0e7ed2745 | 120 | |
f_legge | 4:70553c83c65a | 121 | lcd->cls(); // clear display |
f_legge | 4:70553c83c65a | 122 | |
f_legge | 14:ede0e7ed2745 | 123 | |
f_legge | 14:ede0e7ed2745 | 124 | |
f_legge | 4:70553c83c65a | 125 | // .csv log Init |
f_legge | 14:ede0e7ed2745 | 126 | //mkdir("/sd/logs", 0777); |
f_legge | 14:ede0e7ed2745 | 127 | //fp = fopen ("/sd/logs/log.txt", "w"); // Pointer to log file on uSD |
f_legge | 14:ede0e7ed2745 | 128 | //fprintf(fp, "Log of Frazer Legge's Embedded Software Assignment 2\n\n"); |
f_legge | 14:ede0e7ed2745 | 129 | |
f_legge | 14:ede0e7ed2745 | 130 | //tick.start(CycExec); |
f_legge | 14:ede0e7ed2745 | 131 | |
f_legge | 14:ede0e7ed2745 | 132 | ticker.attach(&CycExec, 0.025); // Period set to 25ms |
f_legge | 4:70553c83c65a | 133 | |
f_legge | 14:ede0e7ed2745 | 134 | /*lcd->locate(0,0); |
f_legge | 14:ede0e7ed2745 | 135 | lcd->printf("Tck: %d", tck);*/ |
f_legge | 14:ede0e7ed2745 | 136 | |
f_legge | 4:70553c83c65a | 137 | while(1){ |
f_legge | 14:ede0e7ed2745 | 138 | led1 = !led1; |
f_legge | 14:ede0e7ed2745 | 139 | wait(0.2); |
f_legge | 4:70553c83c65a | 140 | } |
f_legge | 14:ede0e7ed2745 | 141 | } |
f_legge | 14:ede0e7ed2745 | 142 | |
f_legge | 14:ede0e7ed2745 | 143 | |
f_legge | 14:ede0e7ed2745 | 144 | |
f_legge | 14:ede0e7ed2745 | 145 |