chad
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
tasks.cpp
- Committer:
- f_legge
- Date:
- 2017-03-07
- Revision:
- 13:ad04937ca366
- Child:
- 14:ede0e7ed2745
File content as of revision 13:ad04937ca366:
#include "main.h" // Task 1: Measure input frequency void Task1(void) { timer.reset(); // If the input signal is low, wait for a rising edge to start counting if (FqIn == 0) { while(FqIn == 0) wait_us(SampFreq); timer.start(); // Start timer while(FqIn == 1) // Keep counting as long as signal is high wait_us(SampFreq); } // If the input signal is high, wait for a falling edge to start counting else if (FqIn == 1) { while(FqIn == 1) wait_us(SampFreq); timer.start(); // Start timer while(FqIn == 0) // Keep counting as long as signal is high wait_us(SampFreq); } timer.stop(); // Stop counting when signal changes period = timer.read()*2; // Convert the time into a period freq = 1000000/period; // Convert the period into a frequency lcd->locate(1,0); lcd->printf("F: %d", timer.read()); return; } //////////////////////////////////////////////////////////////////////////////// // // Read Digital input switch // void Task2(void) { if (DSIn == 1) switch_state = 1; else if (DSIn == 0) switch_state = 0; else switch_state = 0; // switch_state = DSIn == 1 ? 1: 0; return; } //////////////////////////////////////////////////////////////////////////////// // // Output watchdog timer pulse // void Task3(void) { WD_pulse = 1; // Pulse High wait_us(WD); // Leave high for specified length WD_pulse = 0; return; } //////////////////////////////////////////////////////////////////////////////// // // Read and filter 2 analogue inputs // 3.3V max // void Task4(void) { A1_val = 0; A2_val = 0; for(int i=0; i<3; i++) { A1_val = A1_val + A1_val + (A1_in * 3.3); A2_val = A2_val + A2_val + (A2_in * 3.3); } A1_val = (A1_val / 3); A2_val = (A2_val / 3); return; } //////////////////////////////////////////////////////////////////////////////// // // Display Frequency, digital and filterd analogue values on LCD // void Task5(void) { lcd->cls(); lcd->locate(0,0); //lcd->printf("F%d S%d% A1d% A2d",freq,switch_state,A1_val,A2_val); lcd->printf("F%d",freq); //lcd->printf("test"); return; } //////////////////////////////////////////////////////////////////////////////// // // Error check // If switch_1 is ON & (average_analogue_in_1 > average_analogue_in_2) error code 3 // Else error code 0 // void Task6(void) {/* if(switch_state == 1 && (A1_val > A2_val)) error_code = 3; else error_code = 0;*/ error_code++; //lcd->cls(); lcd->locate(1,0); lcd->printf("Error: %d", error_code); wait_us(100); return; } //////////////////////////////////////////////////////////////////////////////// // // Log frequency, digital and filtered analogue values to uSD // void Task7(void) { logcount++; fprintf(fp,"Log: %d,Freq: %dHz,Digital_In: %d,Analogue_1: %d,Analogue_2: %d\n",logcount,freq,switch_state,A1_val,A2_val); return; } //////////////////////////////////////////////////////////////////////////////// // // Shutdown on switch // /*void Task8() { if(DS_sIn == 1) { tick.detach(); fprintf(fp, "\nTask 5 took %dms to complete\n", T5.read_ms()); fprintf(fp, "\nCyclic Executive stopped\n"); fclose(fp); } else{ } } */