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