![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
chad
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
Diff: main.cpp
- Revision:
- 17:bc25d5f47bab
- Parent:
- 16:bebcc7d24f3e
- Child:
- 18:bda795e28ed7
--- a/main.cpp Fri Mar 10 18:50:37 2017 +0000 +++ b/main.cpp Mon Mar 13 14:51:55 2017 +0000 @@ -8,8 +8,6 @@ #include "main.h" - - // Pointers to LCD Screen MCP23017 *par_port; // pointer to 16-bit parallel I/O chip WattBob_TextLCD *lcd; // pointer to 2*16 character LCD object @@ -21,48 +19,37 @@ 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(p11); // Watchdog Pulse +DigitalOut WD_pulse(p11); // Watchdog Pulse DigitalOut led1(LED1); DigitalOut led2(LED2); - - // Analogue I/O p15 to p20 AnalogIn A1_(p15); // Analogue input to be filtered AnalogIn A2_(p16); // Analogue input to be filtered // Timer objects -//Ticker tick; // Clock timer for CycExec -Ticker ticker; +Ticker ticker; // Ticker for CycExec Timer timer; // Frequency Timer Timer T5; // Timer for idle states // Constant Declaration -const int SampFreq = 100; // Sampling Frequency const int WD = 6000; // Watchdog pulse length // Variable Declaration -int tck = 1; // Used to define what task is called (CycExec) +int tck = 0; // Used to define what task is called (CycExec) -int FqIn; // Frequency input boolean -float period; // Frequency timer variable (Frequency Check) -float freq; // Frequency return variable (Frequency Check) +float freq; // Frequency read variable -int DSIn; // Switch Input boolean -int switch_state; - -int WD_pulse; +int switch_state; // Output switch 1 +float A1_In; // Analogue 1 Input +float A2_In; // Analogue 2 Input +float A1_val; // Analogue 1 return variable (Analogue In) +float A2_val; // Analogue 2 return variable (Analogue In) -float A1_in; // Analogue 1 input variable -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 error_code; // Error code variable -int DS_sIn; // Shutdown Switch -int error_code; // Error code variable - -int logcount; // Keep track of log number +int logcount; // Keep track of log number @@ -73,39 +60,30 @@ void CycExec() { -/* - if(tck % 10 == 6) { // Every Second (needs offset) freq - //Task1(); - } else if(tck % 3 == 2) { // Every 1/3 sec Dig In + + if(tck % 20 == 0) { // Every 1 sec freq + Task1(); + } else if(tck % 6 == 1) { // Every 1/3 sec Dig In Task2(); - } else if(tck % 20 == 7) { // Every 2 sec WD + } else if(tck % 40 == 2) { // Every 2 sec WD Task3(); - } else if(tck % 5 == 0) { // Every 1/2 sec Ana In + } else if(tck % 10 == 3) { // Every 1/2 sec Ana In Task4(); - } 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 if(tck % 40 == 4) { // Every 2 sec LCD + Task5a(); + } else if(tck % 40 == 5) { // Every 1/2 sec LCD + Task5b(); + } else if(tck % 10 == 6) { // Every 0.5 sec Error + Task6(); + } else if(tck % 10 == 7) { // Every 1/2 sec Log + Task7(); + } else if(tck % 10 == 8) { // Every 1/2 sec Shutdown + Task8(); } - //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; + led2 = !led2; // Shows CycExec running - tck++; - + tck++; // Increment tck register every cycle. Starts tasks. } @@ -120,16 +98,15 @@ lcd->cls(); // clear display - - - // .csv log Init + // Create .txt file on uSD mkdir("/sd/logs", 0777); - fp = fopen ("/sd/logs/log.txt", "w"); // Pointer to log file on uSD + 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"); + fprintf(fp, "Log,Frequency,DigitalIn,Analogue1,Analogue2\n\n"); - ticker.attach(&CycExec, 1.0); // Period set to 25ms + ticker.attach(&CycExec, 0.05); // Period set to 50ms - while(1) { + while(1) { // Indicator to show CycExec was started led1 = !led1; wait(0.2); }