![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
chad
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
main.cpp
- Committer:
- f_legge
- Date:
- 2017-03-13
- Revision:
- 17:bc25d5f47bab
- Parent:
- 16:bebcc7d24f3e
- Child:
- 18:bda795e28ed7
File content as of revision 17:bc25d5f47bab:
// Paramater Allocation // Paramater: 17 // Log Option: 1 (uSD) // Watchdog Pulse Length: 6ms // Watchdog Repetion Rate: 0.5 // Error Display: 1 (LCD) // Execution time display: Task5 (LDC display) #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 FILE *fp; // pointer to uSD object SDFileSystem sd(p5, p6, p7, p8, "sd"); //uSD pinout // Digital I/O p11 to p20 DigitalIn Fq(p14); // Digital frequency in for measurement DigitalIn DS(p12); // Digital switch input DigitalIn DS_s(p13); // Digital shutdown switch 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 ticker; // Ticker for CycExec Timer timer; // Frequency Timer Timer T5; // Timer for idle states // Constant Declaration const int WD = 6000; // Watchdog pulse length // Variable Declaration int tck = 0; // Used to define what task is called (CycExec) float freq; // Frequency read variable 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) int error_code; // Error code variable int logcount; // Keep track of log number //////////////////////////////////////////////////////////////////////////////// // // Main Program // void CycExec() { if(tck % 20 == 0) { // Every 1 sec freq Task1(); } else if(tck % 6 == 1) { // Every 1/3 sec Dig In Task2(); } else if(tck % 40 == 2) { // Every 2 sec WD Task3(); } else if(tck % 10 == 3) { // Every 1/2 sec Ana In Task4(); } 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(); } led2 = !led2; // Shows CycExec running tck++; // Increment tck register every cycle. Starts tasks. } 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 // Create .txt file on uSD 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"); fprintf(fp, "Log,Frequency,DigitalIn,Analogue1,Analogue2\n\n"); ticker.attach(&CycExec, 0.05); // Period set to 50ms while(1) { // Indicator to show CycExec was started led1 = !led1; wait(0.2); } }