chad
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
Diff: main.cpp
- Revision:
- 16:bebcc7d24f3e
- Parent:
- 15:85616bc0e2ae
- Child:
- 17:bc25d5f47bab
diff -r 85616bc0e2ae -r bebcc7d24f3e main.cpp --- a/main.cpp Wed Mar 08 16:17:09 2017 +0000 +++ b/main.cpp Fri Mar 10 18:50:37 2017 +0000 @@ -4,7 +4,7 @@ // Watchdog Pulse Length: 6ms // Watchdog Repetion Rate: 0.5 // Error Display: 1 (LCD) -// Execution time display: Task5 (LDC display) +// Execution time display: Task5 (LDC display) #include "main.h" @@ -15,18 +15,20 @@ WattBob_TextLCD *lcd; // pointer to 2*16 character LCD object FILE *fp; // pointer to uSD object -//SDFileSystem sd(p5, p6, p7, p8, "sd"); //uSD pinout +SDFileSystem sd(p5, p6, p7, p8, "sd"); //uSD pinout // Digital I/O p11 to p20 -DigitalIn Fq(p11); // Digital frequency in for measurement +DigitalIn Fq(p14); // Digital frequency in for measurement DigitalIn DS(p12); // Digital switch input DigitalIn DS_s(p13); // Digital shutdown switch -DigitalOut WD_pulse_out(p14); // Watchdog Pulse +DigitalOut WD_pulse_out(p11); // Watchdog Pulse DigitalOut led1(LED1); DigitalOut led2(LED2); + + // Analogue I/O p15 to p20 -AnalogIn A1_(p15); // Analogue input to be filtered +AnalogIn A1_(p15); // Analogue input to be filtered AnalogIn A2_(p16); // Analogue input to be filtered // Timer objects @@ -43,24 +45,24 @@ int tck = 1; // Used to define what task is called (CycExec) int FqIn; // Frequency input boolean -int period = 0; // Frequency timer variable (Frequency Check) -int freq = 0; // Frequency return variable (Frequency Check) +float period; // Frequency timer variable (Frequency Check) +float freq; // Frequency return variable (Frequency Check) int DSIn; // Switch Input boolean -int switch_state = 0; +int switch_state; -int WD_pulse = 0; +int WD_pulse; float A1_in; // Analogue 1 input variable -float A2_in; // Analogue 2 input variable -float A1_val = 0; // Analogue 1 return variable (Analogue In) -float A2_val = 0; // Analogue 2 return variable (Analogue In) +float A2_in; // Analogue 2 input variable +float A1_val; // Analogue 1 return variable (Analogue In) +float A2_val; // Analogue 2 return variable (Analogue In) -int DS_sIn = DS_s; // Shutdown Switch -int error_code = 0; // Error code variable +int DS_sIn; // Shutdown Switch +int error_code; // Error code variable -int logcount = 0; // Keep track of log number +int logcount; // Keep track of log number @@ -71,84 +73,66 @@ void CycExec() { - /* - if(tck == 2){ // Every Second (needs offset) - //Task1(); - lcd->locate(0,0); - } - else if(tck == 4){ // Every 1/3 sec - //Task2(); - lcd->printf("Test"); - } - else if(tck % 80 == 7){ // Every 2 sec - Task3(); - } - else if(tck % 20 == 0){ // Every 1/2 sec - Task4(); - } - else if(tck % 80 == 1){ // Every 2 sec - Task5(); - } - else if(tck % 20 == 3){ // Every 0.5 sec - Task6(); - } - else if(tck % 20 == 10){ // Every 1/2 sec - Task7(); - } - else{ - Task8(); - } */ - +/* + if(tck % 10 == 6) { // Every Second (needs offset) freq + //Task1(); + } else if(tck % 3 == 2) { // Every 1/3 sec Dig In + Task2(); + } else if(tck % 20 == 7) { // Every 2 sec WD + Task3(); + } else if(tck % 5 == 0) { // Every 1/2 sec Ana In Task4(); - - //lcd->locate(0,0); - //lcd->printf("Tck: %d", tck); - led2 = !led2; - - FqIn = Fq; - DSIn = DS; - A1_in = A1_; - A2_in = A2_; - DS_sIn = DS_s; - WD_pulse_out = WD_pulse; - - /*lcd->locate(0,0); - lcd->printf("S: %d", switch_state);*/ - - tck++; - + } else if(tck % 20 == 1) { // Every 2 sec LCD + Task5(); + } else if(tck % 5 == 3) { // Every 0.5 sec Error + // Task6(); + } else if(tck % 5 == 4) { // Every 1/2 sec Log + // Task7(); + } + //else{ // S/D + // Task8(); + //}*/ + + Task1(); + + led2 = !led2; + + FqIn = Fq; + DSIn = DS; + A1_in = A1_; + A2_in = A2_; + DS_sIn = DS_s; + WD_pulse_out = WD_pulse; + + tck++; + } int main() -{ +{ // LCD Init par_port = new MCP23017(p9, p10, 0x40); // initialise 16-bit I/O chip par_port->config(0x0F00, 0x0F00, 0x0F00); - + lcd = new WattBob_TextLCD(par_port); // initialise 2*26 char display par_port->write_bit(1,BL_BIT); // turn LCD backlight ON - - lcd->cls(); // clear display - - - + + lcd->cls(); // clear display + + + // .csv log Init - //mkdir("/sd/logs", 0777); - //fp = fopen ("/sd/logs/log.txt", "w"); // Pointer to log file on uSD - //fprintf(fp, "Log of Frazer Legge's Embedded Software Assignment 2\n\n"); - - //tick.start(CycExec); - - ticker.attach(&CycExec, 0.025); // Period set to 25ms - - /*lcd->locate(0,0); - lcd->printf("Tck: %d", tck);*/ - - while(1){ + mkdir("/sd/logs", 0777); + fp = fopen ("/sd/logs/log.txt", "w"); // Pointer to log file on uSD + fprintf(fp, "Log of Frazer Legge's Embedded Software Assignment 2\n\n"); + + ticker.attach(&CycExec, 1.0); // Period set to 25ms + + while(1) { led1 = !led1; - wait(0.2); - } + wait(0.2); + } }